openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r595912 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test...
Date Sat, 17 Nov 2007 06:38:36 GMT
Author: pcl
Date: Fri Nov 16 22:38:33 2007
New Revision: 595912

URL: http://svn.apache.org/viewvc?rev=595912&view=rev
Log:
OPENJPA-200

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
    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/fields/TestEnumsInJPQL.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=595912&r1=595911&r2=595912&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Fri Nov 16 22:38:33 2007
@@ -85,6 +85,7 @@
 import org.apache.openjpa.jdbc.schema.Table;
 import org.apache.openjpa.jdbc.schema.Unique;
 import org.apache.openjpa.kernel.Filters;
+import org.apache.openjpa.kernel.exps.Path;
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.jdbc.ConnectionDecorator;
@@ -95,13 +96,13 @@
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.util.GeneralException;
 import org.apache.openjpa.util.InternalException;
+import org.apache.openjpa.util.InvalidStateException;
 import org.apache.openjpa.util.OpenJPAException;
 import org.apache.openjpa.util.ReferentialIntegrityException;
 import org.apache.openjpa.util.Serialization;
 import org.apache.openjpa.util.StoreException;
 import org.apache.openjpa.util.UnsupportedException;
 import org.apache.openjpa.util.UserException;
-import org.apache.openjpa.util.InvalidStateException;
 import serp.util.Numbers;
 import serp.util.Strings;
 
