openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r595910 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java
Date Sat, 17 Nov 2007 05:29:02 GMT
Author: pcl
Date: Fri Nov 16 21:28:58 2007
New Revision: 595910

URL: http://svn.apache.org/viewvc?rev=595910&view=rev
Log:
New test case for enums and JPQL (including some disabled failing tests related to OPENJPA-200);
simplification to JDBCStoreManager.

Added:
    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/kernel/JDBCStoreQuery.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java?rev=595910&r1=595909&r2=595910&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
Fri Nov 16 21:28:58 2007
@@ -28,7 +28,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Iterator;
 
 import org.apache.openjpa.event.LifecycleEventManager;
 import org.apache.openjpa.jdbc.kernel.exps.ExpContext;
@@ -63,7 +62,6 @@
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.ValueMetaData;
-import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.util.UserException;
 import serp.util.Numbers;
 
@@ -422,20 +420,20 @@
     protected Number executeDelete(Executor ex, ClassMetaData base,
         ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts,
         QueryExpressions[] exps, Object[] params) {
-        return executeBulkOperation(ex, base, metas, subclasses, facts, exps,
+        return executeBulkOperation(metas, subclasses, facts, exps,
             params, null);
     }
 
     protected Number executeUpdate(Executor ex, ClassMetaData base,
         ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts,
         QueryExpressions[] exps, Object[] params) {
-        return executeBulkOperation(ex, base, metas, subclasses, facts, exps,
+        return executeBulkOperation(metas, subclasses, facts, exps,
             params, exps[0].updates);
     }
 
-    private Number executeBulkOperation(Executor ex, ClassMetaData base,
-        ClassMetaData[] metas, boolean subclasses, ExpressionFactory[] facts,
-        QueryExpressions[] exps, Object[] params, Map updates) {
+    private Number executeBulkOperation(ClassMetaData[] metas,
+        boolean subclasses, ExpressionFactory[] facts, QueryExpressions[] exps,
+        Object[] params, Map updates) {
         // we cannot execute a bulk delete statement when have mappings in
         // multiple tables, so indicate we want to use in-memory with null
         ClassMapping[] mappings = (ClassMapping[]) metas;

Added: 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=595910&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fields/TestEnumsInJPQL.java
Fri Nov 16 21:28:58 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.fields;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+public class TestEnumsInJPQL
+    extends SingleEMTestCase {
+
+    public void setUp() {
+        setUp(EnumFieldType.class, CLEAR_TABLES);
+
+        EnumFieldType o = new EnumFieldType();
+        o.setEnumField(SampleEnum.BAR);
+        em.getTransaction().begin();
+        em.persist(o);
+        em.getTransaction().commit();
+        em.close();
+        em = emf.createEntityManager();
+    }
+
+    public void testEnumLiteralInSelect() {
+        Query q = em.createQuery("select count(o) from EnumFieldType o where " +
+            "o.enumField = org.apache.openjpa.persistence.fields.SampleEnum.BAR");
+        assertEquals(1, ((Number) q.getSingleResult()).intValue());
+    }
+
+    // fails currently
+    public void xtestEnumLiteralInUpdate() {
+        testEnumLiteralInSelect();
+        em.getTransaction().begin();
+        Query q = em.createQuery("update EnumFieldType o set " +
+            "o.enumField = org.apache.openjpa.persistence.fields.SampleEnum.BAZ");
+        assertEquals(1, ((Number) q.executeUpdate()).intValue());
+        em.getTransaction().commit();
+        postUpdateCheck();
+    }
+
+    private void postUpdateCheck() {
+        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());
+
+        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());
+    }
+
+    public void testEnumPositionalParamInSelect() {
+        Query q = em.createQuery("select count(o) from EnumFieldType o where " +
+            "o.enumField = ?1");
+        q.setParameter(1, SampleEnum.BAR);
+        assertEquals(1, ((Number) q.getSingleResult()).intValue());
+    }
+
+    public void testEnumNamedParamInSelect() {
+        Query q = em.createQuery("select count(o) from EnumFieldType o where " +
+            "o.enumField = :e");
+        q.setParameter("e", SampleEnum.BAR);
+        assertEquals(1, ((Number) q.getSingleResult()).intValue());
+    }
+
+    // fails currently
+    public void xtestEnumParamInUpdate() {
+        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();
+    }
+
+    public void xtestInMemory() {
+        fail("unimplemented");
+    }
+}
\ No newline at end of file



Mime
View raw message