openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r432067 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main...
Date Wed, 16 Aug 2006 23:27:06 GMT
Author: awhite
Date: Wed Aug 16 16:27:04 2006
New Revision: 432067

URL: http://svn.apache.org/viewvc?rev=432067&view=rev
Log:
When a relation mapping uses the expected class of the related type as part of
its join criteria (in addition to the standard foreign key join), make sure
discriminator conditions are appended to the WHERE SQL not only when loading
the relation, but also when traversing it in queries.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStore.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Abs.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMapping.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractDiscriminatorStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/InValueDiscriminatorStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SubclassJoinDiscriminatorStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SuperclassDiscriminatorStrategy.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Join.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Joins.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Abs.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStore.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStore.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStore.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStore.java Wed Aug 16 16:27:04 2006
@@ -93,14 +93,4 @@
      * This is usually done automatically.
      */
     public void loadSubclasses(ClassMapping mapping);
-
-    /**
-     * Add WHERE conditions to the given select limiting the returned results
-     * to the given mapping type, possibly including subclasses.
-     *
-     * @return true if the mapping was joined down to its base class
-     * in order to add the conditions
-     */
-    public boolean addClassConditions(Select sel, ClassMapping mapping,
-        boolean subs, Joins joins);
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java Wed Aug 16 16:27:04 2006
@@ -862,9 +862,11 @@
         // add class conditions so that they're cloned for any batched selects
         boolean joinedSupers = false;
         if ((sm == null || sm.getPCState() == PCState.TRANSIENT)
-            && (subs == sel.SUBS_JOINABLE || subs == sel.SUBS_NONE))
-            joinedSupers = addClassConditions(sel, mapping,
+            && (subs == sel.SUBS_JOINABLE || subs == sel.SUBS_NONE)) {
+            loadSubclasses(mapping); 
+            joinedSupers = mapping.getDiscriminator().addClassConditions(sel,
                 subs == sel.SUBS_JOINABLE, null);
+        }
 
         // create all our eager selects so that those fields are reserved
         // and cannot be reused during the actual eager select process,
@@ -1188,41 +1190,6 @@
         } catch (SQLException se) {
             throw SQLExceptions.getStore(se, _dict);
         }
-    }
-
-    /**
-     * Add WHERE conditions to the given select limiting the returned results
-     * to the given mapping type, possibly including subclasses.
-     *
-     * @return true if the mapping was joined down to its base class
-     * in order to add the conditions
-     */
-    public boolean addClassConditions(Select sel, ClassMapping mapping,
-        boolean subs, Joins joins) {
-        loadSubclasses(mapping);
-        if (mapping.getJoinablePCSuperclassMapping() == null
-            && mapping.getJoinablePCSubclassMappings().length == 0)
-            return false;
-
-        // join down to base class where the conditions will be added
-        ClassMapping from = mapping;
-        ClassMapping sup = mapping.getJoinablePCSuperclassMapping();
-        for (; sup != null; from = sup, sup = from
-            .getJoinablePCSuperclassMapping()) {
-            if (from.getTable() != sup.getTable()) {
-                if (joins == null)
-                    joins = sel.newJoins();
-                joins = from.joinSuperclass(joins, false);
-            }
-        }
-
-        Discriminator dsc = mapping.getDiscriminator();
-        SQLBuffer buf = dsc.getClassConditions(this, sel, joins, mapping, subs);
-        if (buf != null) {
-            sel.where(buf, joins);
-            return true;
-        }
-        return false;
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java Wed Aug 16 16:27:04 2006
@@ -42,7 +42,7 @@
 import serp.util.Numbers;
 import serp.util.Strings;
 
-////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////
 // NOTE: Do not change property names; see SequenceMetaData
 // and SequenceMapping for standard property names.
 ////////////////////////////////////////////////////////////
@@ -270,15 +270,9 @@
         } finally {
             // clean up our resources
             if (rs != null)
-                try {
-                    rs.close();
-                } catch (SQLException se) {
-                }
+                try { rs.close(); } catch (SQLException se) {}
             if (stmnt != null)
-                try {
-                    stmnt.close();
-                } catch (SQLException se) {
-                }
+                try { stmnt.close(); } catch (SQLException se) {}
         }
     }
 
@@ -357,10 +351,7 @@
                 long cur = seq.getSequence(conn);
                 System.out.println(cur);
             } finally {
-                try {
-                    conn.close();
-                } catch (SQLException se) {
-                }
+                try { conn.close(); } catch (SQLException se) {}
             }
         } else
             return false;

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Abs.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Abs.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Abs.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Abs.java Wed Aug 16 16:27:04 2006
@@ -22,8 +22,6 @@
 
 /**
  * Absolute value.
- *
- * @author Abe White
  */
 class Abs
     extends UnaryOp {
@@ -36,14 +34,8 @@
     }
 
     protected Class getType(Class c) {
-        Class wrap = Filters.wrap(c);
-        if (wrap == Integer.class
-            || wrap == Float.class
-            || wrap == Double.class
-            || wrap == Long.class
-            || wrap == BigDecimal.class
-            || wrap == BigInteger.class)
-            return c;
+        if (c == Long.class || c == long.class)
+            return long.class;
         return int.class;
     }
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java Wed Aug 16 16:27:04 2006
@@ -123,8 +123,8 @@
                 sql.append("1 <> 1");
         } else {
             store.loadSubclasses(_dsc.getClassMapping());
-            SQLBuffer buf = _dsc.getClassConditions(store, sel, _joins,
-                _mapping, true);
+            SQLBuffer buf = _dsc.getClassConditions(sel, _joins, _mapping, 
+                true);
             if (buf == null)
                 sql.append("1 = 1");
             else

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java Wed Aug 16 16:27:04 2006
@@ -338,8 +338,10 @@
         // add conditions limiting the projections to the proper classes; if
         // this isn't a projection then they will already be added
         if (exps.projections.length > 0) {
+            store.loadSubclasses(mapping);
             Select indSel = (inner == null) ? sel : inner;
-            store.addClassConditions(indSel, mapping, subclasses, joins);
+            mapping.getDiscriminator().addClassConditions(indSel, subclasses, 
+                joins);
         }
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java Wed Aug 16 16:27:04 2006
@@ -289,6 +289,35 @@
         _subsLoaded = loaded;
     }
 
+    /**
+     * Add WHERE conditions to the given select limiting the returned results
+     * to our mapping type, possibly including subclasses.
+     */
+    public boolean addClassConditions(Select sel, boolean subs, Joins joins) {
+        if (_mapping.getJoinablePCSuperclassMapping() == null
+            && _mapping.getJoinablePCSubclassMappings().length == 0)
+            return false;
+
+        // join down to base class where conditions will be added
+        ClassMapping from = _mapping;
+        ClassMapping sup = _mapping.getJoinablePCSuperclassMapping();
+        for (; sup != null; from = sup, sup = from
+            .getJoinablePCSuperclassMapping()) {
+            if (from.getTable() != sup.getTable()) {
+                if (joins == null)
+                    joins = sel.newJoins();
+                joins = from.joinSuperclass(joins, false);
+            }
+        }
+
+        SQLBuffer buf = getClassConditions(sel, joins, _mapping, subs);
+        if (buf != null) {
+            sel.where(buf, joins);
+            return true;
+        }
+        return false;
+    }
+
     ////////////////////////////////////////
     // DiscriminatorStrategy implementation
     ////////////////////////////////////////
@@ -365,10 +394,9 @@
         return assertStrategy().getClass(store, base, result);
     }
 
