You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2008/12/22 21:07:38 UTC
svn commit: r728758 - in
/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc:
meta/strats/StoreCollectionFieldStrategy.java sql/SQLBuffer.java
Author: faywang
Date: Mon Dec 22 12:07:38 2008
New Revision: 728758
URL: http://svn.apache.org/viewvc?rev=728758&view=rev
Log:
OPENJPA-838: remove cache from StoreCollectionFieldStrategy
Modified:
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=728758&r1=728757&r2=728758&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java Mon Dec 22 12:07:38 2008
@@ -26,11 +26,8 @@
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.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,86 +520,19 @@
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];
- }
- 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()));
+ 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);
}
-
- ClassMapping mapping = field.getDefiningMapping();
- Object oid = sm.getObjectId();
- Column[] cols = mapping.getPrimaryKeyColumns();
- if (sel == null)
- sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
- getDelegate();
-
- 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;
@@ -618,7 +545,7 @@
}
// load values
- Result res = union.execute(store, fetch, parmList);
+ Result res = union.execute(store, fetch);
try {
int seq = -1;
while (res.next()) {
@@ -642,21 +569,6 @@
sm.storeObject(field.getIndex(), coll);
}
- 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.
*/
Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?rev=728758&r1=728757&r2=728758&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java (original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java Mon Dec 22 12:07:38 2008
@@ -56,7 +56,6 @@
private List _subsels = null;
private List _params = null;
private List _cols = null;
- private List _nonFKParams = null;
/**
* Default constructor.
@@ -147,11 +146,6 @@
_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 @@
if (isFK)
break;
}
- if (!isFK) {
- if (_nonFKParams == null)
- _nonFKParams = new ArrayList();
- _nonFKParams.add(o);
- }
}
return this;
}
@@ -399,9 +388,6 @@
return (_params == null) ? Collections.EMPTY_LIST : _params;
}
- public List getNonFKParameters() {
- return (_nonFKParams == null) ? Collections.EMPTY_LIST : _nonFKParams;
- }
/**
* Return the SQL for this buffer.
*/