deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject git commit: DELTASPIKE-617 typedQuery utility method.
Date Tue, 27 May 2014 16:03:25 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master ba17e1f9e -> 271b24a4f


DELTASPIKE-617 typedQuery utility method.


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

Branch: refs/heads/master
Commit: 271b24a4fa0f84d73d39a4bc961a42b050446e42
Parents: ba17e1f
Author: Thomas Hug <Thomas.Hug@ctp.com>
Authored: Tue May 27 09:02:00 2014 -0700
Committer: Thomas Hug <Thomas.Hug@ctp.com>
Committed: Tue May 27 09:02:50 2014 -0700

----------------------------------------------------------------------
 .../deltaspike/data/api/AbstractEntityRepository.java    | 11 ++++++++---
 .../data/impl/handler/EntityRepositoryHandler.java       |  5 +++++
 .../deltaspike/data/test/service/SimpleRepository.java   |  2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/271b24a4/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
index 41659b9..1010934 100755
--- a/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
+++ b/deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java
@@ -21,6 +21,7 @@ package org.apache.deltaspike.data.api;
 import java.io.Serializable;
 
 import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaQuery;
 
 
@@ -38,9 +39,6 @@ public abstract class AbstractEntityRepository<E, PK extends Serializable>
 
     /**
      * Utility method to get hold of the entity manager for this Repository.
-     * This method can be overridden and decorated with qualifiers. If done, the qualifiers
-     * will be used to resolve a specific entity manager other than the default one.
-     *
      * @return          Entity manager instance.
      */
     protected abstract EntityManager entityManager();
@@ -52,6 +50,13 @@ public abstract class AbstractEntityRepository<E, PK extends Serializable>
     protected abstract CriteriaQuery<E> criteriaQuery();
 
     /**
+     * Utility method to create a typed query.
+     * @param qlString  Query string
+     * @return          Typed query
+     */
+    protected abstract TypedQuery<E> typedQuery(String qlString);
+
+    /**
      * Get the entity class this Repository is related to.
      * @return          Repository entity class.
      */

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/271b24a4/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
index 0c6ce40..7d87e1d 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/handler/EntityRepositoryHandler.java
@@ -197,6 +197,11 @@ public class EntityRepositoryHandler<E, PK extends Serializable>
         return entityManager().getCriteriaBuilder().createQuery(entityClass());
     }
 
+    public TypedQuery<E> typedQuery(String qlString)
+    {
+        return entityManager().createQuery(qlString, entityClass());
+    }
+
     @SuppressWarnings("unchecked")
     public Class<E> entityClass()
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/271b24a4/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
index 45301ea..8cc16eb 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
@@ -43,7 +43,7 @@ public abstract class SimpleRepository extends AbstractEntityRepository<Simple,
     public List<Simple> implementedQueryByName(String name)
     {
         String query = "select s from Simple s where s.name = :name";
-        return entityManager().createQuery(query, Simple.class)
+        return typedQuery(query)
                 .setParameter("name", name)
                 .getResultList();
     }


Mime
View raw message