@@ -63,6 +63,9 @@ Examples
6363
6464### Type-safe Criteria API
6565
66+ This code uses a type-safe Criteria API to fetch employees from a specific department
67+ while establishing associations between the related entities:
68+
6669``` java
6770var queryDsl = new QueryDsl (config);
6871var e = new Employee_ ();
@@ -84,23 +87,44 @@ for more information.
8487
8588### SQL templates
8689
90+ This code uses an SQL template to fetch employees from a specific department
91+ while establishing associations between the related entities:
92+
8793``` java
8894@Dao
8995public interface EmployeeDao {
9096
9197 @Sql (
9298 " " "
93- select * from EMPLOYEE where
94- /*%if salary != null*/
95- SALARY >= /*salary*/9999
96- /*%end*/
99+ select
100+ /*%expand*/*
101+ from
102+ EMPLOYEE e
103+ inner join
104+ DEPARTMENT d
105+ on e.departmentId = d.departmentId
106+ where
107+ /*%if departmentName != null*/
108+ d.DEPARTMENT_NAME = /*departmentName*/'test'
109+ /*%end*/
97110 " " " )
98- @Select
99- List<Employee > selectBySalary (BigDecimal salary );
111+ @Select (aggregateStrategy = EmployeeStrategy . class)
112+ List<Employee > selectByDepartmentName (String departmentName );
113+
114+ @AggregateStrategy (root = Employee . class, tableAlias = " e" )
115+ interface EmployeeStrategy {
116+ @AssociationLinker (propertyPath = " department" , tableAlias = " d" )
117+ BiFunction<Employee , Department , Employee > department = (e, d) - > {
118+ e. setDepartment(d);
119+ d. getEmployees(). add(e);
120+ return e;
121+ };
122+ }
100123}
101124```
102125
103- See [ SQL templates] ( https://doma.readthedocs.io/en/latest/sql/ )
126+ See [ SQL templates] ( https://doma.readthedocs.io/en/latest/sql/ ) and
127+ [ Aggregate strategies] ( https://doma.readthedocs.io/en/latest/aggregate-strategy/ )
104128for more information.
105129
106130### More Examples
0 commit comments