mirror of https://github.com/apache/openjpa.git
OPENJPA-838: remove cache from StoreCollectionFieldStrategy
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@728750 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c924cc2fc8
commit
6ff7d9a922
|
@ -26,11 +26,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.apache.openjpa.enhance.PersistenceCapable;
|
||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
|
||||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl;
|
||||
import org.apache.openjpa.jdbc.kernel.JDBCStore;
|
||||
import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
|
||||
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
||||
import org.apache.openjpa.jdbc.meta.FieldMapping;
|
||||
import org.apache.openjpa.jdbc.meta.FieldStrategy;
|
||||
|
@ -38,14 +35,11 @@ import org.apache.openjpa.jdbc.meta.ValueMapping;
|
|||
import org.apache.openjpa.jdbc.schema.Column;
|
||||
import org.apache.openjpa.jdbc.schema.ForeignKey;
|
||||
import org.apache.openjpa.jdbc.sql.Joins;
|
||||
import org.apache.openjpa.jdbc.sql.LogicalUnion;
|
||||
import org.apache.openjpa.jdbc.sql.Result;
|
||||
import org.apache.openjpa.jdbc.sql.Select;
|
||||
import org.apache.openjpa.jdbc.sql.SelectExecutor;
|
||||
import org.apache.openjpa.jdbc.sql.SelectImpl;
|
||||
import org.apache.openjpa.jdbc.sql.Union;
|
||||
import org.apache.openjpa.kernel.OpenJPAStateManager;
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
|
@ -526,94 +520,19 @@ public abstract class StoreCollectionFieldStrategy
|
|||
return;
|
||||
}
|
||||
|
||||
//cache union for field here
|
||||
// select data for this sm
|
||||
boolean found = true;
|
||||
final ClassMapping[] elems = getIndependentElementMappings(true);
|
||||
final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
|
||||
List parmList = null;
|
||||
Union union = null;
|
||||
SelectImpl sel = null;
|
||||
Map<JDBCStoreManager.SelectKey, Object[]> storeCollectionUnionCache = null;
|
||||
JDBCStoreManager.SelectKey selKey = null;
|
||||
if (!((JDBCStoreManager)store).isQuerySQLCacheOn() || elems.length > 1)
|
||||
union = newUnion(sm, store, fetch, elems, resJoins);
|
||||
else {
|
||||
parmList = new ArrayList();
|
||||
JDBCFetchConfiguration fetchClone = new JDBCFetchConfigurationImpl();
|
||||
fetchClone.copy(fetch);
|
||||
|
||||
// to specify the type so that no cast is needed
|
||||
storeCollectionUnionCache = ((JDBCStoreManager)store).
|
||||
getCacheMapFromQuerySQLCache(StoreCollectionFieldStrategy.class);
|
||||
selKey =
|
||||
new JDBCStoreManager.SelectKey(null, field, fetchClone);
|
||||
Object[] objs = storeCollectionUnionCache.get(selKey);
|
||||
if (objs != null) {
|
||||
union = (Union) objs[0];
|
||||
resJoins[0] = (Joins) objs[1];
|
||||
Union union = store.getSQLFactory().newUnion
|
||||
(Math.max(1, elems.length));
|
||||
union.select(new Union.Selector() {
|
||||
public void select(Select sel, int idx) {
|
||||
ClassMapping elem = (elems.length == 0) ? null : elems[idx];
|
||||
resJoins[idx] = selectAll(sel, elem, sm, store, fetch,
|
||||
JDBCFetchConfiguration.EAGER_PARALLEL);
|
||||
}
|
||||
else {
|
||||
synchronized(storeCollectionUnionCache) {
|
||||
objs = storeCollectionUnionCache.get(selKey);
|
||||
if (objs == null) {
|
||||
// select data for this sm
|
||||
union = newUnion(sm, store, fetch, elems, resJoins);
|
||||
found = false;
|
||||
} else {
|
||||
union = (Union) objs[0];
|
||||
resJoins[0] = (Joins) objs[1];
|
||||
}
|
||||
});
|
||||
|
||||
sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
|
||||
getDelegate();
|
||||
if (sel.getSQL() == null) {
|
||||
((SelectImpl)sel).setSQL(store, fetch);
|
||||
found = false;
|
||||
}
|
||||
|
||||
// only cache the union when elems length is 1 for now
|
||||
if (!found) {
|
||||
Object[] objs1 = new Object[2];
|
||||
objs1[0] = union;
|
||||
objs1[1] = resJoins[0];
|
||||
((JDBCStoreManager)store).addToSqlCache(
|
||||
storeCollectionUnionCache, selKey, objs1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log log = store.getConfiguration().
|
||||
getLog(JDBCConfiguration.LOG_JDBC);
|
||||
if (log.isTraceEnabled()) {
|
||||
if (found)
|
||||
log.trace(_loc.get("cache-hit", field, this.getClass()));
|
||||
else
|
||||
log.trace(_loc.get("cache-missed", field, this.getClass()));
|
||||
}
|
||||
|
||||
ClassMapping mapping = field.getDefiningMapping();
|
||||
Object oid = sm.getObjectId();
|
||||
|
||||
if (sel == null)
|
||||
sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
|
||||
getDelegate();
|
||||
|
||||
ValueMapping embed = mapping.getEmbeddingMapping();
|
||||
if (embed != null)
|
||||
mapping = getOwner(embed);
|
||||
|
||||
if (mapping != null) {
|
||||
Column[] cols = mapping.getPrimaryKeyColumns();
|
||||
sel.wherePrimaryKey(mapping, cols, cols, oid, store,
|
||||
null, null, parmList);
|
||||
}
|
||||
|
||||
List nonFKParams = sel.getSQL().getNonFKParameters();
|
||||
if (nonFKParams != null && nonFKParams.size() > 0)
|
||||
parmList.addAll(nonFKParams);
|
||||
}
|
||||
|
||||
// create proxy
|
||||
Object coll;
|
||||
ChangeTracker ct = null;
|
||||
|
@ -626,7 +545,7 @@ public abstract class StoreCollectionFieldStrategy
|
|||
}
|
||||
|
||||
// load values
|
||||
Result res = union.execute(store, fetch, parmList);
|
||||
Result res = union.execute(store, fetch);
|
||||
try {
|
||||
int seq = -1;
|
||||
while (res.next()) {
|
||||
|
@ -649,32 +568,7 @@ public abstract class StoreCollectionFieldStrategy
|
|||
else
|
||||
sm.storeObject(field.getIndex(), coll);
|
||||
}
|
||||
|
||||
private ClassMapping getOwner(ValueMapping embed) {
|
||||
if (embed == null)
|
||||
return null;
|
||||
ClassMapping owner = embed.getFieldMapping().getDefiningMapping();
|
||||
if (owner.getPrimaryKeyFields().length > 0)
|
||||
return owner;
|
||||
ValueMapping embed1 = (ValueMapping) owner.getEmbeddingMetaData();
|
||||
return getOwner(embed1);
|
||||
}
|
||||
|
||||
protected Union newUnion(final OpenJPAStateManager sm, final JDBCStore store,
|
||||
final JDBCFetchConfiguration fetch, final ClassMapping[] elems,
|
||||
final Joins[] resJoins) {
|
||||
Union union = store.getSQLFactory().newUnion
|
||||
(Math.max(1, elems.length));
|
||||
union.select(new Union.Selector() {
|
||||
public void select(Select sel, int idx) {
|
||||
ClassMapping elem = (elems.length == 0) ? null : elems[idx];
|
||||
resJoins[idx] = selectAll(sel, elem, sm, store, fetch,
|
||||
JDBCFetchConfiguration.EAGER_PARALLEL);
|
||||
}
|
||||
});
|
||||
return union;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select data for loading, starting in field table.
|
||||
*/
|
||||
|
|
|
@ -56,7 +56,6 @@ public final class SQLBuffer
|
|||
private List _subsels = null;
|
||||
private List _params = null;
|
||||
private List _cols = null;
|
||||
private List _nonFKParams = null;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
@ -147,11 +146,6 @@ public final class SQLBuffer
|
|||
_cols.add(paramIndex, null);
|
||||
}
|
||||
}
|
||||
if (buf._nonFKParams != null) {
|
||||
if (_nonFKParams == null)
|
||||
_nonFKParams = new ArrayList();
|
||||
_nonFKParams.addAll(buf._nonFKParams);
|
||||
}
|
||||
}
|
||||
|
||||
public SQLBuffer append(Table table) {
|
||||
|
@ -271,11 +265,6 @@ public final class SQLBuffer
|
|||
if (isFK)
|
||||
break;
|
||||
}
|
||||
if (!isFK) {
|
||||
if (_nonFKParams == null)
|
||||
_nonFKParams = new ArrayList();
|
||||
_nonFKParams.add(o);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -399,9 +388,6 @@ public final class SQLBuffer
|
|||
return (_params == null) ? Collections.EMPTY_LIST : _params;
|
||||
}
|
||||
|
||||
public List getNonFKParameters() {
|
||||
return (_nonFKParams == null) ? Collections.EMPTY_LIST : _nonFKParams;
|
||||
}
|
||||
/**
|
||||
* Return the SQL for this buffer.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue