openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r798735 [1/3] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/per...
Date Wed, 29 Jul 2009 00:30:43 GMT
Author: faywang
Date: Wed Jul 29 00:30:41 2009
New Revision: 798735

URL: http://svn.apache.org/viewvc?rev=798735&view=rev
Log:
OPENJPA-1143: embeddable test case and support for Criteria

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestEmbeddableCriteria.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company1_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Company2_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Department1_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Department2_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Department3_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Division_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Coll_Embed_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Coll_Integer_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Embed_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_Embed_ToMany_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_MappedToOne_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_ToMany_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Embed_ToOne_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Employee1_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Employee2_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Employee3_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmployeeName3_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmployeePK2_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_Embed_Embed_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_Embed_ToOne_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_String_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Coll_Embed_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Coll_Integer_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Embed_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_Embed_ToMany_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_MappedToOne_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_ToMany_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Embed_ToOne_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityB1_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Item1_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Item2_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Item3_.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/VicePresident_.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Book.java
  (contents, props changed)
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Joins.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java?rev=798735&r1=798734&r2=798735&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
Wed Jul 29 00:30:41 2009
@@ -73,6 +73,12 @@
             if (direct && ((Const) _val2).getValue(ctx, s2) == null)
                 flags1 = Val.NULL_CMP;
         }
+
+        if (_val1 instanceof PCPath && _val2 instanceof PCPath &&
+            (((PCPath)_val1).isSubqueryPath() || ((PCPath)_val2).isSubqueryPath())) {
+            flags1 = flags1 | Val.CMP_EQUAL;
+            flags2 = flags2 | Val.CMP_EQUAL;
+        }
         
         if (s1 == null)
             s1 = _val1.initialize(sel, ctx, flags1);

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java?rev=798735&r1=798734&r2=798735&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
Wed Jul 29 00:30:41 2009
@@ -313,14 +313,15 @@
                 case JavaTypes.ARRAY:
                 case JavaTypes.COLLECTION:
                     ValueMapping elem = pstate.field.getElementMapping();
-                    if (pstate.field.isElementCollection() &&
-                        pstate.field.getElement().isEmbedded()) {
+                    if (pstate.field.isElementCollection() && pstate.field.getElement().isEmbedded())
{
                         Strategy strategy = pstate.field.getStrategy();
-                        if (strategy instanceof
-                            HandlerCollectionTableFieldStrategy)
-                            return ((HandlerCollectionTableFieldStrategy)
-                                strategy).getElementColumns(
-                                elem.getTypeMapping());
+                        if (strategy instanceof HandlerCollectionTableFieldStrategy) {
+                            if (pstate.compareEqual)
+                                return pstate.field.getJoinForeignKey().getColumns();
+                            return ((HandlerCollectionTableFieldStrategy) strategy).
+                                getElementColumns(elem.getTypeMapping());
+                            
+                        }
                     }
                     if (pstate.joinedRel && elem.getTypeCode() == JavaTypes.PC)
                         return elem.getTypeMapping().getPrimaryKeyColumns();
@@ -473,6 +474,7 @@
 
     public ExpState initialize(Select sel, ExpContext ctx, int flags) {
         PathExpState pstate = new PathExpState(sel.newJoins());
+        pstate.compareEqual = (flags & Val.CMP_EQUAL) != 0 ? true : false;
         boolean key = false;
         boolean forceOuter = false;
         ClassMapping rel = _candidate;
@@ -743,7 +745,8 @@
         public Column[] cols = null;
         public boolean joinedRel = false;
         public boolean isEmbedElementColl = false;
-
+        public boolean compareEqual = false;
+        
         public PathExpState(Joins joins) {
             super(joins);
         }
@@ -1039,6 +1042,13 @@
         else
             pstate.field.appendIsNotNull(sql, sel, pstate.joins);
     }
+    
+    public boolean isSubqueryPath() {
+        if (_actions != null && _actions.size() == 1 && 
+           ((Action)_actions.get(0)).op == Action.SUBQUERY)
+            return true;
+        return false;
+    }
 
     public int hashCode() {
         if (_actions == null)

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java?rev=798735&r1=798734&r2=798735&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
Wed Jul 29 00:30:41 2009
@@ -51,6 +51,12 @@
      */
     public final int FORCE_OUTER = 2 << 2; 
 
+    /**
+     * Initialization flag indicating to this value is for compare/equal 
+     * path.
+     */
+    public final int CMP_EQUAL = 2 << 3; 
+
     public final int VAL = 0;
     public final int MATH_VAL = 1;
     public final int CONCAT_VAL = 2;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java?rev=798735&r1=798734&r2=798735&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
Wed Jul 29 00:30:41 2009
@@ -99,7 +99,42 @@
             Student.class,
             TransactionHistory.class,
             Transaction.class,
-            VideoStore.class};
+            VideoStore.class,
+            org.apache.openjpa.persistence.embed.Company1.class,
+            org.apache.openjpa.persistence.embed.Company2.class,
+            org.apache.openjpa.persistence.embed.Department1.class,
+            org.apache.openjpa.persistence.embed.Department2.class,
+            org.apache.openjpa.persistence.embed.Department3.class,
+            org.apache.openjpa.persistence.embed.Division.class,
+            org.apache.openjpa.persistence.embed.Embed.class,
+            org.apache.openjpa.persistence.embed.Embed_Coll_Embed.class,
+            org.apache.openjpa.persistence.embed.Embed_Coll_Integer.class,
+            org.apache.openjpa.persistence.embed.Embed_Embed.class,
+            org.apache.openjpa.persistence.embed.Embed_Embed_ToMany.class,
+            org.apache.openjpa.persistence.embed.Embed_MappedToOne.class,
+            org.apache.openjpa.persistence.embed.Embed_ToMany.class,
+            org.apache.openjpa.persistence.embed.Embed_ToOne.class,
+            org.apache.openjpa.persistence.embed.Employee1.class,
+            org.apache.openjpa.persistence.embed.Employee2.class,
+            org.apache.openjpa.persistence.embed.Employee3.class,
+            org.apache.openjpa.persistence.embed.EmployeeName3.class,
+            org.apache.openjpa.persistence.embed.EmployeePK2.class,
+            org.apache.openjpa.persistence.embed.EntityA_Coll_Embed_Embed.class,
+            org.apache.openjpa.persistence.embed.EntityA_Coll_Embed_ToOne.class,
+            org.apache.openjpa.persistence.embed.EntityA_Coll_String.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_Coll_Embed.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_Coll_Integer.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_Embed.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_Embed_ToMany.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_MappedToOne.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_ToMany.class,
+            org.apache.openjpa.persistence.embed.EntityA_Embed_ToOne.class,
+            org.apache.openjpa.persistence.embed.EntityB1.class,
+            org.apache.openjpa.persistence.embed.Item1.class,
+            org.apache.openjpa.persistence.embed.Item2.class,
+            org.apache.openjpa.persistence.embed.Item3.class,
+            org.apache.openjpa.persistence.embed.VicePresident.class        
+    };
     
     protected Class[] getDomainClasses() {
         return CLASSES;
@@ -291,6 +326,58 @@
         }
     }
 
