openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r725078 - in /openjpa/trunk/openjpa-slice/src/test: java/org/apache/openjpa/slice/TestQuery.java java/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java resources/META-INF/persistence.xml
Date Wed, 10 Dec 2008 13:03:08 GMT
Author: ppoddar
Date: Wed Dec 10 05:03:08 2008
New Revision: 725078

URL: http://svn.apache.org/viewvc?rev=725078&view=rev
Log:
OPENJPA-820: Test entity reference can be used as query parameter for slices.

Modified:
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java
    openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java?rev=725078&r1=725077&r2=725078&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java Wed
Dec 10 05:03:08 2008
@@ -40,7 +40,8 @@
     }
 
     public void setUp() throws Exception {
-        super.setUp(PObject.class, Person.class, Address.class, CLEAR_TABLES);
+        super.setUp(PObject.class, Person.class, Address.class, Country.class, 
+        		CLEAR_TABLES);
         int count = count(PObject.class);
         if (count == 0) {
             create(POBJECT_COUNT);
@@ -58,6 +59,21 @@
             String expected = (pc.getValue()%2 == 0) ? "Even" : "Odd";
             assertEquals(expected, slice);
         }
+        Person p1 = new Person();
+        Person p2 = new Person();
+        Address a1 = new Address();
+        Address a2 = new Address();
+        p1.setName("Even");
+        p2.setName("Odd");
+        a1.setCity("San Francisco");
+        a2.setCity("Rome");
+        p1.setAddress(a1);
+        p2.setAddress(a2);
+        em.persist(p1);
+        em.persist(p2);
+        assertEquals("Even", SlicePersistence.getSlice(p1));
+        assertEquals("Odd", SlicePersistence.getSlice(p2));
+        
         em.getTransaction().commit();
     }
     
@@ -147,4 +163,30 @@
         List result = query.getResultList();
         em.getTransaction().rollback();
     }
+    
+    public void testQueryParameter() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        Query query = em.createQuery("SELECT p FROM PObject p WHERE p.value > :v")
+        	.setParameter("v", 200);
+        List result = query.getResultList();
+        em.getTransaction().rollback();
+    }
+    
+    public void testQueryParameterEntity() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        Address a = (Address)em.createQuery("select a from Address a where a.city = :city")
+        	.setParameter("city", "Rome").getSingleResult();
+        assertNotNull(a);
+        assertEquals("Odd", SlicePersistence.getSlice(a));
+        Query query = em.createQuery("SELECT p FROM Person p WHERE p.address = :a")
+        	.setParameter("a", a);
+        List<Person> result = query.getResultList();
+        assertEquals(1, result.size());
+        Person p = result.get(0);
+        assertEquals("Odd", SlicePersistence.getSlice(p));
+        assertEquals("Rome", p.getAddress().getCity());
+        em.getTransaction().rollback();
+    }
 }

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java?rev=725078&r1=725077&r2=725078&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/policy/EvenOddDistributionPolicy.java
Wed Dec 10 05:03:08 2008
@@ -30,6 +30,11 @@
             int v = ((PObject)pc).getValue();
             return (v%2 == 0) ? "Even" : "Odd";
         }
+        if (pc instanceof Person) {
+        	String name = ((Person)pc).getName();
+        	char firstChar = Character.toLowerCase(name.charAt(0));
+        	return (firstChar >= 'a' && firstChar <='m') ? "Even" : "Odd";
+        }
         return null;
     }
 

Modified: openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml?rev=725078&r1=725077&r2=725078&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml Wed Dec 10 05:03:08
2008
@@ -108,6 +108,9 @@
    
       <persistence-unit name="ordering">
         <class>org.apache.openjpa.slice.PObject</class>
+        <class>org.apache.openjpa.slice.Person</class>
+        <class>org.apache.openjpa.slice.Address</class>
+        <class>org.apache.openjpa.slice.Country</class>
         <properties>
             <property name="openjpa.BrokerFactory" value="slice"/>
             <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>



Mime
View raw message