deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johndam...@apache.org
Subject deltaspike git commit: DELTASPIKE-1089 Added attribute to turn off forced entity conversion in native queries.
Date Thu, 02 Jun 2016 01:01:03 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master df1a0c9d4 -> 946b88a7b


DELTASPIKE-1089 Added attribute to turn off forced entity conversion in native queries.


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/946b88a7
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/946b88a7
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/946b88a7

Branch: refs/heads/master
Commit: 946b88a7ba2738411c203d414aab7548ea549e46
Parents: df1a0c9
Author: John D. Ament <johndament@apache.org>
Authored: Wed Jun 1 21:00:59 2016 -0400
Committer: John D. Ament <johndament@apache.org>
Committed: Wed Jun 1 21:00:59 2016 -0400

----------------------------------------------------------------------
 .../main/java/org/apache/deltaspike/data/api/Query.java  |  6 ++++++
 .../data/impl/builder/AnnotatedQueryBuilder.java         |  9 ++++++++-
 .../data/impl/handler/EntityRepositoryHandlerTest.java   | 11 +++++++++++
 .../data/test/service/SimpleIntermediateRepository.java  |  4 ++++
 4 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/946b88a7/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/Query.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/Query.java
b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/Query.java
index 9e09150..cd532c2 100755
--- a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/Query.java
+++ b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/Query.java
@@ -80,4 +80,10 @@ public @interface Query
      */
     SingleResultType singleResult() default SingleResultType.JPA;
 
+    /**
+     * For native queries only, whether or not this query returns the defined entity class
or not.
+     * Due to type erasure from generics, we don't have runtime information about the return
collection
+     */
+    boolean returnsEntity() default true;
+
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/946b88a7/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
index 4421717..1d8b0d5 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/AnnotatedQueryBuilder.java
@@ -70,7 +70,14 @@ public class AnnotatedQueryBuilder extends QueryBuilder
         else if (query.isNative())
         {
             String jpqlQuery = context.applyQueryStringPostProcessors(query.value());
-            result = params.applyTo(entityManager.createNativeQuery(jpqlQuery, context.getEntityClass()));
+            if (query.returnsEntity())
+            {
+                result = params.applyTo(entityManager.createNativeQuery(jpqlQuery, context.getEntityClass()));
+            }
+            else
+            {
+                result = params.applyTo(entityManager.createNativeQuery(jpqlQuery));
+            }
         }
         else
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/946b88a7/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
index 6a8eb2a..778552d 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandlerTest.java
@@ -477,4 +477,15 @@ public class EntityRepositoryHandlerTest extends TransactionalTestCase
         assertEquals(id, found.getId());
     }
 
+    @Test
+    public void should_query_names()
+    {
+        String name = "should_return_entity_primary_key";
+        testData.createSimple(name);
+
+        List<String> names = intermediate.findAllNames();
+
+        assertEquals(name, names.get(0));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/946b88a7/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleIntermediateRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleIntermediateRepository.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleIntermediateRepository.java
index 85ea36e..53fa47d 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleIntermediateRepository.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleIntermediateRepository.java
@@ -25,6 +25,7 @@ import org.apache.deltaspike.data.api.Repository;
 import org.apache.deltaspike.data.test.domain.Simple;
 
 import javax.persistence.QueryHint;
+import java.util.List;
 
 @Repository
 public interface SimpleIntermediateRepository extends EntityRepository<Simple, Long>
@@ -34,4 +35,7 @@ public interface SimpleIntermediateRepository extends EntityRepository<Simple,
L
             @QueryHint(name = "org.hibernate.comment", value = "I'm a little comment short
and stout")
     })
     Simple findBy(Long id);
+
+    @Query(value = "select name from simple_table", isNative = true, returnsEntity = false)
+    List<String> findAllNames();
 }


Mime
View raw message