Vertical inheritance with eager fetching fixes.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@462560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
A. Abram White 2006-10-10 20:56:32 +00:00
parent b42c74b6cb
commit 08d69d15a7
3 changed files with 32 additions and 11 deletions

View File

@ -383,10 +383,7 @@ public class PagingResultObjectProvider
(_page[j]), store, fetch, res);
} finally {
if (res instanceof Closeable)
try {
((Closeable) res).close();
} catch (Exception e) {
}
try { ((Closeable) res).close(); } catch (Exception e) {}
}
}
}

View File

@ -40,6 +40,7 @@ import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.ChangeTracker;
import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.Proxies;
import org.apache.openjpa.util.Proxy;
@ -85,8 +86,16 @@ public abstract class RelationToManyInverseKeyFieldStrategy
protected Joins join(Joins joins, ClassMapping elem) {
ValueMapping vm = field.getElementMapping();
return joins.joinRelation(field.getName(), vm.getForeignKey(elem),
elem, vm.getSelectSubclasses(), true, true);
ForeignKey fk = vm.getForeignKey(elem);
ClassMapping owner = field.getDefiningMapping();
while (fk.getPrimaryKeyTable() != owner.getTable()) {
joins = owner.joinSuperclass(joins, false);
owner = owner.getJoinablePCSuperclassMapping();
if (owner == null)
throw new InternalException();
}
return joins.joinRelation(field.getName(), fk, elem,
vm.getSelectSubclasses(), true, true);
}
protected Joins joinElementRelation(Joins joins, ClassMapping elem) {

View File

@ -1121,6 +1121,15 @@ public class SelectImpl
(mapping.getPrimaryKeyColumns(), fk.getPrimaryKeyColumns())) {
if (joins == null)
joins = newJoins();
// traverse to foreign key target mapping
while (mapping.getTable() != fk.getPrimaryKeyTable()) {
if (joins == null)
joins = newJoins();
joins = mapping.joinSuperclass(joins, false);
mapping = mapping.getJoinablePCSuperclassMapping();
if (mapping == null)
throw new InternalException();
}
joins = joins.join(fk, false, false);
wherePrimaryKey(oid, mapping, joins, store);
return;
@ -1159,8 +1168,7 @@ public class SelectImpl
int count = 0;
for (int i = 0; i < toCols.length; i++, count++) {
if (pks == null)
val = (oid == null) ? null
: Numbers.valueOf(((Id) oid).getId());
val = (oid == null) ? null : Numbers.valueOf(((Id)oid).getId());
else {
// must be app identity; use pk index to get correct pk value
join = mapping.assertJoinable(toCols[i]);
@ -2556,9 +2564,19 @@ public class SelectImpl
// the joins will all be done in the from select
boolean createJoin = _sel._from == null;
Table table1 = null;
Table table2 = null;
int alias1 = -1;
if (createJoin) {
table1 = (inverse) ? fk.getPrimaryKeyTable() : fk.getTable();
table2 = (inverse) ? fk.getTable() : fk.getPrimaryKeyTable();
if (target != null) {
while (target.getTable() != table2) {
target.joinSuperclass(this, false);
target = target.getJoinablePCSuperclassMapping();
if (target == null)
throw new InternalException();
}
}
alias1 = _sel.getTableIndex(table1, this, true);
}
@ -2572,10 +2590,7 @@ public class SelectImpl
_outer = outer;
if (createJoin) {
Table table2 = (inverse) ? fk.getTable()
: fk.getPrimaryKeyTable();
int alias2 = _sel.getTableIndex(table2, this, true);
Join j = new Join(table1, alias1, table2, alias2, fk, inverse);
j.setType((outer) ? Join.TYPE_OUTER : Join.TYPE_INNER);