Search in sources :

Example 1 with CriteriaLoader

use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.

the class SessionImpl method scroll.

@Override
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
    checkOpenOrWaitingForAutoClose();
    checkTransactionSynchStatus();
    String entityName = criteriaImpl.getEntityOrClassName();
    CriteriaLoader loader = new CriteriaLoader(getOuterJoinLoadable(entityName), getFactory(), criteriaImpl, entityName, getLoadQueryInfluencers());
    autoFlushIfRequired(loader.getQuerySpaces());
    dontFlushFromFind++;
    try {
        return loader.scroll(this, scrollMode);
    } finally {
        delayedAfterCompletion();
        dontFlushFromFind--;
    }
}
Also used : CriteriaLoader(org.hibernate.loader.criteria.CriteriaLoader)

Example 2 with CriteriaLoader

use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.

the class StatelessSessionImpl method list.

@Override
@SuppressWarnings({ "unchecked" })
public List list(Criteria criteria) throws HibernateException {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
    checkOpen();
    String[] implementors = getFactory().getMetamodel().getImplementors(criteriaImpl.getEntityOrClassName());
    int size = implementors.length;
    CriteriaLoader[] loaders = new CriteriaLoader[size];
    for (int i = 0; i < size; i++) {
        loaders[i] = new CriteriaLoader(getOuterJoinLoadable(implementors[i]), getFactory(), criteriaImpl, implementors[i], getLoadQueryInfluencers());
    }
    List results = Collections.EMPTY_LIST;
    boolean success = false;
    try {
        for (int i = 0; i < size; i++) {
            final List currentResults = loaders[i].list(this);
            currentResults.addAll(results);
            results = currentResults;
        }
        success = true;
    } finally {
        afterOperation(success);
    }
    temporaryPersistenceContext.clear();
    return results;
}
Also used : CriteriaLoader(org.hibernate.loader.criteria.CriteriaLoader) List(java.util.List)

Example 3 with CriteriaLoader

use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.

the class StatelessSessionImpl method scroll.

@Override
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
    checkOpen();
    String entityName = criteriaImpl.getEntityOrClassName();
    CriteriaLoader loader = new CriteriaLoader(getOuterJoinLoadable(entityName), getFactory(), criteriaImpl, entityName, getLoadQueryInfluencers());
    return loader.scroll(this, scrollMode);
}
Also used : CriteriaLoader(org.hibernate.loader.criteria.CriteriaLoader)

Example 4 with CriteriaLoader

use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.

the class SessionImpl method list.

@Override
public List list(Criteria criteria) throws HibernateException {
    // TODO: Is this guaranteed to always be CriteriaImpl?
    CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
    if (criteriaImpl.getMaxResults() != null && criteriaImpl.getMaxResults() == 0) {
        return Collections.EMPTY_LIST;
    }
    final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess(criteriaImpl);
    if (naturalIdLoadAccess != null) {
        // EARLY EXIT!
        return Arrays.asList(naturalIdLoadAccess.load());
    }
    checkOpenOrWaitingForAutoClose();
    //		checkTransactionSynchStatus();
    String[] implementors = getFactory().getMetamodel().getImplementors(criteriaImpl.getEntityOrClassName());
    int size = implementors.length;
    CriteriaLoader[] loaders = new CriteriaLoader[size];
    Set spaces = new HashSet();
    for (int i = 0; i < size; i++) {
        loaders[i] = new CriteriaLoader(getOuterJoinLoadable(implementors[i]), getFactory(), criteriaImpl, implementors[i], getLoadQueryInfluencers());
        spaces.addAll(loaders[i].getQuerySpaces());
    }
    autoFlushIfRequired(spaces);
    List results = Collections.EMPTY_LIST;
    dontFlushFromFind++;
    boolean success = false;
    try {
        for (int i = 0; i < size; i++) {
            final List currentResults = loaders[i].list(this);
            currentResults.addAll(results);
            results = currentResults;
        }
        success = true;
    } finally {
        dontFlushFromFind--;
        afterOperation(success);
        delayedAfterCompletion();
    }
    return results;
}
Also used : NaturalIdLoadAccess(org.hibernate.NaturalIdLoadAccess) SimpleNaturalIdLoadAccess(org.hibernate.SimpleNaturalIdLoadAccess) Set(java.util.Set) HashSet(java.util.HashSet) CriteriaLoader(org.hibernate.loader.criteria.CriteriaLoader) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 5 with CriteriaLoader

use of org.hibernate.loader.criteria.CriteriaLoader in project midpoint by Evolveum.

the class HibernateToSqlTranslator method toSql.

/**
     * Do not use in production code! Only for testing purposes only. Used for example during query engine upgrade.
     * Method provides translation from hibernate {@link Criteria} to plain SQL string query.
     *
     * @param criteria
     * @return SQL string, null if criteria parameter was null.
     */
public static String toSql(Criteria criteria) {
    if (criteria == null) {
        return null;
    }
    try {
        CriteriaImpl c;
        if (criteria instanceof CriteriaImpl) {
            c = (CriteriaImpl) criteria;
        } else {
            CriteriaImpl.Subcriteria subcriteria = (CriteriaImpl.Subcriteria) criteria;
            c = (CriteriaImpl) subcriteria.getParent();
        }
        SessionImpl s = (SessionImpl) c.getSession();
        SessionFactoryImplementor factory = s.getSessionFactory();
        String[] implementors = factory.getImplementors(c.getEntityOrClassName());
        CriteriaLoader loader = new CriteriaLoader((OuterJoinLoadable) factory.getEntityPersister(implementors[0]), factory, c, implementors[0], s.getLoadQueryInfluencers());
        Field f = OuterJoinLoader.class.getDeclaredField("sql");
        f.setAccessible(true);
        return (String) f.get(loader);
    } catch (Exception ex) {
        throw new SystemException(ex.getMessage(), ex);
    }
}
Also used : Field(java.lang.reflect.Field) CriteriaImpl(org.hibernate.internal.CriteriaImpl) SystemException(com.evolveum.midpoint.util.exception.SystemException) CriteriaLoader(org.hibernate.loader.criteria.CriteriaLoader) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SessionImpl(org.hibernate.internal.SessionImpl) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Aggregations

CriteriaLoader (org.hibernate.loader.criteria.CriteriaLoader)5 List (java.util.List)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 NaturalIdLoadAccess (org.hibernate.NaturalIdLoadAccess)1 SimpleNaturalIdLoadAccess (org.hibernate.SimpleNaturalIdLoadAccess)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 CriteriaImpl (org.hibernate.internal.CriteriaImpl)1 SessionImpl (org.hibernate.internal.SessionImpl)1