// 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()));
}
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;
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, parmList);
try {
int seq = -1;
while (res.next()) {
if (ct != null && field.getOrderColumn() != null)
seq = res.getInt(field.getOrderColumn());