Search in sources :

Example 1 with FilterQueryPlan

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;
}
Also used : FilterQueryPlan(org.hibernate.engine.query.spi.FilterQueryPlan) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with FilterQueryPlan

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;
}
Also used : FilterQueryPlan(org.hibernate.engine.query.spi.FilterQueryPlan) QueryException(org.hibernate.QueryException) CollectionEntry(org.hibernate.engine.spi.CollectionEntry) CollectionPersister(org.hibernate.persister.collection.CollectionPersister)

Example 3 with FilterQueryPlan

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;
}
Also used : FilterQueryPlan(org.hibernate.engine.query.spi.FilterQueryPlan) Iterator(java.util.Iterator)

Aggregations

FilterQueryPlan (org.hibernate.engine.query.spi.FilterQueryPlan)3 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 QueryException (org.hibernate.QueryException)1 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)1 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)1