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,6 +525,7 @@ public abstract class StoreCollectionFieldStrategy
return; return;
} }
// select data for this state manager // select data for this state manager
synchronized (this) {
final ClassMapping[] elems = getIndependentElementMappings(true); final ClassMapping[] elems = getIndependentElementMappings(true);
final Joins[] resJoins = new Joins[Math.max(1, elems.length)]; final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
Union union; Union union;
@ -558,26 +559,26 @@ public abstract class StoreCollectionFieldStrategy
Result res = union.execute(store, fetch); Result res = union.execute(store, fetch);
try { try {
int seq = -1; int seq = -1;
boolean ordered = ct != null && field.getOrderColumn() != null;
while (res.next()) { while (res.next()) {
if (ct != null && field.getOrderColumn() != null) if (ordered) seq = res.getInt(field.getOrderColumn());
seq = res.getInt(field.getOrderColumn());
setMappedBy(sm.getObjectId(), sm, coll, res); setMappedBy(sm.getObjectId(), sm, coll, res);
add(store, coll, loadElement(sm, store, fetch, res, resJoins[res.indexOf()])); add(store, coll, loadElement(sm, store, fetch, res, resJoins[res.indexOf()]));
} }
if (ct != null && field.getOrderColumn() != null) if (ordered) ct.setNextSequence(seq + 1);
ct.setNextSequence(seq + 1);
} finally { } finally {
res.close(); res.close();
} }
// set into sm // set into sm
if (field.getTypeCode() == JavaTypes.ARRAY) { if (field.getTypeCode() == JavaTypes.ARRAY) {
sm.storeObject(field.getIndex(), JavaTypes.toArray sm.storeObject(field.getIndex(),
((Collection) coll, field.getElement().getType())); JavaTypes.toArray((Collection<?>) coll, field.getElement().getType()));
} else { } else {
sm.storeObject(field.getIndex(), coll); sm.storeObject(field.getIndex(), coll);
} }
} }
}
/** /**
* Selects data for loading, starting in field table. * Selects data for loading, starting in field table.

View File

@ -1404,15 +1404,15 @@ public class SelectImpl
return; return;
} }
Object[] params = getBindParameter(oid, mapping, toCols, fromCols, pj, store);
SQLBuffer buf = isReadOnly() ? _where : new SQLBuffer(_dict); SQLBuffer buf = isReadOnly() ? _where : new SQLBuffer(_dict);
Object[] params = getBindParameter(oid, mapping, toCols, fromCols, pj, store);
bindParameter(buf, params, fromCols, pj); bindParameter(buf, params, fromCols, pj);
if (constCols != null && constCols.length > 0) { if (constCols != null && constCols.length > 0) {
bindParameter(buf, vals, constCols, pj); bindParameter(buf, vals, constCols, pj);
} }
if (buf != _where) { if (!isReadOnly()) {
where(buf, pj); where(buf, pj);
} }
} }
@ -1498,22 +1498,22 @@ public class SelectImpl
} }
public void where(Joins joins) { public void where(Joins joins) {
assertMutable();
if (joins != null) if (joins != null)
where((SQLBuffer) null, joins); getJoins(joins, true);
}
public void where(SQLBuffer sql) {
where(sql, (Joins) null);
} }
public void where(SQLBuffer sql, Joins joins) { 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. * 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... // no need to use joins...
if (sql == null || sql.isEmpty()) if (sql == null || sql.isEmpty())
return; return;
@ -3132,9 +3132,9 @@ public class SelectImpl
} }
int idx; int idx;
if (_aliases.put(id, alias) != null) if (_aliases.put(id, alias) != null) {
idx = _ids.indexOf(id); idx = _ids.indexOf(id);
else { } else {
_ids.add(id); _ids.add(id);
idx = _ids.size() - 1; idx = _ids.size() - 1;