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;
|
FieldMapping fm;
|
||||||
Joinable join;
|
Joinable join;
|
||||||
int pkIdx;
|
int pkIdx;
|
||||||
|
boolean canReadDiscriminator = true;
|
||||||
for (int i = 0; i < pks.length; i++) {
|
for (int i = 0; i < pks.length; i++) {
|
||||||
// we know that all pk column join mappings use primary key fields,
|
// we know that all pk column join mappings use primary key fields,
|
||||||
// cause this mapping uses the oid as its primary key (we recursed
|
// cause this mapping uses the oid as its primary key (we recursed
|
||||||
|
@ -182,7 +183,7 @@ public class ClassMapping
|
||||||
join = assertJoinable(pks[i]);
|
join = assertJoinable(pks[i]);
|
||||||
fm = getFieldMapping(join.getFieldIndex());
|
fm = getFieldMapping(join.getFieldIndex());
|
||||||
pkIdx = fm.getPrimaryKeyIndex();
|
pkIdx = fm.getPrimaryKeyIndex();
|
||||||
|
canReadDiscriminator &= isSelfReference(fk, join.getColumns());
|
||||||
// could have already set value with previous multi-column joinable
|
// could have already set value with previous multi-column joinable
|
||||||
if (vals[pkIdx] == null) {
|
if (vals[pkIdx] == null) {
|
||||||
res.startDataRequest(fm);
|
res.startDataRequest(fm);
|
||||||
|
@ -197,8 +198,13 @@ public class ClassMapping
|
||||||
// the oid data is loaded by the base type, but if discriminator data
|
// 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
|
// is present, make sure to use it to construct the actual oid instance
|
||||||
// so that we get the correct app id class, etc
|
// 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;
|
ClassMapping dcls = cls;
|
||||||
if (subs) {
|
if (subs && canReadDiscriminator) {
|
||||||
res.startDataRequest(cls.getDiscriminator());
|
res.startDataRequest(cls.getDiscriminator());
|
||||||
try {
|
try {
|
||||||
Class dtype = cls.getDiscriminator().getClass(store, cls, res);
|
Class dtype = cls.getDiscriminator().getClass(store, cls, res);
|
||||||
|
@ -218,6 +224,15 @@ public class ClassMapping
|
||||||
return oid;
|
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
|
* Return the given column value(s) for the given object. The given
|
||||||
* columns will be primary key columns of this mapping, but may be in
|
* columns will be primary key columns of this mapping, but may be in
|
||||||
|
|
|
@ -556,10 +556,8 @@ public class RelationFieldStrategy
|
||||||
ClassMapping relMapping = field.getTypeMapping();
|
ClassMapping relMapping = field.getTypeMapping();
|
||||||
Object oid = null;
|
Object oid = null;
|
||||||
if (relMapping.isMapped()) {
|
if (relMapping.isMapped()) {
|
||||||
boolean subs = field.getPolymorphic() != ValueMapping.POLY_FALSE
|
|
||||||
&& relMapping.getPCSubclasses().length > 0;
|
|
||||||
oid = relMapping.getObjectId(store, res, field.getForeignKey(),
|
oid = relMapping.getObjectId(store, res, field.getForeignKey(),
|
||||||
subs, null);
|
field.getPolymorphic() != ValueMapping.POLY_FALSE, null);
|
||||||
} else {
|
} else {
|
||||||
Column[] cols = field.getColumns();
|
Column[] cols = field.getColumns();
|
||||||
if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) {
|
if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) {
|
||||||
|
|
Loading…
Reference in New Issue