Search in sources :

Example 1 with HibernateQuery

use of org.hibernate.jpa.HibernateQuery in project querydsl by querydsl.

the class HibernateHandler method transform.

@Override
public boolean transform(Query query, FactoryExpression<?> projection) {
    if (query instanceof HibernateQuery) {
        ResultTransformer transformer = new FactoryExpressionTransformer(projection);
        ((HibernateQuery) query).getHibernateQuery().setResultTransformer(transformer);
        return true;
    } else {
        return false;
    }
}
Also used : HibernateQuery(org.hibernate.jpa.HibernateQuery) ResultTransformer(org.hibernate.transform.ResultTransformer)

Example 2 with HibernateQuery

use of org.hibernate.jpa.HibernateQuery in project querydsl by querydsl.

the class HibernateHandler method iterate.

@SuppressWarnings("unchecked")
@Override
public <T> CloseableIterator<T> iterate(Query query, FactoryExpression<?> projection) {
    if (query instanceof HibernateQuery) {
        HibernateQuery hQuery = (HibernateQuery) query;
        ScrollableResults results = hQuery.getHibernateQuery().scroll(ScrollMode.FORWARD_ONLY);
        CloseableIterator<T> iterator = new ScrollableResultsIterator<T>(results);
        if (projection != null) {
            iterator = new TransformingIterator<T>(iterator, projection);
        }
        return iterator;
    } else {
        Iterator<T> iterator = query.getResultList().iterator();
        if (projection != null) {
            return new TransformingIterator<T>(iterator, projection);
        } else {
            return new IteratorAdapter<T>(iterator);
        }
    }
}
Also used : IteratorAdapter(com.mysema.commons.lang.IteratorAdapter) HibernateQuery(org.hibernate.jpa.HibernateQuery) ScrollableResults(org.hibernate.ScrollableResults)

Aggregations

HibernateQuery (org.hibernate.jpa.HibernateQuery)2 IteratorAdapter (com.mysema.commons.lang.IteratorAdapter)1 ScrollableResults (org.hibernate.ScrollableResults)1 ResultTransformer (org.hibernate.transform.ResultTransformer)1