OPENJPA-2099: Guard cached select

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1233026 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2012-01-18 19:58:59 +00:00
parent 3dee2ca176
commit 024ff20a8c
2 changed files with 63 additions and 62 deletions

View File

@ -525,57 +525,58 @@ public abstract class StoreCollectionFieldStrategy
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);
}
}
}

View File

@ -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;