@@ -29,10 +29,6 @@ configuration = MyProgramConfiguration.read();
29
29
EntityManagerFactory emf =
30
30
dbUtils. createAutoclosingEntityManagerFactory(MyProgram . class, " my-server" );
31
31
32
- // Create a JpqlTransactionManager which will be used to maintain transactions
33
- // throughout the server.
34
- JpqlTransactionManager jpqlTransactionManager = new JpqlTransactionManager (emf);
35
-
36
32
// Create the server.
37
33
HttpServer server = HttpServer . builder()
38
34
.applicationName(" my-rest-server" )
@@ -115,9 +111,8 @@ And lastly, update the server-code so that we expose the endpoint.
115
111
// Last line here is the creation of the server ending with ".build()"
116
112
117
113
// Register a custom handler for the resource 'user'.
118
- server. handlerGroupFor(UserJpa . class, UserJson . class, jpqlTransactionManager )
114
+ server. handlerGroupFor(UserJpa . class, UserJson . class, new JpqlDao< UserJpa > (emf, UserJpa . class) )
119
115
.path(" users" )
120
- .dao(new JpqlDao<UserJpa > (emf, UserJpa . class))
121
116
.endpoints(Endpoint . ALL )
122
117
.addRoleFor(Endpoint . ALL , RoleBuilder . open())
123
118
.getListInterceptor()
@@ -182,9 +177,8 @@ If you have long-running operations, you better choose an async-extension point.
182
177
#### Example
183
178
184
179
``` java
185
- server. handlerGroupFor(SomeSingletonJpa . class, SomeSingletonJson . class, jpqlTransactionManager )
180
+ server. handlerGroupFor(SomeSingletonJpa . class, SomeSingletonJson . class, new JpqlAsyncDao< SomeSingletonJpa > (emf, SomeSingletonJpa . class) )
186
181
.path(" cmd/somesingleton" )
187
- .dao(new JpqlAsyncDao<SomeSingletonJpa > (emf, SomeSingletonJpa . class))
188
182
.endpoints(Endpoint . ALL )
189
183
.addRoleFor(Endpoint . ALL , RoleBuilder . open())
190
184
.extension()
@@ -212,9 +206,8 @@ Run in their own context, detached from the request-response-process and therefo
212
206
#### Example
213
207
214
208
``` java
215
- server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, jpqlTransactionManager )
209
+ server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, subscriptionDao )
216
210
.path(" /subscriptions" )
217
- .dao(subscriptionDao)
218
211
.endpoints(Endpoint . ALL )
219
212
.addRoleFor(Endpoint . ALL , RoleBuilder . open())
220
213
.extension()
@@ -253,9 +246,8 @@ Be cautious when using those and be sure to have the right indexes on your datab
253
246
##### Example 1
254
247
255
248
``` java
256
- server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, jpqlTransactionManager )
249
+ server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, subscriptionDao )
257
250
.path(" /subscriptions" )
258
- .dao(subscriptionDao)
259
251
.endpoints(Endpoint . ALL )
260
252
.addRoleFor(Endpoint . ALL , RoleBuilder . open())
261
253
.getListInterceptor()
@@ -353,9 +345,8 @@ public class InterceptorData {
353
345
# #### Example
354
346
355
347
` ` ` java
356
- server.handlerGroupFor(SubscriptionJpa.class, SubscriptionJson.class, jpqlTransactionManager )
348
+ server.handlerGroupFor(SubscriptionJpa.class, SubscriptionJson.class, subscriptionDao )
357
349
.path("/subscriptions")
358
- .dao(subscriptionDao)
359
350
.endpoints(Endpoint.ALL)
360
351
.addRoleFor(Endpoint.ALL, RoleBuilder.open())
361
352
.getListInterceptor(subscriptionInterceptor::select)
@@ -375,5 +366,58 @@ public InterceptorData select(final Context ctx, final HandlerUtils hu) {
375
366
...
376
367
` ` `
377
368
369
+ # ### Business-Logic SQL Queries
370
+
371
+ In order to keep SQL- queries somewhat consistent and because of my deep aversion of Criteria queries, I' ve used the following ' query language' you can get calling every `JpqlDao<JpaType>`.
372
+
373
+ ##### Examples
374
+
375
+ ```java
376
+ // Insert...
377
+ userDao.insert(entity).execute();
378
+ userDao.insert(entity).entityManager(em).execute();
379
+
380
+ // Full-Update...
381
+ userDao.update(entity).execute();
382
+ userDao.update(entity).entityManager(em).execute();
383
+
384
+ // Single-Result Query...
385
+ SingleQueryBuilder<NexusUserJpa, NexusUserJpa> single = userDao.select(32L);
386
+ single.delete();
387
+ NexusUserJpa en = single.get();
388
+
389
+ // List-Result Query...
390
+ JpaListQuery<NexusUserJpa> query;
391
+ query = userDao.select().build();
392
+ query = userDao.select().entityManager(em).build();
393
+ query = userDao.select().where("o.id = :id").addParam("id", 32L).build();
394
+ query = userDao.select()
395
+ .where("o.priority > :priority AND o.enabled = :enabled AND userId IS NOT NULL")
396
+ .addParam("priority", 10L)
397
+ .addParam("enabled", true)
398
+ .desc("o.priority")
399
+ .lockPessimistic()
400
+ .build();
401
+ query = userDao.select("o")
402
+ .join("LEFT JOIN GroupJpa g ON g.id = o.groupId")
403
+ .where("g.enabled = :enabled")
404
+ .addParam("enabled", true)
405
+ .build();
378
406
407
+ // Delete all list-results.
408
+ query.delete();
409
+
410
+ // Upsert first element of list-results.
411
+ query.upsert(entity);
412
+
413
+ // Various ways to get some or all entities from the list-results.
414
+ NexusUserJpa a = query.getFirst();
415
+ List<NexusUserJpa> b = query.getList();
416
+ List<NexusUserJpa> c = query.getList(0, 10);
417
+ ListJson<NexusUserJpa> d = query.getListJson();
418
+ ListJson<NexusUserJpa> e = query.getListJson(10, 10);
419
+ List<NexusUserJpa> f = query.getListReversed();
420
+ List<NexusUserJpa> g = query.getN(22);
421
+ NexusUserJpa h = query.getSingle();
422
+ ```
379
423
0 commit comments