Author: ppoddar
Date: Wed Jan 18 19:58:59 2012
New Revision: 1233026
URL: http://svn.apache.org/viewvc?rev=1233026&view=rev
Log:
OPENJPA-2099: Guard cached select
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=1233026&r1=1233025&r2=1233026&view=diff
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
Wed Jan 18 19:58:59 2012
@@ -525,57 +525,58 @@ public abstract class StoreCollectionFie
return;
}
// select data for this state manager
- final ClassMapping[] elems = getIndependentElementMappings(true);
- final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
- Union union;
- if (_executor == null) {
- union = store.getSQLFactory().newUnion(Math.max(1,
elems.length));
- if (store.getConfiguration().getSelectCacheEnabled()) {
- _executor = union;
- }
- } else {
- union = (Union)_executor;
- }
- 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);
- }
- });
-
- // create proxy
- Object coll;
- ChangeTracker ct = null;
- if (field.getTypeCode() == JavaTypes.ARRAY)
- coll = new ArrayList();
- else {
- coll = sm.newProxy(field.getIndex());
- if (coll instanceof Proxy)
- ct = ((Proxy) coll).getChangeTracker();
- }
-
- // load values
- Result res = union.execute(store, fetch);
- try {
- int seq = -1;
- while (res.next()) {
- if (ct != null && field.getOrderColumn() != null)
- seq = res.getInt(field.getOrderColumn());
- setMappedBy(sm.getObjectId(), sm, coll, res);
- add(store, coll, loadElement(sm, store, fetch, res,
resJoins[res.indexOf()]));
- }
- if (ct != null && field.getOrderColumn() != null)
- ct.setNextSequence(seq + 1);
- } finally {
- res.close();
- }
-
- // set into sm
- if (field.getTypeCode() == JavaTypes.ARRAY) {
- sm.storeObject(field.getIndex(), JavaTypes.toArray
- ((Collection) coll, field.getElement().getType()));
- } else {
- sm.storeObject(field.getIndex(), coll);
+ synchronized (this) {
+ final ClassMapping[] elems =
getIndependentElementMappings(true);
+ final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
+ Union union;
+ if (_executor == null) {
+ union = store.getSQLFactory().newUnion(Math.max(1,
elems.length));
+ if (store.getConfiguration().getSelectCacheEnabled()) {
+ _executor = union;
+ }
+ } else {
+ union = (Union)_executor;
+ }
+ 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);
+ }
+ });
+
+ // create proxy
+ Object coll;
+ ChangeTracker ct = null;
+ if (field.getTypeCode() == JavaTypes.ARRAY)
+ coll = new ArrayList();
+ else {
+ coll = sm.newProxy(field.getIndex());
+ if (coll instanceof Proxy)
+ ct = ((Proxy) coll).getChangeTracker();
+ }
+
+ // load values
+ Result res = union.execute(store, fetch);
+ try {
+ int seq = -1;
+ boolean ordered = ct != null && field.getOrderColumn() !=
null;
+ while (res.next()) {
+ if (ordered) seq = res.getInt(field.getOrderColumn());
+ setMappedBy(sm.getObjectId(), sm, coll, res);
+ add(store, coll, loadElement(sm, store, fetch, res,
resJoins[res.indexOf()]));
+ }
+ if (ordered) ct.setNextSequence(seq + 1);
+ } finally {
+ res.close();
+ }
+
+ // set into sm
+ if (field.getTypeCode() == JavaTypes.ARRAY) {
+ sm.storeObject(field.getIndex(),
+ JavaTypes.toArray((Collection<?>) coll,
field.getElement().getType()));
+ } else {
+ sm.storeObject(field.getIndex(), coll);
+ }
}
}
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=1233026&r1=1233025&r2=1233026&view=diff
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Wed Jan 18 19:58:59 2012
@@ -1404,15 +1404,15 @@ public class SelectImpl
return;
}
+ Object[] params = getBindParameter(oid, mapping, toCols, fromCols, pj,
store);
SQLBuffer buf = isReadOnly() ? _where : new SQLBuffer(_dict);
- Object[] params = getBindParameter(oid, mapping, toCols, fromCols, pj,
store);
bindParameter(buf, params, fromCols, pj);
if (constCols != null && constCols.length > 0) {
bindParameter(buf, vals, constCols, pj);
}
- if (buf != _where) {
+ if (!isReadOnly()) {
where(buf, pj);
}
}
@@ -1498,22 +1498,22 @@ public class SelectImpl
}
public void where(Joins joins) {
+ assertMutable();
if (joins != null)
- where((SQLBuffer) null, joins);
- }
-
- public void where(SQLBuffer sql) {
- where(sql, (Joins) null);
+ getJoins(joins, true);
}
public void where(SQLBuffer sql, Joins joins) {
- where(sql, getJoins(joins, true));
+ assertMutable();
+ where(joins);
+ where(sql);
}
/**
* Add the given condition to the WHERE clause.
*/
- private void where(SQLBuffer sql, PathJoins pj) {
+ public void where(SQLBuffer sql) {
+ assertMutable();
// no need to use joins...
if (sql == null || sql.isEmpty())
return;
@@ -3132,9 +3132,9 @@ public class SelectImpl
}
int idx;
- if (_aliases.put(id, alias) != null)
+ if (_aliases.put(id, alias) != null) {
idx = _ids.indexOf(id);
- else {
+ } else {
_ids.add(id);
idx = _ids.size() - 1;