use of org.hibernate.engine.query.spi.FilterQueryPlan in project hibernate-orm by hibernate.
the class SessionImpl method listFilter.
@Override
public List listFilter(Object collection, String filter, QueryParameters queryParameters) {
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
FilterQueryPlan plan = getFilterQueryPlan(collection, filter, queryParameters, false);
List results = Collections.EMPTY_LIST;
boolean success = false;
//stops flush being called multiple times if this method is recursively called
dontFlushFromFind++;
try {
results = plan.performList(queryParameters, this);
success = true;
} finally {
dontFlushFromFind--;
afterOperation(success);
delayedAfterCompletion();
}
return results;
}
use of org.hibernate.engine.query.spi.FilterQueryPlan in project hibernate-orm by hibernate.
the class SessionImpl method getFilterQueryPlan.
private FilterQueryPlan getFilterQueryPlan(Object collection, String filter, QueryParameters parameters, boolean shallow) throws HibernateException {
if (collection == null) {
throw new NullPointerException("null collection passed to filter");
}
CollectionEntry entry = persistenceContext.getCollectionEntryOrNull(collection);
final CollectionPersister roleBeforeFlush = (entry == null) ? null : entry.getLoadedPersister();
FilterQueryPlan plan = null;
if (roleBeforeFlush == null) {
// if it was previously unreferenced, we need to flush in order to
// get its state into the database in order to execute query
flush();
entry = persistenceContext.getCollectionEntryOrNull(collection);
CollectionPersister roleAfterFlush = (entry == null) ? null : entry.getLoadedPersister();
if (roleAfterFlush == null) {
throw new QueryException("The collection was unreferenced");
}
plan = getFactory().getQueryPlanCache().getFilterQueryPlan(filter, roleAfterFlush.getRole(), shallow, getLoadQueryInfluencers().getEnabledFilters());
} else {
// otherwise, we only need to flush if there are in-memory changes
// to the queried tables
plan = getFactory().getQueryPlanCache().getFilterQueryPlan(filter, roleBeforeFlush.getRole(), shallow, getLoadQueryInfluencers().getEnabledFilters());
if (autoFlushIfRequired(plan.getQuerySpaces())) {
// might need to run a different filter entirely afterQuery the flush
// because the collection role may have changed
entry = persistenceContext.getCollectionEntryOrNull(collection);
CollectionPersister roleAfterFlush = (entry == null) ? null : entry.getLoadedPersister();
if (roleBeforeFlush != roleAfterFlush) {
if (roleAfterFlush == null) {
throw new QueryException("The collection was dereferenced");
}
plan = getFactory().getQueryPlanCache().getFilterQueryPlan(filter, roleAfterFlush.getRole(), shallow, getLoadQueryInfluencers().getEnabledFilters());
}
}
}
if (parameters != null) {
parameters.getPositionalParameterValues()[0] = entry.getLoadedKey();
parameters.getPositionalParameterTypes()[0] = entry.getLoadedPersister().getKeyType();
}
return plan;
}
use of org.hibernate.engine.query.spi.FilterQueryPlan in project hibernate-orm by hibernate.
the class SessionImpl method iterateFilter.
@Override
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) {
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
FilterQueryPlan plan = getFilterQueryPlan(collection, filter, queryParameters, true);
Iterator itr = plan.performIterate(queryParameters, this);
delayedAfterCompletion();
return itr;
}
Aggregations