1515import java .util .stream .Collectors ;
1616import java .util .stream .Stream ;
1717import org .seasar .doma .jdbc .Config ;
18- import org .seasar .doma .jdbc .criteria .Entityql ;
19- import org .seasar .doma .jdbc .criteria .NativeSql ;
18+ import org .seasar .doma .jdbc .criteria .QueryDsl ;
2019import org .seasar .doma .jdbc .criteria .expression .Expressions ;
2120import org .seasar .doma .jdbc .criteria .option .LikeOption ;
2221import org .seasar .doma .jdbc .criteria .statement .StreamMappable ;
2322import org .seasar .doma .jdbc .criteria .tuple .Tuple2 ;
2423
2524public class EmployeeRepository {
2625
27- private final Entityql entityql ;
28-
29- private final NativeSql nativeSql ;
26+ private final QueryDsl queryDsl ;
3027
3128 public EmployeeRepository (Config config ) {
3229 Objects .requireNonNull (config );
33- entityql = new Entityql (config );
34- nativeSql = new NativeSql (config );
30+ queryDsl = new QueryDsl (config );
3531 }
3632
3733 public Employee selectById (Integer id ) {
3834 Employee_ e = new Employee_ ();
39- return entityql .from (e ).where (c -> c .eq (e .id , id )).fetchOne ();
35+ return queryDsl .from (e ).where (c -> c .eq (e .id , id )).fetchOne ();
4036 }
4137
4238 public List <Employee > selectByAgeRange (Age min , Age max ) {
4339 Employee_ e = new Employee_ ();
44- return entityql
40+ return queryDsl
4541 .from (e )
4642 .where (
4743 c -> {
@@ -53,22 +49,22 @@ public List<Employee> selectByAgeRange(Age min, Age max) {
5349
5450 public List <Employee > selectByName (String name ) {
5551 Employee_ e = new Employee_ ();
56- return entityql .from (e ).where (c -> c .eq (e .name , name )).fetch ();
52+ return queryDsl .from (e ).where (c -> c .eq (e .name , name )).fetch ();
5753 }
5854
5955 public List <Employee > selectByNames (List <String > names ) {
6056 Employee_ e = new Employee_ ();
61- return entityql .from (e ).where (c -> c .in (e .name , names )).fetch ();
57+ return queryDsl .from (e ).where (c -> c .in (e .name , names )).fetch ();
6258 }
6359
6460 public List <Employee > selectByAges (List <Age > ages ) {
6561 Employee_ e = new Employee_ ();
66- return entityql .from (e ).where (c -> c .in (e .age , ages )).fetch ();
62+ return queryDsl .from (e ).where (c -> c .in (e .age , ages )).fetch ();
6763 }
6864
6965 public List <Employee > selectByNotEmptyName (String name ) {
7066 Employee_ e = new Employee_ ();
71- return entityql
67+ return queryDsl
7268 .from (e )
7369 .where (
7470 c -> {
@@ -81,24 +77,24 @@ public List<Employee> selectByNotEmptyName(String name) {
8177
8278 public List <Employee > selectByNameWithPrefixMatching (String prefix ) {
8379 Employee_ e = new Employee_ ();
84- return entityql .from (e ).where (c -> c .like (e .name , prefix , LikeOption .prefix ())).fetch ();
80+ return queryDsl .from (e ).where (c -> c .like (e .name , prefix , LikeOption .prefix ())).fetch ();
8581 }
8682
8783 public List <Employee > selectByNameWithSuffixMatching (String suffix ) {
8884 Employee_ e = new Employee_ ();
89- return entityql .from (e ).where (c -> c .like (e .name , suffix , LikeOption .suffix ())).fetch ();
85+ return queryDsl .from (e ).where (c -> c .like (e .name , suffix , LikeOption .suffix ())).fetch ();
9086 }
9187
9288 public List <Employee > selectByNameWithInfixMatching (String inside ) {
9389 Employee_ e = new Employee_ ();
94- return entityql .from (e ).where (c -> c .like (e .name , inside , LikeOption .infix ())).fetch ();
90+ return queryDsl .from (e ).where (c -> c .like (e .name , inside , LikeOption .infix ())).fetch ();
9591 }
9692
9793 public List <Employee > selectByHiredateRange (LocalDateTime from , LocalDateTime to ) {
9894 LocalDate fromDate = from .toLocalDate ();
9995 LocalDate toDate = to .toLocalDate ().plusDays (1 );
10096 Employee_ e = new Employee_ ();
101- return entityql
97+ return queryDsl
10298 .from (e )
10399 .where (
104100 c -> {
@@ -110,17 +106,17 @@ public List<Employee> selectByHiredateRange(LocalDateTime from, LocalDateTime to
110106
111107 public List <Employee > selectBySalary (Salary salary ) {
112108 Employee_ e = new Employee_ ();
113- return entityql .from (e ).where (c -> c .gt (e .salary , salary )).fetch ();
109+ return queryDsl .from (e ).where (c -> c .gt (e .salary , salary )).fetch ();
114110 }
115111
116112 public Optional <Salary > selectSummedSalary () {
117113 Employee_ e = new Employee_ ();
118- return nativeSql .from (e ).select (Expressions .sum (e .salary )).fetchOptional ();
114+ return queryDsl .from (e ).select (Expressions .sum (e .salary )).fetchOptional ();
119115 }
120116
121117 public List <Employee > selectByExample (Employee employee ) {
122118 Employee_ e = new Employee_ ();
123- return entityql .from (e ).where (c -> c .eq (e .name , employee .getName ())).fetch ();
119+ return queryDsl .from (e ).where (c -> c .eq (e .name , employee .getName ())).fetch ();
124120 }
125121
126122 public List <Employee > selectAll () {
@@ -130,31 +126,31 @@ public List<Employee> selectAll() {
130126 public Tuple2 <List <Employee >, Long > selectAndCount (Integer offset , Integer limit ) {
131127 List <Employee > list = select (offset , limit );
132128 Employee_ e = new Employee_ ();
133- long count = nativeSql .from (e ).select (Expressions .count ()).fetchOptional ().orElse (0L );
129+ long count = queryDsl .from (e ).select (Expressions .count ()).fetchOptional ().orElse (0L );
134130 return new Tuple2 <>(list , count );
135131 }
136132
137133 public List <Employee > select (Integer offset , Integer limit ) {
138134 Employee_ e = new Employee_ ();
139- return nativeSql .from (e ).orderBy (c -> c .asc (e .id )).offset (offset ).limit (limit ).fetch ();
135+ return queryDsl .from (e ).orderBy (c -> c .asc (e .id )).offset (offset ).limit (limit ).fetch ();
140136 }
141137
142138 public <R > R selectByAge (Age age , Function <Stream <Employee >, R > mapper ) {
143139 Employee_ e = new Employee_ ();
144140 StreamMappable <Employee > stmt =
145- nativeSql .from (e ).where (c -> c .gt (e .age , age )).orderBy (c -> c .asc (e .age ));
141+ queryDsl .from (e ).where (c -> c .gt (e .age , age )).orderBy (c -> c .asc (e .age ));
146142 return stmt .mapStream (mapper );
147143 }
148144
149145 public long selectCount () {
150146 Employee_ e = new Employee_ ();
151- return nativeSql .from (e ).select (Expressions .count ()).fetchOptional ().orElse (0L );
147+ return queryDsl .from (e ).select (Expressions .count ()).fetchOptional ().orElse (0L );
152148 }
153149
154150 public List <Employee > selectAllWithAssociation () {
155151 Employee_ e = new Employee_ ();
156152 Department_ d = new Department_ ();
157- return entityql
153+ return queryDsl
158154 .from (e )
159155 .leftJoin (d , on -> on .eq (e .departmentId , d .id ))
160156 .orderBy (c -> c .asc (e .id ))
@@ -171,7 +167,7 @@ public List<Employee> selectAllWithAssociation() {
171167 public List <Employee > selectByDepartmentName_in (String departmentName ) {
172168 Employee_ e = new Employee_ ();
173169 Department_ d = new Department_ ();
174- return entityql
170+ return queryDsl
175171 .from (e )
176172 .where (
177173 c ->
@@ -184,7 +180,7 @@ public List<Employee> selectByDepartmentName_in(String departmentName) {
184180 public List <Employee > selectByDepartmentName_exists (String departmentName ) {
185181 Employee_ e = new Employee_ ();
186182 Department_ d = new Department_ ();
187- return entityql
183+ return queryDsl
188184 .from (e )
189185 .where (
190186 c ->
@@ -201,7 +197,7 @@ public List<Employee> selectByDepartmentName_exists(String departmentName) {
201197 public List <Employee > selectByDepartmentName_join (String departmentName ) {
202198 Employee_ e = new Employee_ ();
203199 Department_ d = new Department_ ();
204- return entityql
200+ return queryDsl
205201 .from (e )
206202 .innerJoin (d , on -> on .eq (e .departmentId , d .id ))
207203 .where (c -> c .eq (d .name , departmentName ))
@@ -210,29 +206,29 @@ public List<Employee> selectByDepartmentName_join(String departmentName) {
210206
211207 public List <Employee > selectNameAndSalaryAsEntityList () {
212208 Employee_ e = new Employee_ ();
213- return entityql .from (e ).selectTo (e , e .name , e .salary ).fetch ();
209+ return queryDsl .from (e ).selectTo (e , e .name , e .salary ).fetch ();
214210 }
215211
216212 public List <Tuple2 <String , Salary >> selectNameAndSalaryAsTuple2List () {
217213 Employee_ e = new Employee_ ();
218- return nativeSql .from (e ).select (e .name , e .salary ).fetch ();
214+ return queryDsl .from (e ).select (e .name , e .salary ).fetch ();
219215 }
220216
221217 public List <NameAndSalaryDto > selectNameAndSalaryAsNameAndSalaryDtoList () {
222218 Employee_ e = new Employee_ ();
223- return nativeSql .from (e ).select (e .name , e .salary ).stream ()
219+ return queryDsl .from (e ).select (e .name , e .salary ).stream ()
224220 .map (tuple -> new NameAndSalaryDto (tuple .getItem1 (), tuple .getItem2 ()))
225221 .collect (Collectors .toList ());
226222 }
227223
228224 public void insert (Employee employee ) {
229225 Employee_ e = new Employee_ ();
230- entityql .insert (e , employee ).execute ();
226+ queryDsl .insert (e ). single ( employee ).execute ();
231227 }
232228
233- public void insertByNativeSql (Employee employee ) {
229+ public void insertWithSpecifiedValues (Employee employee ) {
234230 Employee_ e = new Employee_ ();
235- nativeSql
231+ queryDsl
236232 .insert (e )
237233 .values (
238234 c -> {
@@ -252,12 +248,12 @@ public void insertByNativeSql(Employee employee) {
252248
253249 public void update (Employee employee ) {
254250 Employee_ e = new Employee_ ();
255- entityql .update (e , employee ).execute ();
251+ queryDsl .update (e ). single ( employee ).execute ();
256252 }
257253
258- public void updateByNativeSql (Employee employee ) {
254+ public void updateByWhereExpression (Employee employee ) {
259255 Employee_ e = new Employee_ ();
260- nativeSql
256+ queryDsl
261257 .update (e )
262258 .set (
263259 c -> {
@@ -276,26 +272,26 @@ public void updateByNativeSql(Employee employee) {
276272
277273 public void delete (Employee employee ) {
278274 Employee_ e = new Employee_ ();
279- entityql .delete (e , employee ).execute ();
275+ queryDsl .delete (e ). single ( employee ).execute ();
280276 }
281277
282- public void deleteByNativeSql (Employee employee ) {
278+ public void deleteByWhereExpression (Employee employee ) {
283279 Employee_ e = new Employee_ ();
284- nativeSql .delete (e ).where (c -> c .eq (e .id , employee .getId ())).execute ();
280+ queryDsl .delete (e ).where (c -> c .eq (e .id , employee .getId ())).execute ();
285281 }
286282
287283 public void batchInsert (List <Employee > employees ) {
288284 Employee_ e = new Employee_ ();
289- entityql .insert (e , employees ).execute ();
285+ queryDsl .insert (e ). batch ( employees ).execute ();
290286 }
291287
292288 public void batchUpdate (List <Employee > employees ) {
293289 Employee_ e = new Employee_ ();
294- entityql .update (e , employees ).execute ();
290+ queryDsl .update (e ). batch ( employees ).execute ();
295291 }
296292
297293 public void batchDelete (List <Employee > employees ) {
298294 Employee_ e = new Employee_ ();
299- entityql .delete (e , employees ).execute ();
295+ queryDsl .delete (e ). batch ( employees ).execute ();
300296 }
301297}
0 commit comments