openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1716891 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TupleQueryTest.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Date Fri, 27 Nov 2015 15:52:13 GMT
Author: rmannibucau
Date: Fri Nov 27 15:52:13 2015
New Revision: 1716891

URL: http://svn.apache.org/viewvc?rev=1716891&view=rev
Log:
OPENJPA-2618 pevent Tuple to pass through in createXQuery methods since we dont support it
yet

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TupleQueryTest.java
      - copied, changed from r1716854, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java
Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java

Copied: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TupleQueryTest.java
(from r1716854, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java)
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TupleQueryTest.java?p2=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TupleQueryTest.java&p1=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java&r1=1716854&r2=1716891&rev=1716891&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TupleQueryTest.java
Fri Nov 27 15:52:13 2015
@@ -18,19 +18,15 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.simple.NamedEntity;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
-/**
- * Test that we can query by an entity's abstract schema name.
- *
- * @author Abe White
- */
-public class TestAbstractSchemaName
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import javax.persistence.Tuple;
+
+public class TupleQueryTest
     extends SingleEMFTestCase {
 
     public void setUp() {
@@ -46,17 +42,20 @@ public class TestAbstractSchemaName
         em.close();
     }
 
-    public void testQuery() {
+    public void testNormalQuery() {
         EntityManager em = emf.createEntityManager();
-        Query q = em.createQuery("select e from named e");
-        NamedEntity e = (NamedEntity) q.getSingleResult();
-        assertNotNull(e);
-        assertEquals("e", e.getName());
-        em.close();
+        try {
+            em.createQuery("select e.name from named e", Tuple.class);
+            fail();
+        } catch (final PersistenceException pe) {
+            // ok
+        } finally {
+            em.close();
+        }
     }
 
     public static void main(String[] args) {
-        TestRunner.run(TestAbstractSchemaName.class);
+        TestRunner.run(TupleQueryTest.class);
     }
 }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=1716891&r1=1716890&r2=1716891&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Fri Nov 27 15:52:13 2015
@@ -46,6 +46,7 @@ import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
 import javax.persistence.PessimisticLockScope;
 import javax.persistence.Query;
+import javax.persistence.Tuple;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.ParameterExpression;
@@ -972,9 +973,16 @@ public class EntityManagerImpl
 
     @SuppressWarnings("unchecked")
     public <T> TypedQuery<T> createQuery(String query, Class<T> resultClass)
{
+        checkTuple(resultClass);
         return createQuery(query).setResultClass(resultClass);
     }
-    
+
+    private <T> void checkTuple(Class<T> resultClass) {
+        if (Tuple.class == resultClass) {
+            throw new PersistenceException("Tuple is not a valid type", null, null, true);
+        }
+    }
+
     public OpenJPAQuery createQuery(String query) {
         return createQuery(JPQLParser.LANG_JPQL, query);
     }
@@ -1014,6 +1022,7 @@ public class EntityManagerImpl
     
     @SuppressWarnings("unchecked")
     public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
{
+        checkTuple(resultClass);
         return createNamedQuery(name).setResultClass(resultClass);
     }
 
@@ -1055,6 +1064,7 @@ public class EntityManagerImpl
     }
 
     public OpenJPAQuery createNativeQuery(String query, Class cls) {
+        checkTuple(cls);
         return createNativeQuery(query).setResultClass(cls);
     }
 



Mime
View raw message