You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/18 17:50:59 UTC

[isis] branch master updated: ISIS-2033: adds support for named queries (for JPA)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new daf5425  ISIS-2033: adds support for named queries (for JPA)
daf5425 is described below

commit daf5425d152782cf8a2f1eb0a9e7d3ead9ba8560
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Dec 18 18:50:43 2020 +0100

    ISIS-2033: adds support for named queries (for JPA)
---
 .../metamodel/JpaEntityFacetFactory.java           | 22 +++++++++++++++++++---
 .../apache/isis/testdomain/jpa/JpaQueryTest.java   |  3 +--
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java b/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java
index a278b29..8c5ba6a 100644
--- a/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java
+++ b/persistence/jpa/integration/src/main/java/org/apache/isis/persistence/jpa/integration/metamodel/JpaEntityFacetFactory.java
@@ -179,14 +179,30 @@ public class JpaEntityFacetFactory extends FacetFactoryAbstract {
                 
             } else if(query instanceof NamedQuery) {
                 
-                val queryNamed = (NamedQuery<?>) query;
-                val queryResultType = queryNamed.getResultType();
+                val applibNamedQuery = (NamedQuery<?>) query;
+                val queryResultType = applibNamedQuery.getResultType();
                 
+                val entityManager = getEntityManager();
+                
+                val namedQuery = entityManager
+                        .createNamedQuery(applibNamedQuery.getName(), queryResultType)
+                        .setFirstResult(Math.toIntExact(applibNamedQuery.getStart()))
+                        .setMaxResults(Math.toIntExact(
+                                NON_NEGATIVE_INTS.bounded(applibNamedQuery.getCount())));
                 
+                applibNamedQuery
+                    .getParametersByName()
+                    .forEach((paramName, paramValue)->
+                        namedQuery.setParameter(paramName, paramValue));
+
+                return Can.ofStream(
+                        namedQuery.getResultStream()
+                        .map(entity->ManagedObject.of(spec, entity)));
                 
             }
             
-            throw _Exceptions.notImplemented();
+            throw _Exceptions.unsupportedOperation(
+                    "Support for Query of type %s not implemented.", query.getClass());
         }
 
         @Override
diff --git a/regressiontests/stable/src/test/java/org/apache/isis/testdomain/jpa/JpaQueryTest.java b/regressiontests/stable/src/test/java/org/apache/isis/testdomain/jpa/JpaQueryTest.java
index 5676429..2b43498 100644
--- a/regressiontests/stable/src/test/java/org/apache/isis/testdomain/jpa/JpaQueryTest.java
+++ b/regressiontests/stable/src/test/java/org/apache/isis/testdomain/jpa/JpaQueryTest.java
@@ -156,8 +156,7 @@ class JpaQueryTest extends IsisIntegrationTestAbstract {
                 2);
     }
     
-    //TODO[2033] no implementation of named queries for JPA yet
-    @Test @Order(4) @Disabled("no implementation of named queries for JPA yet")
+    @Test @Order(4)
     void sampleInventory_shouldSupportNamedQueries() {
         
         setUp3Books();