@@ -29,10 +29,6 @@ configuration = MyProgramConfiguration.read();
2929EntityManagerFactory emf =
3030 dbUtils. createAutoclosingEntityManagerFactory(MyProgram . class, " my-server" );
3131
32- // Create a JpqlTransactionManager which will be used to maintain transactions
33- // throughout the server.
34- JpqlTransactionManager jpqlTransactionManager = new JpqlTransactionManager (emf);
35-
3632// Create the server.
3733HttpServer server = HttpServer . builder()
3834 .applicationName(" my-rest-server" )
@@ -115,9 +111,8 @@ And lastly, update the server-code so that we expose the endpoint.
115111// Last line here is the creation of the server ending with ".build()"
116112
117113// 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) )
119115 .path(" users" )
120- .dao(new JpqlDao<UserJpa > (emf, UserJpa . class))
121116 .endpoints(Endpoint . ALL )
122117 .addRoleFor(Endpoint . ALL , RoleBuilder . open())
123118 .getListInterceptor()
@@ -182,9 +177,8 @@ If you have long-running operations, you better choose an async-extension point.
182177#### Example
183178
184179``` java
185- server. handlerGroupFor(SomeSingletonJpa . class, SomeSingletonJson . class, jpqlTransactionManager )
180+ server. handlerGroupFor(SomeSingletonJpa . class, SomeSingletonJson . class, new JpqlAsyncDao< SomeSingletonJpa > (emf, SomeSingletonJpa . class) )
186181 .path(" cmd/somesingleton" )
187- .dao(new JpqlAsyncDao<SomeSingletonJpa > (emf, SomeSingletonJpa . class))
188182 .endpoints(Endpoint . ALL )
189183 .addRoleFor(Endpoint . ALL , RoleBuilder . open())
190184 .extension()
@@ -212,9 +206,8 @@ Run in their own context, detached from the request-response-process and therefo
212206#### Example
213207
214208``` java
215- server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, jpqlTransactionManager )
209+ server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, subscriptionDao )
216210 .path(" /subscriptions" )
217- .dao(subscriptionDao)
218211 .endpoints(Endpoint . ALL )
219212 .addRoleFor(Endpoint . ALL , RoleBuilder . open())
220213 .extension()
@@ -253,9 +246,8 @@ Be cautious when using those and be sure to have the right indexes on your datab
253246##### Example 1
254247
255248``` java
256- server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, jpqlTransactionManager )
249+ server. handlerGroupFor(SubscriptionJpa . class, SubscriptionJson . class, subscriptionDao )
257250 .path(" /subscriptions" )
258- .dao(subscriptionDao)
259251 .endpoints(Endpoint . ALL )
260252 .addRoleFor(Endpoint . ALL , RoleBuilder . open())
261253 .getListInterceptor()
@@ -353,9 +345,8 @@ public class InterceptorData {
353345# #### Example
354346
355347` ` ` java
356- server.handlerGroupFor(SubscriptionJpa.class, SubscriptionJson.class, jpqlTransactionManager )
348+ server.handlerGroupFor(SubscriptionJpa.class, SubscriptionJson.class, subscriptionDao )
357349 .path("/subscriptions")
358- .dao(subscriptionDao)
359350 .endpoints(Endpoint.ALL)
360351 .addRoleFor(Endpoint.ALL, RoleBuilder.open())
361352 .getListInterceptor(subscriptionInterceptor::select)
@@ -375,5 +366,58 @@ public InterceptorData select(final Context ctx, final HandlerUtils hu) {
375366 ...
376367` ` `
377368
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();
378406
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+ ```
379423
0 commit comments