openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r547872 - in /openjpa/trunk: openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNewlinesInQueries.java
Date Sat, 16 Jun 2007 06:54:12 GMT
Author: pcl
Date: Fri Jun 15 23:54:12 2007
New Revision: 547872

URL: http://svn.apache.org/viewvc?view=rev&rev=547872
Log:
OPENJPA-259. Applied Craig's patch (minus the ACK char; maybe Craig meant ^L instead?), and
added a test case. The test uses dynamic JPQL, but the parser change should work for XML-based
named queries also, and it seems fair to allow newlines in dynamic strings as well.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNewlinesInQueries.java
      - copied, changed from r544634, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt

Modified: openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt?view=diff&rev=547872&r1=547871&r2=547872
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt (original)
+++ openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt Fri
Jun 15 23:54:12 2007
@@ -117,6 +117,7 @@
 SKIP :
 {
  	" "
+    | "\n"
 	| "\r"
 	| "\t"
 }

Copied: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNewlinesInQueries.java
(from r544634, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java)
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNewlinesInQueries.java?view=diff&rev=547872&p1=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java&r1=544634&p2=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNewlinesInQueries.java&r2=547872
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNewlinesInQueries.java
Fri Jun 15 23:54:12 2007
@@ -18,83 +18,32 @@
  */
 package org.apache.openjpa.persistence.query;
 
-import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
-import junit.textui.TestRunner;
-import org.apache.openjpa.persistence.OpenJPAQuery;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
- * Test that we can exclude subclass instances from query results.
- *
- * @author Abe White
+ * Test that our parser handles newlines in queries
  */
-public class TestQueryExcludingSubclasses
+public class TestNewlinesInQueries
     extends SingleEMFTestCase {
 
     public void setUp() {
-        setUp(ManyOneEntity.class, ManyOneEntitySub.class);
-
-        ManyOneEntity e1 = new ManyOneEntity();
-        e1.setName("e1"); 
-        ManyOneEntity e2 = new ManyOneEntity();
-        e2.setName("e2"); 
-        ManyOneEntity invalid = new ManyOneEntity();
-        invalid.setName("invalid"); 
-        ManyOneEntitySub esub1 = new ManyOneEntitySub();
-        esub1.setName("esub1"); 
-        ManyOneEntitySub esub2 = new ManyOneEntitySub();
-        esub2.setName("esub2"); 
-        ManyOneEntitySub invalidsub = new ManyOneEntitySub();
-        invalidsub.setName("invalidsub"); 
+        setUp(SimpleEntity.class, CLEAR_TABLES);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
-        em.persist(e1);
-        em.persist(e2);
-        em.persist(invalid);
-        em.persist(esub1);
-        em.persist(esub2);
-        em.persist(invalidsub);
+        em.persist(new SimpleEntity("foo", "bar"));
         em.getTransaction().commit();
         em.close();
     }
 
     public void testQuery() {
         EntityManager em = emf.createEntityManager();
-        Query q = em.createQuery("select e from ManyOneEntity e "
-            + "where e.name like 'e%' order by e.name asc");
-        List<ManyOneEntity> res = (List<ManyOneEntity>) q.getResultList();
-        assertEquals(4, res.size());
-        for (int i = 0; i < 2; i++) {
-            assertEquals(ManyOneEntity.class, res.get(i).getClass());
-            assertEquals("e" + (i + 1), res.get(i).getName());
-        }
-        for (int i = 0; i < 2; i++) {
-            assertEquals(ManyOneEntitySub.class, res.get(i + 2).getClass());
-            assertEquals("esub" + (i + 1), res.get(i + 2).getName());
-        }
-        em.close();
-    }
-
-    public void testQueryExcludingSubclasses() {
-        EntityManager em = emf.createEntityManager();
-        Query q = em.createQuery("select e from ManyOneEntity e "
-            + "where e.name like 'e%' order by e.name asc");
-        ((OpenJPAQuery) q).setSubclasses(false);
-        List<ManyOneEntity> res = (List<ManyOneEntity>) q.getResultList();
-        assertEquals(2, res.size());
-        for (int i = 0; i < res.size(); i++) {
-            assertEquals(ManyOneEntity.class, res.get(i).getClass());
-            assertEquals("e" + (i + 1), res.get(i).getName());
-        }
+        Query q = em.createQuery("select e \n from simple e");
+        SimpleEntity e = (SimpleEntity) q.getSingleResult();
+        assertEquals("foo", e.getName());
         em.close();
     }
-
-    public static void main(String[] args) {
-        TestRunner.run(TestQueryExcludingSubclasses.class);
-    }
-}
-
+}
\ No newline at end of file



Mime
View raw message