mirror of https://github.com/apache/openjpa.git
OPENJPA-677: Make a judgement whether reading discrimnator value from the result makes sense in a context
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@683916 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
610023adee
commit
237c092ebb
|
@ -175,6 +175,7 @@ public class ClassMapping
|
|||
FieldMapping fm;
|
||||
Joinable join;
|
||||
int pkIdx;
|
||||
boolean canReadDiscriminator = true;
|
||||
for (int i = 0; i < pks.length; i++) {
|
||||
// we know that all pk column join mappings use primary key fields,
|
||||
// cause this mapping uses the oid as its primary key (we recursed
|
||||
|
@ -182,7 +183,7 @@ public class ClassMapping
|
|||
join = assertJoinable(pks[i]);
|
||||
fm = getFieldMapping(join.getFieldIndex());
|
||||
pkIdx = fm.getPrimaryKeyIndex();
|
||||
|
||||
canReadDiscriminator &= isSelfReference(fk, join.getColumns());
|
||||
// could have already set value with previous multi-column joinable
|
||||
if (vals[pkIdx] == null) {
|
||||
res.startDataRequest(fm);
|
||||
|
@ -197,8 +198,13 @@ public class ClassMapping
|
|||
// the oid data is loaded by the base type, but if discriminator data
|
||||
// is present, make sure to use it to construct the actual oid instance
|
||||
// so that we get the correct app id class, etc
|
||||
|
||||
// Discriminator refers to the row but the vals[] may hold data that
|
||||
// refer to another row. Then there is little point reading the disc
|
||||
// value
|
||||
|
||||
ClassMapping dcls = cls;
|
||||
if (subs) {
|
||||
if (subs && canReadDiscriminator) {
|
||||
res.startDataRequest(cls.getDiscriminator());
|
||||
try {
|
||||
Class dtype = cls.getDiscriminator().getClass(store, cls, res);
|
||||
|
@ -217,6 +223,15 @@ public class ClassMapping
|
|||
}
|
||||
return oid;
|
||||
}
|
||||
|
||||
boolean isSelfReference(ForeignKey fk, Column[] cols) {
|
||||
if (fk == null)
|
||||
return true;
|
||||
for (Column col : cols)
|
||||
if (fk.getColumn(col) != col)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the given column value(s) for the given object. The given
|
||||
|
|
|
@ -556,10 +556,8 @@ public class RelationFieldStrategy
|
|||
ClassMapping relMapping = field.getTypeMapping();
|
||||
Object oid = null;
|
||||
if (relMapping.isMapped()) {
|
||||
boolean subs = field.getPolymorphic() != ValueMapping.POLY_FALSE
|
||||
&& relMapping.getPCSubclasses().length > 0;
|
||||
oid = relMapping.getObjectId(store, res, field.getForeignKey(),
|
||||
subs, null);
|
||||
field.getPolymorphic() != ValueMapping.POLY_FALSE, null);
|
||||
} else {
|
||||
Column[] cols = field.getColumns();
|
||||
if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) {
|
||||
|
|
Loading…
Reference in New Issue