-    public SQLBuffer getClassConditions(JDBCStore store, Select sel,
-        Joins joins, ClassMapping base, boolean subs) {
-        return assertStrategy().getClassConditions(store, sel, joins,
-            base, subs);
+    public SQLBuffer getClassConditions(Select sel, Joins joins, 
+        ClassMapping base, boolean subs) {
+        return assertStrategy().getClassConditions(sel, joins, base, subs);
     }
 
     private DiscriminatorStrategy assertStrategy() {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java Wed Aug 16 16:27:04 2006
@@ -64,6 +64,6 @@
      * no conditions needed. The select and joins instances are supplied
      * in order to get column aliases.
      */
-    public SQLBuffer getClassConditions(JDBCStore store, Select sel,
-        Joins joins, ClassMapping base, boolean subs);
+    public SQLBuffer getClassConditions(Select sel, Joins joins, 
+        ClassMapping base, boolean subs);
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMapping.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMapping.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMapping.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ValueMapping.java Wed Aug 16 16:27:04 2006
@@ -189,10 +189,10 @@
     public ClassMapping[] getIndependentTypeMappings();
 
     /**
-     * Return the {@link org.apache.openjpa.sql.Select} subclasses constant for loading
-     * this relation, based on how the related type is mapped, whether this
-     * relation is polymorphic, and whether it is configured to use class
-     * criteria.
+     * Return the {@link org.apache.openjpa.sql.Select} subclasses constant 
+     * for loading this relation, based on how the related type is mapped, 
+     * whether this relation is polymorphic, and whether it is configured to 
+     * use class criteria.
      */
     public int getSelectSubclasses();
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractDiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractDiscriminatorStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractDiscriminatorStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/AbstractDiscriminatorStrategy.java Wed Aug 16 16:27:04 2006
@@ -82,8 +82,8 @@
         return base.getDescribedType();
     }
 
-    public SQLBuffer getClassConditions(JDBCStore store, Select sel,
-        Joins joins, ClassMapping base, boolean subs) {
+    public SQLBuffer getClassConditions(Select sel, Joins joins, 
+        ClassMapping base, boolean subs) {
         return null;
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/InValueDiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/InValueDiscriminatorStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/InValueDiscriminatorStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/InValueDiscriminatorStrategy.java Wed Aug 16 16:27:04 2006
@@ -113,8 +113,8 @@
         return getClass(cls, store);
     }
 
-    public SQLBuffer getClassConditions(JDBCStore store, Select sel,
-        Joins joins, ClassMapping base, boolean subclasses) {
+    public SQLBuffer getClassConditions(Select sel, Joins joins, 
+        ClassMapping base, boolean subclasses) {
         // if selecting the first mapped class and all subclasses, no need
         // to limit the query
         if (isFinal || (base.getJoinablePCSuperclassMapping() == null
@@ -128,7 +128,8 @@
 
         // if not selecting subclasses, limit to just the given class
         Column col = disc.getColumns()[0];
-        SQLBuffer sql = new SQLBuffer(store.getDBDictionary());
+        SQLBuffer sql = new SQLBuffer(sel.getConfiguration().
+            getDBDictionaryInstance());
         sql.append(sel.getColumnAlias(col, joins));
         if (!subclasses || subs.length == 0)
             return sql.append(" = ").appendValue(getDiscriminatorValue(base),

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java Wed Aug 16 16:27:04 2006
@@ -398,8 +398,10 @@
         // and join into relation
         ForeignKey fk = field.getForeignKey(cls);
         if (!forceInner && field.getNullValue() != FieldMapping.NULL_EXCEPTION)
-            return joins.outerJoinRelation(field.getName(), fk, inverse, false);
-        return joins.joinRelation(field.getName(), fk, inverse, false);
+            return joins.outerJoinRelation(field.getName(), fk, field.
+                getTypeMapping(), field.getSelectSubclasses(), inverse, false);
+        return joins.joinRelation(field.getName(), fk, field.getTypeMapping(), 
+            field.getSelectSubclasses(), inverse, false);
     }
 
     public int select(Select sel, OpenJPAStateManager sm, JDBCStore store,
@@ -549,9 +551,9 @@
                     sel.whereForeignKey(field.getForeignKey(rels[idx]),
                         sm.getObjectId(), field.getDefiningMapping(), store);
                 else {
-                    resJoins[idx] = sel.newJoins().joinRelation
-                        (field.getName(), field.getForeignKey(rels[idx]),
-                            false, false);
+                    resJoins[idx] = sel.newJoins().joinRelation(field.getName(),
+                        field.getForeignKey(rels[idx]), rels[idx],
+                        field.getSelectSubclasses(), false, false);
                     field.wherePrimaryKey(sel, sm, store);
                 }
                 sel.select(rels[idx], subs, store, fetch, fetch.EAGER_JOIN, 
@@ -638,13 +640,15 @@
         // already traversed the relation; just join back to owner table
         if (field.getJoinDirection() != field.JOIN_INVERSE)
             return field.join(joins, forceOuter, false);
-        if (field.getIndependentTypeMappings().length != 1)
+        ClassMapping[] clss = field.getIndependentTypeMappings();
+        if (clss.length != 1)
             throw RelationStrategies.uninversable(field);
         if (forceOuter)
             return joins.outerJoinRelation(field.getName(),
-                field.getForeignKey(), true, false);
+                field.getForeignKey(), clss[0], field.getSelectSubclasses(), 
+                true, false);
         return joins.joinRelation(field.getName(), field.getForeignKey(),
-            true, false);
+            clss[0], field.getSelectSubclasses(), true, false);
     }
 
     public Joins joinRelation(Joins joins, boolean forceOuter,
@@ -659,10 +663,11 @@
             return joins;
         }
         if (forceOuter)
-            return joins.outerJoinRelation(field.getName(),
-                field.getForeignKey(clss[0]), false, false);
-        return joins.joinRelation(field.getName(),
-            field.getForeignKey(clss[0]), false, false);
+            return joins.outerJoinRelation(field.getName(), 
+                field.getForeignKey(clss[0]), clss[0], 
+                field.getSelectSubclasses(), false, false);
+        return joins.joinRelation(field.getName(), field.getForeignKey(clss[0]),
+            clss[0], field.getSelectSubclasses(), false, false);
     }
 
     /////////////////////////////

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyInverseKeyFieldStrategy.java Wed Aug 16 16:27:04 2006
@@ -84,8 +84,9 @@
     }
 
     protected Joins join(Joins joins, ClassMapping elem) {
-        return joins.joinRelation(field.getName(),
-            field.getElementMapping().getForeignKey(elem), true, true);
+        ValueMapping vm = field.getElementMapping();
+        return joins.joinRelation(field.getName(), vm.getForeignKey(elem), 
+            elem, vm.getSelectSubclasses(), true, true);
     }
 
     protected Joins joinElementRelation(Joins joins, ClassMapping elem) {
@@ -295,10 +296,11 @@
         if (clss.length != 1)
             throw RelationStrategies.unjoinable(elem);
         if (forceOuter)
-            return joins.outerJoinRelation(field.getName(),
-                elem.getForeignKey(clss[0]), true, true);
-        return joins.joinRelation(field.getName(),
-            elem.getForeignKey(clss[0]), true, true);
+            return joins.outerJoinRelation(field.getName(), 
+                elem.getForeignKey(clss[0]), clss[0],
+                elem.getSelectSubclasses(), true, true);
+        return joins.joinRelation(field.getName(), elem.getForeignKey(clss[0]),
+            clss[0], elem.getSelectSubclasses(), true, true);
     }
 
     private void assertInversable() {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationToManyTableFieldStrategy.java Wed Aug 16 16:27:04 2006
@@ -84,8 +84,9 @@
     }
 
     protected Joins joinElementRelation(Joins joins, ClassMapping elem) {
-        return joins.joinRelation(field.getName(), field.getElementMapping().
-            getForeignKey(elem), false, false);
+        ValueMapping vm = field.getElementMapping();
+        return joins.joinRelation(field.getName(), vm.getForeignKey(elem), 
+            elem, vm.getSelectSubclasses(), false, false);
     }
 
     public void map(boolean adapt) {
@@ -258,8 +259,9 @@
         }
         if (forceOuter)
             return joins.outerJoinRelation(field.getName(),
-                elem.getForeignKey(clss[0]), false, false);
-        return joins.joinRelation(field.getName(),
-            elem.getForeignKey(clss[0]), false, false);
+                elem.getForeignKey(clss[0]), clss[0], 
+                elem.getSelectSubclasses(), false, false);
+        return joins.joinRelation(field.getName(), elem.getForeignKey(clss[0]),
+            clss[0], elem.getSelectSubclasses(), false, false);
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SubclassJoinDiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SubclassJoinDiscriminatorStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SubclassJoinDiscriminatorStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SubclassJoinDiscriminatorStrategy.java Wed Aug 16 16:27:04 2006
@@ -130,8 +130,8 @@
         return derived;
     }
 
-    public SQLBuffer getClassConditions(JDBCStore store, Select sel,
-        Joins joins, ClassMapping base, boolean subclasses) {
+    public SQLBuffer getClassConditions(Select sel, Joins joins, 
+        ClassMapping base, boolean subclasses) {
         if (isFinal || subclasses)
             return null;
         ClassMapping[] subs = base.getJoinablePCSubclassMappings();
@@ -150,7 +150,8 @@
             if (buf == null) {
                 // make sure the base class is aliased first so that we don't
                 // end up with our outer joins before the inner ones
-                buf = new SQLBuffer(store.getDBDictionary());
+                buf = new SQLBuffer(sel.getConfiguration().
+                    getDBDictionaryInstance());
                 sel.getColumnAlias(base.getPrimaryKeyColumns()[0], joins);
             } else
                 buf.append(" AND ");

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SuperclassDiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SuperclassDiscriminatorStrategy.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SuperclassDiscriminatorStrategy.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/SuperclassDiscriminatorStrategy.java Wed Aug 16 16:27:04 2006
@@ -53,10 +53,9 @@
             getDiscriminator().getClass(store, base, res);
     }
 
-    public SQLBuffer getClassConditions(JDBCStore store, Select sel,
-        Joins joins, ClassMapping base, boolean subclasses) {
+    public SQLBuffer getClassConditions(Select sel, Joins joins, 
+        ClassMapping base, boolean subclasses) {
         return disc.getClassMapping().getPCSuperclassMapping().
-            getDiscriminator().getClassConditions(store, sel, joins, base,
-            subclasses);
+            getDiscriminator().getClassConditions(sel, joins, base, subclasses);
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java Wed Aug 16 16:27:04 2006
@@ -822,13 +822,13 @@
             return this;
         }
 
-        public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
-            boolean toMany) {
+        public Joins joinRelation(String name, ForeignKey fk, 
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
             return this;
         }
 
         public Joins outerJoinRelation(String name, ForeignKey fk,
-            boolean inverse, boolean toMany) {
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
             return this;
         }
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Wed Aug 16 16:27:04 2006
@@ -60,6 +60,7 @@
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
+import org.apache.openjpa.jdbc.kernel.exps.Val;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
@@ -1659,6 +1660,7 @@
     public SQLBuffer toSelectCount(Select sel) {
         SQLBuffer selectSQL = new SQLBuffer(this);
         SQLBuffer from;
+        sel.addJoinClassConditions();
         if (sel.getFromSelect() != null)
             from = getFromSelect(sel, false);
         else
@@ -1751,13 +1753,14 @@
      * @return the SQLBuffer for the update, or <em>null</em> if it is not
      * possible to perform the bulk update
      */
-    public SQLBuffer toBulkOperation(ClassMapping mapping, Select sel,
+    protected SQLBuffer toBulkOperation(ClassMapping mapping, Select sel,
         JDBCStore store, Object[] params, Map updateParams) {
         SQLBuffer sql = new SQLBuffer(this);
         if (updateParams == null)
             sql.append("DELETE FROM ");
         else
             sql.append("UPDATE ");
+        sel.addJoinClassConditions();
 
         // if there is only a single table in the select, then we can
         // just issue a single DELETE FROM TABLE WHERE <conditions>
@@ -1851,8 +1854,7 @@
         for (Iterator i = updateParams.entrySet().iterator(); i.hasNext();) {
             Map.Entry next = (Map.Entry) i.next();
             FieldMetaData fmd = (FieldMetaData) next.getKey();
-            org.apache.openjpa.jdbc.kernel.exps.Val val =
-                (org.apache.openjpa.jdbc.kernel.exps.Val) next.getValue();
+            Val val = (Val) next.getValue();
 
             Column col = ((FieldMapping) fmd).getColumns()[0];
             sql.append(col.getName());
@@ -1878,6 +1880,7 @@
      */
     public SQLBuffer toSelect(Select sel, boolean forUpdate,
         JDBCFetchConfiguration fetch) {
+        sel.addJoinClassConditions();
         boolean update = forUpdate && sel.getFromSelect() == null;
         SQLBuffer select = getSelects(sel, false, update);
         SQLBuffer ordering = null;
@@ -1906,7 +1909,6 @@
                 fromSQL.append(itr.next().toString());
                 if (forUpdate && tableForUpdateClause != null)
                     fromSQL.append(" ").append(tableForUpdateClause);
-
                 if (itr.hasNext())
                     fromSQL.append(", ");
             }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Join.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Join.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Join.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Join.java Wed Aug 16 16:27:04 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.openjpa.jdbc.sql;
 
+import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Table;
 
@@ -37,6 +38,9 @@
     private Table _table1;
     private Table _table2;
     private ForeignKey _fk;
+    private ClassMapping _target;
+    private int _subs;
+    private Joins _joins;
     private boolean _inverse;
 
     /**
@@ -99,6 +103,38 @@
     }
 
     /**
+     * If joining a relation, the target type.  
+     */
+    public ClassMapping getRelationTarget() {
+        return _target;
+    }
+
+    /**
+     * If joining a relation, how to deal with subclasses.  See subclass
+     * constants in {@link Select}.
+     */
+    public int getSubclasses() {
+        return _subs;
+    }
+
+    /**
+     * If joining a relation, the joins leading to the relation.
+     */
+    public Joins getRelationJoins() {
+        return _joins;
+    }
+
+    /**
+     * When joining a relation, set target type and how to deal with
+     * subclasses.  See subclass constants in {@link #Select}.
+     */
+    public void setRelation(ClassMapping target, int subs, Joins joins) {
+        _target = target;
+        _subs = subs;
+        _joins = joins;
+    }
+
+    /**
      * Return a join that is this join in reverse.
      */
     public Join reverse() {
@@ -108,8 +144,11 @@
         join._alias1 = _alias2;
         join._table2 = _table1;
         join._alias2 = _alias1;
-        join._fk = _fk;
         join._inverse = !_inverse;
+        join._fk = _fk;
+        join._target = _target;
+        join._subs = _subs;
+        join._joins = _joins;
         return join;
     }
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Joins.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Joins.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Joins.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Joins.java Wed Aug 16 16:27:04 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.openjpa.jdbc.sql;
 
+import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
 import org.apache.openjpa.jdbc.schema.Table;
 
@@ -49,15 +50,15 @@
      * Join the columns of the given foreign key, which represents a relation
      * via the given field name.
      */
-    public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
-        boolean toMany);
+    public Joins joinRelation(String name, ForeignKey fk, ClassMapping target,
+        int subclasses, boolean inverse, boolean toMany);
 
     /**
      * Join the columns of the given foreign key, which represents a relation
      * via the given field name.
      */
-    public Joins outerJoinRelation(String name, ForeignKey fk, boolean inverse,
-        boolean toMany);
+    public Joins outerJoinRelation(String name, ForeignKey fk, 
+        ClassMapping target, int subclasses, boolean inverse, boolean toMany);
 
     /**
      * Set the variable name being traversed into with the next join.

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/LogicalUnion.java Wed Aug 16 16:27:04 2006
@@ -461,6 +461,10 @@
             return sel.getHaving();
         }
 
+        public void addJoinClassConditions() {
+            sel.addJoinClassConditions();
+        }
+
         public Joins getJoins() {
             return sel.getJoins();
         }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java Wed Aug 16 16:27:04 2006
@@ -866,14 +866,8 @@
             return Numbers.valueOf(rs.getLong(1));
         } finally {
             if (rs != null)
-                try {
-                    rs.close();
-                } catch (SQLException se) {
-                }
-            try {
-                stmnt.close();
-            } catch (SQLException se) {
-            }
+                try { rs.close(); } catch (SQLException se) {}
+            try { stmnt.close(); } catch (SQLException se) {}
         }
     }
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Select.java Wed Aug 16 16:27:04 2006
@@ -182,6 +182,13 @@
     public SQLBuffer getHaving();
 
     /**
+     * Apply class conditions from relation joins.  This may affect the return
+     * values of {@link #getJoins}, {@link #getJoinIterator}, and
+     * {@link #getWhere}.
+     */
+    public void addJoinClassConditions();
+
+    /**
      * Return the top-level joins for this select.
      */
     public Joins getJoins();

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java Wed Aug 16 16:27:04 2006
@@ -269,20 +269,11 @@
             return rs.getInt(1);
         } finally {
             if (rs != null)
-                try {
-                    rs.close();
-                } catch (SQLException se) {
-                }
+                try { rs.close(); } catch (SQLException se) {}
             if (stmnt != null)
-                try {
-                    stmnt.close();
-                } catch (SQLException se) {
-                }
+                try { stmnt.close(); } catch (SQLException se) {}
             if (conn != null)
-                try {
-                    conn.close();
-                } catch (SQLException se) {
-                }
+                try { conn.close(); } catch (SQLException se) {}
         }
     }
 
@@ -331,14 +322,8 @@
         } catch (SQLException se) {
             // clean up statement
             if (stmnt != null)
-                try {
-                    stmnt.close();
-                } catch (SQLException se2) {
-                }
-            try {
-                conn.close();
-            } catch (SQLException se2) {
-            }
+                try { stmnt.close(); } catch (SQLException se2) {}
+            try { conn.close(); } catch (SQLException se2) {}
             throw se;
         }
 
@@ -496,6 +481,23 @@
         return _having;
     }
 
+    public void addJoinClassConditions() {
+        if (_joins == null || _joins.joins() == null)
+            return;
+
+        // join set iterator allows concurrent modification
+        Join j;
+        for (Iterator itr = _joins.joins().iterator(); itr.hasNext();) {
+            j = (Join) itr.next();
+            if (j.getRelationTarget() != null) {
+                j.getRelationTarget().getDiscriminator().addClassConditions
+                    (this, j.getSubclasses() == SUBS_JOINABLE, 
+                    j.getRelationJoins());
+                j.setRelation(null, 0, null);
+            }
+        }
+    }
+
     public Joins getJoins() {
         return _joins;
     }
@@ -1928,15 +1930,16 @@
         return new SelectJoins(this).outerJoin(fk, inverse, toMany);
     }
 
-    public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
-        boolean toMany) {
-        return new SelectJoins(this).joinRelation(name, fk, inverse, toMany);
+    public Joins joinRelation(String name, ForeignKey fk, ClassMapping target,
+        int subs, boolean inverse, boolean toMany) {
+        return new SelectJoins(this).joinRelation(name, fk, target, subs, 
+            inverse, toMany);
     }
 
-    public Joins outerJoinRelation(String name, ForeignKey fk,
-        boolean inverse, boolean toMany) {
-        return new SelectJoins(this).outerJoinRelation(name, fk, inverse,
-            toMany);
+    public Joins outerJoinRelation(String name, ForeignKey fk, 
+        ClassMapping target, int subs, boolean inverse, boolean toMany) {
+        return new SelectJoins(this).outerJoinRelation(name, fk, target, subs, 
+            inverse, toMany);
     }
 
     public Joins setVariable(String var) {
@@ -2268,15 +2271,16 @@
             return this;
         }
 
-        public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
-            boolean toMany) {
-            return new PathJoinsImpl().joinRelation(name, fk, inverse, toMany);
+        public Joins joinRelation(String name, ForeignKey fk, 
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
+            return new PathJoinsImpl().joinRelation(name, fk, target, subs, 
+                inverse, toMany);
         }
 
         public Joins outerJoinRelation(String name, ForeignKey fk,
-            boolean inverse, boolean toMany) {
-            return new PathJoinsImpl().outerJoinRelation(name, fk, inverse,
-                toMany);
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
+            return new PathJoinsImpl().outerJoinRelation(name, fk, target, subs,
+                inverse, toMany);
         }
 
         public Joins setVariable(String var) {
@@ -2361,8 +2365,8 @@
             return this;
         }
 
-        public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
-            boolean toMany) {
+        public Joins joinRelation(String name, ForeignKey fk, 
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
             append(name);
             append(var);
             var = null;
@@ -2370,7 +2374,7 @@
         }
 
         public Joins outerJoinRelation(String name, ForeignKey fk,
-            boolean inverse, boolean toMany) {
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
             append(name);
             append(var);
             var = null;
@@ -2396,7 +2400,8 @@
      * Joins implementation.
      */
     private static class SelectJoins
-        extends PathJoinsImpl {
+        extends PathJoinsImpl 
+        implements Cloneable {
 
         private final SelectImpl _sel;
         private JoinSet _joins = null;
@@ -2482,25 +2487,25 @@
         }
 
         public Joins join(ForeignKey fk, boolean inverse, boolean toMany) {
-            return join(null, fk, inverse, toMany, false);
+            return join(null, fk, null, -1, inverse, toMany, false);
         }
 
         public Joins outerJoin(ForeignKey fk, boolean inverse, boolean toMany) {
-            return join(null, fk, inverse, toMany, true);
+            return join(null, fk, null, -1, inverse, toMany, true);
         }
 
-        public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
-            boolean toMany) {
-            return join(name, fk, inverse, toMany, false);
+        public Joins joinRelation(String name, ForeignKey fk, 
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
+            return join(name, fk, target, subs, inverse, toMany, false);
         }
 
         public Joins outerJoinRelation(String name, ForeignKey fk,
-            boolean inverse, boolean toMany) {
-            return join(name, fk, inverse, toMany, true);
+            ClassMapping target, int subs, boolean inverse, boolean toMany) {
+            return join(name, fk, target, subs, inverse, toMany, true);
         }
 
-        private Joins join(String name, ForeignKey fk, boolean inverse,
-            boolean toMany, boolean outer) {
+        private Joins join(String name, ForeignKey fk, ClassMapping target,
+            int subs, boolean inverse, boolean toMany, boolean outer) {
             // don't let the get alias methods see that a var has been set
             // until we get past the local table
             String var = this.var;
@@ -2536,7 +2541,9 @@
 
                 if (_joins == null)
                     _joins = new JoinSet();
-                _joins.add(j);
+                if (_joins.add(j) && (subs == Select.SUBS_JOINABLE 
+                    || subs == Select.SUBS_NONE))
+                    j.setRelation(target, subs, clone(_sel));
             }
             return this;
         }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Abs.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Abs.java?rev=432067&r1=432066&r2=432067&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Abs.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Abs.java Wed Aug 16 16:27:04 2006
@@ -23,8 +23,6 @@
 
 /**
  * Take the absolute value of a number.
- *
- * @author Abe White
  */
 class Abs
     extends UnaryMathVal {
@@ -44,11 +42,12 @@
             || wrap == Long.class
             || wrap == BigDecimal.class
             || wrap == BigInteger.class)
-            return c;
+            return Filters.unwrap(c);
         return int.class;
     }
 
     protected Object operate(Object o, Class c) {
+        c = Filters.wrap(c);
         if (c == Integer.class)
             return Numbers.valueOf(Math.abs(((Number) o).intValue()));
         if (c == Float.class)



Mime
View raw message