openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r654272 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta...
Date Wed, 07 May 2008 21:06:19 GMT
Author: ppoddar
Date: Wed May  7 14:06:16 2008
New Revision: 654272

URL: http://svn.apache.org/viewvc?rev=654272&view=rev
Log:
OPENJPA-586 Query parameter binding for externalized fields

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=654272&r1=654271&r2=654272&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Wed May  7 14:06:16 2008
@@ -1160,7 +1160,7 @@
         if (fmd == null)
             return;
 
-        Class type = path.isXPath() ? path.getType() : fmd.getType();
+        Class type = path.isXPath() ? path.getType() : fmd.getDeclaredType();
         if (type == null)
             return;
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java?rev=654272&r1=654271&r2=654272&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
Wed May  7 14:06:16 2008
@@ -19,18 +19,26 @@
 package org.apache.openjpa.persistence.meta;
 
 
+import java.util.List;
+import java.util.UUID;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
 import org.apache.openjpa.persistence.meta.common.apps.ExternalValues;
 import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import org.apache.openjpa.persistence.ArgumentException;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 
 /**
  * <p>Tests the {@link ExternalValuesFieldMapping}.</p>
  *
  * @author Abe White
+ * @author Pinaki Poddar (added binding query parameter tests) 
  */
 public class TestExternalValues
     extends AbstractTestCase {
-
+    
     public TestExternalValues(String test) {
         super(test, "metacactusapp");
     }
@@ -55,7 +63,6 @@
         pc.setDoubleToByte(4.5);
         pc.setCharToInt('f');
         pc.setStringToLong("foo");
-
         pm.persist(pc);
         Object oid = pm.getObjectId(pc);
         endTx(pm);
@@ -112,4 +119,77 @@
         pc = (ExternalValues) pm.find(ExternalValues.class, oid);
         endEm(pm);
     }
+    
+    public void testPositionalBindingQueryParameterEqualsDeclaredType() {
+        UUID uuid = new UUID(1,4);
+        createInstance(uuid);
+        
+        EntityManager em = currentEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=?1";
+        List<ExternalValues> result = em.createQuery(jpql)
+                                        .setParameter(1, uuid)
+                                        .getResultList();
+        assertFalse(result.isEmpty());
+        for (ExternalValues x:result) {
+            assertEquals(uuid, x.getUuid());
+        }
+    }
+    
+    public void testNamedBindingQueryParameterEqualsDeclaredType() {
+        UUID uuid = new UUID(2,4);
+        createInstance(uuid);
+        
+        EntityManager em = currentEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=:uuid";
+        List<ExternalValues> result = em.createQuery(jpql)
+                                        .setParameter("uuid", uuid)
+                                        .getResultList();
+        assertFalse(result.isEmpty());
+        for (ExternalValues pc:result) {
+            assertEquals(uuid, pc.getUuid());
+        }
+    }
+    
+    public void testPositionalBindingQueryParameterNotEqualsExternalizedType() {
+        UUID uuid = new UUID(1,4);
+        createInstance(uuid);
+        
+        EntityManager em = currentEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=?1";
+        Query query = em.createQuery(jpql)
+                        .setParameter(1, uuid.toString());
+                                        
+        try {
+            query.getResultList();
+            fail("Expected ArgumentException");
+       } catch (ArgumentException ex) {
+           // expected
+       }
+    }
+
+    public void testNamedBindingQueryParameterNotEqualsExternalizedType() {
+        UUID uuid = new UUID(2,4);
+        createInstance(uuid);
+        
+        EntityManager em = currentEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=:uuid";
+        Query query = em.createQuery(jpql)
+                        .setParameter("uuid", uuid.toString());
+        try {
+             query.getResultList();
+             fail("Expected ArgumentException");
+        } catch (ArgumentException ex) {
+            // expected
+        }
+    }
+    
+    private void createInstance(UUID uuid) {
+        EntityManager em = currentEntityManager();
+        em.getTransaction().begin();
+        ExternalValues pc = new ExternalValues();
+        pc.setUuid(uuid);
+        em.persist(pc);
+        em.getTransaction().commit();
+        em.clear();
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java?rev=654272&r1=654271&r2=654272&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
Wed May  7 14:06:16 2008
@@ -19,8 +19,14 @@
 package org.apache.openjpa.persistence.meta.common.apps;
 
 
+import java.util.UUID;
+
 import javax.persistence.Entity;
 
+import org.apache.openjpa.persistence.Externalizer;
+import org.apache.openjpa.persistence.Factory;
+import org.apache.openjpa.persistence.Persistent;
+
 @Entity
 public class ExternalValues {
 
@@ -33,6 +39,10 @@
     private double doubleToByte;
     private char charToInt;
     private String stringToLong;
+    @Persistent
+    @Externalizer("toString")        
+    @Factory("UUID.fromString")
+    private UUID    uuid;
 
     public boolean getBooleanToShort() {
         return booleanToShort;
@@ -105,4 +115,12 @@
     public void setStringToLong(String s) {
         stringToLong = s;
     }
+
+    public UUID getUuid() {
+        return uuid;
+    }
+
+    public void setUuid(UUID uuid) {
+        this.uuid = uuid;
+    }
 }



Mime
View raw message