+    void executeExpectFail(CriteriaQuery<?> c, String jpql) {
+        List<String> cSQL = null;
+        StringWriter w = new StringWriter();
+        try {
+            Query cQ = em.createQuery(c);
+            cSQL = executeQueryAndCollectSQL(cQ);
+            fail("CriteriaQuery corresponding to " + jpql + " is expected to fail\r\n" +
w);
+        } catch (Exception e) {
+            e.printStackTrace(new PrintWriter(w));
+        }
+    }
+    
+    void executeExpectFail(CriteriaQuery<?> c, String jpql, String[] paramNames, Object[]
params) {
+        List<String> cSQL = null;
+        StringWriter w = new StringWriter();
+        try {
+            Query cQ = em.createQuery(c);
+            for (int i = 0; i < params.length; i++)
+                cQ.setParameter(paramNames[i], params[i]);
+            cSQL = executeQueryAndCollectSQL(cQ);
+            fail("CriteriaQuery corresponding to " + jpql + " is expected to fail\r\n" +
w);
+        } catch (Exception e) {
+            e.printStackTrace(new PrintWriter(w));
+        }
+    }
+    
+    void executeExpectFail(String jpql) {
+        List<String> jSQL = null;
+        StringWriter w = new StringWriter();
+        try {
+            Query jQ = em.createQuery(jpql);
+            jSQL = executeQueryAndCollectSQL(jQ);
+            fail("JPQL " + jpql + " is expected to Failed to execute\r\n" + w);
+        } catch (Exception e) {
+            e.printStackTrace(new PrintWriter(w));
+        }
+    }
+
+    void executeExpectFail(String jpql, String[] paramNames, Object[] params) {
+        List<String> jSQL = null;
+        StringWriter w = new StringWriter();
+        try {
+            Query jQ = em.createQuery(jpql);
+            for (int i = 0; i < params.length; i++)
+                jQ.setParameter(paramNames[i], params[i]);
+            jSQL = executeQueryAndCollectSQL(jQ);
+            fail("JPQL " + jpql + " is expected to Failed to execute\r\n" + w);
+        } catch (Exception e) {
+            e.printStackTrace(new PrintWriter(w));
+        }
+    }
+
     void printSQL(String header, String sql) {
         System.err.println(header);
         System.err.println(sql);



Mime
View raw message