mirror of
https://github.com/apache/openjpa.git
synced 2025-02-08 02:59:42 +00:00
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:
parent
3dee2ca176
commit
024ff20a8c
@ -525,57 +525,58 @@ public abstract class StoreCollectionFieldStrategy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// select data for this state manager
|
// select data for this state manager
|
||||||
final ClassMapping[] elems = getIndependentElementMappings(true);
|
synchronized (this) {
|
||||||
final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
|
final ClassMapping[] elems = getIndependentElementMappings(true);
|
||||||
Union union;
|
final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
|
||||||
if (_executor == null) {
|
Union union;
|
||||||
union = store.getSQLFactory().newUnion(Math.max(1, elems.length));
|
if (_executor == null) {
|
||||||
if (store.getConfiguration().getSelectCacheEnabled()) {
|
union = store.getSQLFactory().newUnion(Math.max(1, elems.length));
|
||||||
_executor = union;
|
if (store.getConfiguration().getSelectCacheEnabled()) {
|
||||||
}
|
_executor = union;
|
||||||
} else {
|
}
|
||||||
union = (Union)_executor;
|
} else {
|
||||||
}
|
union = (Union)_executor;
|
||||||
union.select(new Union.Selector() {
|
}
|
||||||
public void select(Select sel, int idx) {
|
union.select(new Union.Selector() {
|
||||||
ClassMapping elem = (elems.length == 0) ? null : elems[idx];
|
public void select(Select sel, int idx) {
|
||||||
resJoins[idx] = selectAll(sel, elem, sm, store, fetch, JDBCFetchConfiguration.EAGER_PARALLEL);
|
ClassMapping elem = (elems.length == 0) ? null : elems[idx];
|
||||||
}
|
resJoins[idx] = selectAll(sel, elem, sm, store, fetch, JDBCFetchConfiguration.EAGER_PARALLEL);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// create proxy
|
// create proxy
|
||||||
Object coll;
|
Object coll;
|
||||||
ChangeTracker ct = null;
|
ChangeTracker ct = null;
|
||||||
if (field.getTypeCode() == JavaTypes.ARRAY)
|
if (field.getTypeCode() == JavaTypes.ARRAY)
|
||||||
coll = new ArrayList();
|
coll = new ArrayList();
|
||||||
else {
|
else {
|
||||||
coll = sm.newProxy(field.getIndex());
|
coll = sm.newProxy(field.getIndex());
|
||||||
if (coll instanceof Proxy)
|
if (coll instanceof Proxy)
|
||||||
ct = ((Proxy) coll).getChangeTracker();
|
ct = ((Proxy) coll).getChangeTracker();
|
||||||
}
|
}
|
||||||
|
|
||||||
// load values
|
// load values
|
||||||
Result res = union.execute(store, fetch);
|
Result res = union.execute(store, fetch);
|
||||||
try {
|
try {
|
||||||
int seq = -1;
|
int seq = -1;
|
||||||
while (res.next()) {
|
boolean ordered = ct != null && field.getOrderColumn() != null;
|
||||||
if (ct != null && field.getOrderColumn() != null)
|
while (res.next()) {
|
||||||
seq = res.getInt(field.getOrderColumn());
|
if (ordered) 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user