mirror of
https://github.com/apache/openjpa.git
synced 2025-02-21 01:15:30 +00:00
OPENJPA-1989: Flip FeildMetaData.DefaultFetchGroupExplicit flag when parsing ToOne xml relationships.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1101951 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aa88b32b06
commit
862e818e50
@ -459,7 +459,7 @@ public class JDBCStoreManager
|
||||
}
|
||||
Object coll = owner.fetchObject(fms[i].getIndex());
|
||||
if (coll instanceof Map)
|
||||
coll = ((Map)coll).values();
|
||||
coll = ((Map<?,?>)coll).values();
|
||||
if (coll instanceof Collection<?> &&
|
||||
((Collection<?>) coll).size() > 0) {
|
||||
// Found eagerly loaded collection.
|
||||
@ -594,7 +594,7 @@ public class JDBCStoreManager
|
||||
|
||||
Union union = _sql.newUnion(mappings.length);
|
||||
union.setExpectedResultCount(1, false);
|
||||
if (fetch.getSubclassFetchMode(mapping) != fetch.EAGER_JOIN)
|
||||
if (fetch.getSubclassFetchMode(mapping) != EagerFetchModes.EAGER_JOIN)
|
||||
union.abortUnion();
|
||||
union.select(new Union.Selector() {
|
||||
public void select(Select sel, int i) {
|
||||
@ -823,7 +823,7 @@ public class JDBCStoreManager
|
||||
|
||||
ResultObjectProvider[] rops = null;
|
||||
final JDBCFetchConfiguration jfetch = (JDBCFetchConfiguration) fetch;
|
||||
if (jfetch.getSubclassFetchMode(mapping) != jfetch.EAGER_JOIN)
|
||||
if (jfetch.getSubclassFetchMode(mapping) != EagerFetchModes.EAGER_JOIN)
|
||||
rops = new ResultObjectProvider[mappings.length];
|
||||
|
||||
try {
|
||||
@ -1232,15 +1232,15 @@ public class JDBCStoreManager
|
||||
int mode;
|
||||
for (int i = 0; i < fms.length; i++) {
|
||||
mode = fms[i].getEagerFetchMode();
|
||||
if (mode == fetch.EAGER_NONE)
|
||||
if (mode == EagerFetchModes.EAGER_NONE)
|
||||
continue;
|
||||
if (!requiresSelect(fms[i], sm, fields, fetch))
|
||||
continue;
|
||||
|
||||
// try to select with join first
|
||||
jtype = (fms[i].getNullValue() == fms[i].NULL_EXCEPTION)
|
||||
? sel.EAGER_INNER : sel.EAGER_OUTER;
|
||||
if (mode != fetch.EAGER_PARALLEL && !fms[i].isEagerSelectToMany()
|
||||
jtype = (fms[i].getNullValue() == FieldMetaData.NULL_EXCEPTION)
|
||||
? Select.EAGER_INNER : Select.EAGER_OUTER;
|
||||
if (mode != EagerFetchModes.EAGER_PARALLEL && !fms[i].isEagerSelectToMany()
|
||||
&& fms[i].supportsSelect(sel, jtype, sm, this, fetch) > 0
|
||||
&& sel.eagerClone(fms[i], jtype, false, 1) != null)
|
||||
continue;
|
||||
@ -1252,8 +1252,8 @@ public class JDBCStoreManager
|
||||
// to use a to-many join also. currently we limit eager
|
||||
// outer joins to non-LRS, non-ranged selects that don't already
|
||||
// have an eager to-many join
|
||||
if ((hasJoin || mode == fetch.EAGER_JOIN
|
||||
|| (mode == fetch.DEFAULT && sm != null))
|
||||
if ((hasJoin || mode == EagerFetchModes.EAGER_JOIN
|
||||
|| (mode == FetchConfiguration.DEFAULT && sm != null))
|
||||
&& fms[i].isEagerSelectToMany()
|
||||
&& !inEagerJoin
|
||||
&& !sel.hasEagerJoin(true)
|
||||
@ -1268,8 +1268,8 @@ public class JDBCStoreManager
|
||||
}
|
||||
|
||||
// finally, try parallel
|
||||
if (eager == fetch.EAGER_PARALLEL
|
||||
&& (sels = fms[i].supportsSelect(sel, sel.EAGER_PARALLEL, sm,
|
||||
if (eager == EagerFetchModes.EAGER_PARALLEL
|
||||
&& (sels = fms[i].supportsSelect(sel, Select.EAGER_PARALLEL, sm,
|
||||
this, fetch)) != 0)
|
||||
sel.eagerClone(fms[i], Select.EAGER_PARALLEL,
|
||||
fms[i].isEagerSelectToMany(), sels);
|
||||
@ -1372,7 +1372,7 @@ public class JDBCStoreManager
|
||||
seld = Math.max(fseld, seld);
|
||||
} else if (optSelect(fms[i], sel, sm, fetch)) {
|
||||
fseld = fms[i].select(sel, sm, this,
|
||||
fetch.traverseJDBC(fms[i]), fetch.EAGER_NONE);
|
||||
fetch.traverseJDBC(fms[i]), EagerFetchModes.EAGER_NONE);
|
||||
|
||||
// don't upgrade seld to > 0 based on these fields, since
|
||||
// they're not in the calculated field set
|
||||
@ -1412,10 +1412,10 @@ public class JDBCStoreManager
|
||||
private boolean optSelect(FieldMapping fm, Select sel,
|
||||
OpenJPAStateManager sm, JDBCFetchConfiguration fetch) {
|
||||
return !fm.isInDefaultFetchGroup()
|
||||
&& !fm.isDefaultFetchGroupExplicit()
|
||||
&& !fm.isDefaultFetchGroupExplicit()
|
||||
&& (sm == null || sm.getPCState() == PCState.TRANSIENT
|
||||
|| !sm.getLoaded().get(fm.getIndex()))
|
||||
&& fm.supportsSelect(sel, sel.TYPE_TWO_PART, sm, this, fetch) > 0;
|
||||
&& fm.supportsSelect(sel, Select.TYPE_TWO_PART, sm, this, fetch) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1458,7 +1458,7 @@ public class JDBCStoreManager
|
||||
if (fetch.requiresFetch(fms[j]) != FetchConfiguration.FETCH_LOAD
|
||||
&& ((!fms[j].isInDefaultFetchGroup()
|
||||
&& fms[j].isDefaultFetchGroupExplicit())
|
||||
|| fms[j].supportsSelect(sel, sel.TYPE_TWO_PART, sm, this,
|
||||
|| fms[j].supportsSelect(sel, Select.TYPE_TWO_PART, sm, this,
|
||||
fetch) <= 0))
|
||||
continue;
|
||||
|
||||
@ -1472,10 +1472,8 @@ public class JDBCStoreManager
|
||||
}
|
||||
|
||||
// if can select with tables already selected, do it
|
||||
if (fms[j].supportsSelect(sel, sel.TYPE_JOINLESS, sm, this,
|
||||
fetch) > 0)
|
||||
fms[j].select(sel, null, this, fetch.traverseJDBC(fms[j]),
|
||||
fetch.EAGER_NONE);
|
||||
if (fms[j].supportsSelect(sel, Select.TYPE_JOINLESS, sm, this, fetch) > 0)
|
||||
fms[j].select(sel, null, this, fetch.traverseJDBC(fms[j]), EagerFetchModes.EAGER_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,11 +47,17 @@ public class TestToOneLazyXmlOverride extends SQLListenerTestCase {
|
||||
resetSQL();
|
||||
|
||||
em.find(XmlOverrideToOneEntity.class, x.getId());
|
||||
for (String lastSql : sql) {
|
||||
// Make sure we don't have any joins!
|
||||
assertFalse("Shouldn't have found any instances of join or JOIN in last sql, but did. Last SQL = "
|
||||
+ lastSql, lastSql.contains("join") || lastSql.contains("JOIN"));
|
||||
}
|
||||
|
||||
assertTrue(sql.size() == 1);
|
||||
String lastSql = sql.get(0);
|
||||
// Make sure we don't have any joins!
|
||||
assertFalse("Shouldn't have found any instances of join or JOIN in last sql, but did. Last SQL = "
|
||||
+ lastSql, lastSql.contains("join") || lastSql.contains("JOIN"));
|
||||
|
||||
// Make sure that we selected lazy join columns.
|
||||
assertTrue(lastSql.contains("o2o"));
|
||||
assertTrue(lastSql.contains("m2o"));
|
||||
|
||||
} finally {
|
||||
if (em.getTransaction().isActive()) {
|
||||
em.getTransaction().rollback();
|
||||
|
@ -19,12 +19,16 @@
|
||||
*/
|
||||
package org.apache.openjpa.persistence.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class XmlOverrideToOneEntity {
|
||||
@ -32,12 +36,17 @@ public class XmlOverrideToOneEntity {
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
int id;
|
||||
|
||||
@OneToOne
|
||||
@OneToOne
|
||||
@JoinColumn(name="o2o")
|
||||
XmlOverrideToOneEntity otherO2O;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="m2o")
|
||||
XmlOverrideToOneEntity otherM2O;
|
||||
|
||||
|
||||
@Version
|
||||
int version;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -25,8 +25,10 @@
|
||||
<entity name="XmlOverrideToOneEntity" class="XmlOverrideToOneEntity">
|
||||
<attributes>
|
||||
<many-to-one name="otherM2O" fetch="LAZY">
|
||||
<join-column name="m2o"/>
|
||||
</many-to-one>
|
||||
<one-to-one name="otherO2O" fetch="LAZY">
|
||||
<join-column name="o2o"/>
|
||||
</one-to-one>
|
||||
</attributes>
|
||||
</entity>
|
||||
|
@ -1471,11 +1471,14 @@ public class XMLPersistenceMetaDataParser
|
||||
protected void parseOneToOne(FieldMetaData fmd, Attributes attrs)
|
||||
throws SAXException {
|
||||
String val = attrs.getValue("fetch");
|
||||
if (val == null) {
|
||||
fmd.setInDefaultFetchGroup(true);
|
||||
} else {
|
||||
fmd.setInDefaultFetchGroup("EAGER".equals(val));
|
||||
}
|
||||
boolean dfg = (val != null && val.equals("LAZY")) ? false : true;
|
||||
|
||||
// We need to toggle the DFG explicit flag here because this is used for an optimization when selecting an
|
||||
// Entity with lazy fields.
|
||||
fmd.setDefaultFetchGroupExplicit(true);
|
||||
fmd.setInDefaultFetchGroup(dfg);
|
||||
fmd.setDefaultFetchGroupExplicit(false);
|
||||
|
||||
val = attrs.getValue("target-entity");
|
||||
if (val != null)
|
||||
fmd.setTypeOverride(AnnotationPersistenceMetaDataParser.toOverrideType(classForName(val)));
|
||||
@ -1495,11 +1498,14 @@ public class XMLPersistenceMetaDataParser
|
||||
protected void parseManyToOne(FieldMetaData fmd, Attributes attrs)
|
||||
throws SAXException {
|
||||
String val = attrs.getValue("fetch");
|
||||
if (val == null) {
|
||||
fmd.setInDefaultFetchGroup(true);
|
||||
} else {
|
||||
fmd.setInDefaultFetchGroup("EAGER".equals(val));
|
||||
}
|
||||
boolean dfg = (val != null && val.equals("LAZY")) ? false : true;
|
||||
|
||||
// We need to toggle the DFG explicit flag here because this is used for an optimization when selecting an
|
||||
// Entity with lazy fields.
|
||||
fmd.setDefaultFetchGroupExplicit(true);
|
||||
fmd.setInDefaultFetchGroup(dfg);
|
||||
fmd.setDefaultFetchGroupExplicit(false);
|
||||
|
||||
val = attrs.getValue("target-entity");
|
||||
if (val != null)
|
||||
fmd.setTypeOverride(AnnotationPersistenceMetaDataParser.toOverrideType(classForName(val)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user