openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r763516 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/
Date Thu, 09 Apr 2009 05:11:20 GMT
Author: fancy
Date: Thu Apr  9 05:11:20 2009
New Revision: 763516

URL: http://svn.apache.org/viewvc?rev=763516&view=rev
Log:
OPENJPA-967 JPA2 Query support for MapKey fixes

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MapKey.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/Type.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MapKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MapKey.java?rev=763516&r1=763515&r2=763516&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MapKey.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MapKey.java
Thu Apr  9 05:11:20 2009
@@ -108,7 +108,7 @@
     }
 
     public Class getType() {
-        return Object.class;
+        return _key.getType();
     }
 
     public void setImplicitType(Class type) {

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=763516&r1=763515&r2=763516&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
Thu Apr  9 05:11:20 2009
@@ -77,13 +77,11 @@
     private final ClassMapping _candidate;
     private ClassMapping _class = null;
     private boolean _key = false;
-    private boolean _keyPath = false;
     private int _type = PATH;
     private String _varName = null;
     private Class _cast = null;
     private boolean _cid = false;
     private FieldMetaData _xmlfield = null;
-    private FieldMetaData _mapfield = null;
 
     /**
      * Return a path starting with the 'this' ptr.
@@ -249,8 +247,7 @@
             if (pstate.field.getKey().getTypeCode() == JavaTypes.PC)
                 return pstate.field.getKeyMapping().getTypeMapping();
             return null;
-        } else if (_keyPath)
-            return pstate.field.getDefiningMapping();
+        }
         if (pstate.field.getElement().getTypeCode() == JavaTypes.PC) {
             if (pstate.field.isElementCollection() &&
                 pstate.field.getElement().isEmbedded())
@@ -372,10 +369,14 @@
         if (_cid)
             return;
 
-        _mapfield = last();
-        // change the last action to a get key
-        Action action = (Action) _actions.getLast();
-        action.op = Action.GET_KEY;
+        // replace the last field action to a get key
+        Action action = lastFieldAction();
+        Action key = new Action();
+        key.op = Action.GET_KEY;
+        key.data = action.data;
+        int pos = _actions.indexOf(action);
+        _actions.remove(action);
+        _actions.add(pos, key);
         _cast = null;
         _key = true;
         _type = PATH;
@@ -383,7 +384,7 @@
 
     public FieldMetaData last() {
         Action act = lastFieldAction();
-        return (act == null || act.op == Action.GET_KEY) ? null : isXPath() ?
+        return (act == null) ? null : isXPath() ?
             _xmlfield : (FieldMetaData) act.data;
     }
 
@@ -416,7 +417,6 @@
             return ((XMLMetaData) act.data).getType();
         
         FieldMetaData fld = act == null ? null :
-            act.op == Action.GET_KEY ? _mapfield :
             (FieldMetaData) act.data;
         boolean key = act != null && act.op == Action.GET_KEY;
         if (fld != null) {
@@ -480,22 +480,8 @@
                     rel.getTable());
             } else {
                 // move past the previous field, if any
-                field = (action.op == Action.GET_XPATH) ?
-                    (FieldMapping) _xmlfield :
-                    (action.op == Action.GET_KEY) ? null :
-                    (FieldMapping) action.data;
-
-                // mark if the next traversal should go through
-                // the key rather than value
-                key = action.op == Action.GET_KEY;
-                forceOuter |= action.op == Action.GET_OUTER;
-
-                // if last action is get map key, use the previous field mapping
-                if (key && !itr.hasNext()) {
-                    field = pstate.field;
-                    pstate.joins = pstate.joins.setVariable((String)
-                        action.data);
-                }
+                field = (FieldMapping) ((action.op == Action.GET_XPATH) ?
+                    _xmlfield : action.data);
 
                 if (pstate.field != null) {
                     // if this is the second-to-last field and the last is
@@ -509,15 +495,14 @@
                     rel = traverseField(pstate, key, forceOuter, false);
                 }
 
+                // mark if the next traversal should go through
+                // the key rather than value
+                key = action.op == Action.GET_KEY;
+                forceOuter |= action.op == Action.GET_OUTER;
+
                 // get mapping for the current field
                 pstate.field = field;
 
-                if (key && itr.hasNext()) {
-                    // path navigation thru KEY
-                    _keyPath = true;
-                    continue;
-                }
-
                 owner = pstate.field.getDefiningMapping();
                 if (pstate.field.getManagement() 
                     != FieldMapping.MANAGE_PERSISTENT)
@@ -555,11 +540,6 @@
         if (_varName != null)
             pstate.joins = pstate.joins.setVariable(_varName);
 
-        // if last action is key action, avoid redundant joins
-        if (key) {
-            return pstate;
-        }
-
         // if we're not comparing to null or doing an isEmpty, then
         // join into the data on the final field; obviously we can't do these
         // joins when comparing to null b/c the whole purpose is to see
@@ -737,7 +717,7 @@
         boolean pks) {
         ClassMapping mapping = getClassMapping(state);
         PathExpState pstate = (PathExpState) state;
-        if (mapping == null || !pstate.joinedRel || _keyPath ||
+        if (mapping == null || !pstate.joinedRel ||
             pstate.isEmbedElementColl)            
             sel.select(getColumns(state), pstate.joins);
         else if (_key && pstate.field.getKey().isEmbedded())
@@ -760,7 +740,7 @@
     public void groupBy(Select sel, ExpContext ctx, ExpState state) {
         ClassMapping mapping = getClassMapping(state);
         PathExpState pstate = (PathExpState) state;
-        if (mapping == null || !pstate.joinedRel || _keyPath)
+        if (mapping == null || !pstate.joinedRel)
             sel.groupBy(getColumns(state), sel.outer(pstate.joins));
         else {
             int subs = (_type == UNBOUND_VAR) ? Select.SUBS_JOINABLE

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java?rev=763516&r1=763515&r2=763516&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Type.java
Thu Apr  9 05:11:20 2009
@@ -31,6 +31,7 @@
  * Entity Type expression.
  *
  * @author Catalina Wei
+ * @since 2.0.0
  */
 class Type
     extends UnaryOp {
@@ -45,26 +46,37 @@
     }
 
     public ExpState initialize(Select sel, ExpContext ctx, int flags) {
-        // initialize the value with a null test
-        return initializeValue(sel, ctx, NULL_CMP);
+        return initializeValue(sel, ctx, flags);
     }
 
     public Object load(ExpContext ctx, ExpState state, Result res)
         throws SQLException {
-        Object type = getValue().load(ctx, state, res);
+        Object type = null;
+        if (_disc != null && _disc.getColumns().length > 0) {
+            type = res.getObject(_disc.getColumns()[0], null, state.joins);
+            ClassMapping sup = (ClassMapping) getMetaData();
+            ClassMapping[] subs = sup.getMappedPCSubclassMappings();
+            for (ClassMapping sub : subs) {
+                if (sub.getDiscriminator().getValue().equals(type))
+                    return sub.getDescribedType();
+            }
+        }
+        else
+            type = getValue().load(ctx, state, res);
         return type.getClass();
     }
 
     public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
         Val other, ExpState otherState) {
         super.calculateValue(sel, ctx, state, null, null);
-        if (_disc != null)
-            _disc.select(sel, (ClassMapping) getMetaData()); 
     }
 
     public void select(Select sel, ExpContext ctx, ExpState state, 
         boolean pks) {
-        getValue().select(sel, ctx, state, pks);
+        if (_disc != null && _disc.getColumns().length > 0)
+            sel.select(_disc.getColumns(), state.joins);
+        else
+            getValue().select(sel, ctx, state, pks);
     }
 
     public void appendTo(Select sel, ExpContext ctx, ExpState state, 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java?rev=763516&r1=763515&r2=763516&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java
Thu Apr  9 05:11:20 2009
@@ -95,7 +95,7 @@
         
         // test ORDER BY qualified path
         query = "select KEY(e), KEY(e).fName from Department d, " +
-            " in (d.emps) e order by d.deptId";
+            " in (d.emps) e order by KEY(e).fName";
         q = em.createQuery(query);
         if (inMemory) 
             setCandidate(q, Department.class);



Mime
View raw message