use of org.hibernate.engine.spi.SubselectFetch in project hibernate-orm by hibernate.
the class AbstractCollectionPersister method getSubselectInitializer.
private CollectionInitializer getSubselectInitializer(Serializable key, SharedSessionContractImplementor session) {
if (!isSubselectLoadable()) {
return null;
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
SubselectFetch subselect = persistenceContext.getBatchFetchQueue().getSubselect(session.generateEntityKey(key, getOwnerEntityPersister()));
if (subselect == null) {
return null;
} else {
// Take care of any entities that might have
// been evicted!
Iterator iter = subselect.getResult().iterator();
while (iter.hasNext()) {
if (!persistenceContext.containsEntity((EntityKey) iter.next())) {
iter.remove();
}
}
// Run a subquery loader
return createSubselectInitializer(subselect, session);
}
}
use of org.hibernate.engine.spi.SubselectFetch in project hibernate-orm by hibernate.
the class ResultSetProcessingContextImpl method createSubselects.
private void createSubselects() {
if (subselectLoadableEntityKeyMap == null || nRowsRead <= 1) {
LOG.tracef("Skipping create subselects because there are fewer than 2 results, so query by key is more efficient.", getClass().getName());
// early return
return;
}
final Map<String, int[]> namedParameterLocMap = ResultSetProcessorHelper.buildNamedParameterLocMap(queryParameters, namedParameterContext);
final String subselectQueryString = SubselectFetch.createSubselectFetchQueryFragment(queryParameters);
for (Map.Entry<EntityReference, Set<EntityKey>> entry : subselectLoadableEntityKeyMap.entrySet()) {
if (!entry.getKey().getEntityPersister().hasSubselectLoadableCollections()) {
continue;
}
SubselectFetch subselectFetch = new SubselectFetch(subselectQueryString, aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(entry.getKey().getQuerySpaceUid()), (Loadable) entry.getKey().getEntityPersister(), queryParameters, entry.getValue(), namedParameterLocMap);
for (EntityKey key : entry.getValue()) {
session.getPersistenceContext().getBatchFetchQueue().addSubselect(key, subselectFetch);
}
}
}
use of org.hibernate.engine.spi.SubselectFetch in project hibernate-orm by hibernate.
the class Loader method createSubselects.
private void createSubselects(List keys, QueryParameters queryParameters, SharedSessionContractImplementor session) {
if (keys.size() > 1) {
//if we only returned one entity, query by key is more efficient
Set[] keySets = transpose(keys);
Map namedParameterLocMap = buildNamedParameterLocMap(queryParameters);
final Loadable[] loadables = getEntityPersisters();
final String[] aliases = getAliases();
final String subselectQueryString = SubselectFetch.createSubselectFetchQueryFragment(queryParameters);
for (Object key : keys) {
final EntityKey[] rowKeys = (EntityKey[]) key;
for (int i = 0; i < rowKeys.length; i++) {
if (rowKeys[i] != null && loadables[i].hasSubselectLoadableCollections()) {
SubselectFetch subselectFetch = new SubselectFetch(subselectQueryString, aliases[i], loadables[i], queryParameters, keySets[i], namedParameterLocMap);
session.getPersistenceContext().getBatchFetchQueue().addSubselect(rowKeys[i], subselectFetch);
}
}
}
}
}
Aggregations