use of org.eclipse.persistence.queries.Cursor in project querydsl by querydsl.
the class EclipseLinkHandler method iterate.
@SuppressWarnings("unchecked")
@Override
public <T> CloseableIterator<T> iterate(Query query, FactoryExpression<?> projection) {
Iterator<T> iterator = null;
Closeable closeable = null;
if (query instanceof JpaQuery) {
JpaQuery<T> elQuery = (JpaQuery<T>) query;
elQuery.setHint(QueryHints.RESULT_SET_TYPE, ResultSetType.ForwardOnly);
elQuery.setHint(QueryHints.SCROLLABLE_CURSOR, true);
final Cursor cursor = elQuery.getResultCursor();
closeable = new Closeable() {
@Override
public void close() throws IOException {
cursor.close();
}
};
iterator = cursor;
} else {
iterator = query.getResultList().iterator();
}
if (projection != null) {
return new TransformingIterator<T>(iterator, closeable, projection);
} else {
return new IteratorAdapter<T>(iterator, closeable);
}
}
Aggregations