@@ -1897,7 +1898,8 @@
 
         for (Iterator i = updateParams.entrySet().iterator(); i.hasNext();) {
             Map.Entry next = (Map.Entry) i.next();
-            FieldMapping fmd = (FieldMapping) next.getKey();
+            Path path = (Path) next.getKey();
+            FieldMapping fmd = (FieldMapping) path.last();
 
             if (fmd.isVersion())
                 augmentUpdates = false;
@@ -1909,7 +1911,9 @@
             sql.append(" = ");
 
             ExpState state = val.initialize(sel, ctx, 0);
-            val.calculateValue(sel, ctx, state, null, null);
+            // JDBC Paths are always PCPaths; PCPath implements Val
+            ExpState pathState = ((Val) path).initialize(sel, ctx, 0);
+            val.calculateValue(sel, ctx, state, (Val) path, pathState);
 
             // append the value with a null for the Select; i
             // indicates that the
@@ -1922,9 +1926,9 @@
         }
 
         if (augmentUpdates) {
-            ClassMapping meta =
-                ((FieldMapping) updateParams.keySet().iterator().next())
-                    .getDeclaringMapping();
+            Path path = (Path) updateParams.keySet().iterator().next();
+            FieldMapping fm = (FieldMapping) path.last();
+            ClassMapping meta = fm.getDeclaringMapping();
             Map updates = meta.getVersion().getBulkUpdateValues();
             for (Iterator iter = updates.entrySet().iterator();
                 iter.hasNext(); ) {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java?rev=595912&r1=595911&r2=595912&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
Fri Nov 16 22:38:33 2007
@@ -83,10 +83,10 @@
     /**
      * Add an update.
      */
-    public void putUpdate(FieldMetaData fmd, Value val) {
+    public void putUpdate(Path path, Value val) {
         if (updates == Collections.EMPTY_MAP)
             updates = new HashMap();
-        updates.put(fmd, val);
+        updates.put(path, val);
     }
 
     /**

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=595912&r1=595911&r2=595912&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
Fri Nov 16 22:38:33 2007
@@ -467,9 +467,9 @@
         // handle SET field = value
         JPQLNode[] nodes = root().findChildrenByID(JJTUPDATEITEM);
         for (int i = 0; nodes != null && i < nodes.length; i++) {
-            FieldMetaData field = getPath(firstChild(nodes[i])).last();
+            Path path = getPath(firstChild(nodes[i]));
             Value val = getValue(onlyChild(lastChild(nodes[i])));
-            exps.putUpdate(field, val);
+            exps.putUpdate(path, val);
         }
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java?rev=595912&r1=595911&r2=595912&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java
Fri Nov 16 22:38:33 2007
@@ -39,29 +39,45 @@
 
     public void testEnumLiteralInSelect() {
         Query q = em.createQuery("select count(o) from EnumFieldType o where " +
-            "o.enumField = org.apache.openjpa.persistence.fields.SampleEnum.BAR");
+            "o.enumField = " +
+            "org.apache.openjpa.persistence.fields.SampleEnum.BAR");
         assertEquals(1, ((Number) q.getSingleResult()).intValue());
     }
 
-    // fails currently
-    public void xtestEnumLiteralInUpdate() {
+    public void testEnumLiteralInSetInUpdate() {
         testEnumLiteralInSelect();
         em.getTransaction().begin();
         Query q = em.createQuery("update EnumFieldType o set " +
-            "o.enumField = org.apache.openjpa.persistence.fields.SampleEnum.BAZ");
+            "o.enumField = " +
+            "org.apache.openjpa.persistence.fields.SampleEnum.BAZ");
         assertEquals(1, ((Number) q.executeUpdate()).intValue());
         em.getTransaction().commit();
-        postUpdateCheck();
+        postUpdateCheck(true);
     }
 
-    private void postUpdateCheck() {
+    public void testEnumLiteralInWhereInUpdate() {
+        testEnumLiteralInSelect();
+        em.getTransaction().begin();
+        Query q = em.createQuery("update EnumFieldType o set o.intField = 3 " +
+            "where o.enumField = " +
+            "org.apache.openjpa.persistence.fields.SampleEnum.BAR");
+        assertEquals(1, ((Number) q.executeUpdate()).intValue());
+        em.getTransaction().commit();
+        postUpdateCheck(false);
+    }
+
+    private void postUpdateCheck(boolean wasEnumModified) {
         Query q = em.createQuery("select count(o) from EnumFieldType o where " +
-            "o.enumField = org.apache.openjpa.persistence.fields.SampleEnum.BAR");
-        assertEquals(0, ((Number) q.getSingleResult()).intValue());
+            "o.enumField = " +
+            "org.apache.openjpa.persistence.fields.SampleEnum.BAR");
+        assertEquals(wasEnumModified ? 0 : 1,
+            ((Number) q.getSingleResult()).intValue());
 
         q = em.createQuery("select count(o) from EnumFieldType o where " +
-            "o.enumField = org.apache.openjpa.persistence.fields.SampleEnum.BAZ");
-        assertEquals(1, ((Number) q.getSingleResult()).intValue());
+            "o.enumField = " +
+            "org.apache.openjpa.persistence.fields.SampleEnum.BAZ");
+        assertEquals(wasEnumModified ? 1 : 0,
+            ((Number) q.getSingleResult()).intValue());
     }
 
     public void testEnumPositionalParamInSelect() {
@@ -78,15 +94,25 @@
         assertEquals(1, ((Number) q.getSingleResult()).intValue());
     }
 
-    // fails currently
-    public void xtestEnumParamInUpdate() {
+    public void testEnumParamInSetInUpdate() {
         testEnumLiteralInSelect();
         em.getTransaction().begin();
         Query q = em.createQuery("update EnumFieldType o set o.enumField = :e");
         q.setParameter("e", SampleEnum.BAZ);
         assertEquals(1, ((Number) q.executeUpdate()).intValue());
         em.getTransaction().commit();
-        postUpdateCheck();
+        postUpdateCheck(true);
+    }
+
+    public void testEnumParamInWhereInUpdate() {
+        testEnumLiteralInSelect();
+        em.getTransaction().begin();
+        Query q = em.createQuery("update EnumFieldType o set o.intField = 3 " +
+            "where o.enumField = :e");
+        q.setParameter("e", SampleEnum.BAR);
+        assertEquals(1, ((Number) q.executeUpdate()).intValue());
+        em.getTransaction().commit();
+        postUpdateCheck(false);
     }
 
     public void xtestInMemory() {



Mime
View raw message