use of org.hibernate.internal.ScrollableResultsImpl in project hibernate-orm by hibernate.
the class Loader method scroll.
/**
* Return the query results, as an instance of <tt>ScrollableResults</tt>
*
* @param queryParameters The parameters with which the query should be executed.
* @param returnTypes The expected return types of the query
* @param holderInstantiator If the return values are expected to be wrapped
* in a holder, this is the thing that knows how to wrap them.
* @param session The session from which the scroll request originated.
*
* @return The ScrollableResults instance.
*
* @throws HibernateException Indicates an error executing the query, or constructing
* the ScrollableResults.
*/
protected ScrollableResultsImplementor scroll(final QueryParameters queryParameters, final Type[] returnTypes, final HolderInstantiator holderInstantiator, final SharedSessionContractImplementor session) throws HibernateException {
checkScrollability();
final boolean stats = getQueryIdentifier() != null && getFactory().getStatistics().isStatisticsEnabled();
long startTime = 0;
if (stats) {
startTime = System.nanoTime();
}
try {
// Don't use Collections#emptyList() here -- follow on locking potentially adds AfterLoadActions,
// so the list cannot be immutable.
final SqlStatementWrapper wrapper = executeQueryStatement(queryParameters, true, new ArrayList<AfterLoadAction>(), session);
final ResultSet rs = wrapper.getResultSet();
final PreparedStatement st = (PreparedStatement) wrapper.getStatement();
if (stats) {
final long endTime = System.nanoTime();
final long milliseconds = TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS);
getFactory().getStatistics().queryExecuted(getQueryIdentifier(), 0, milliseconds);
}
if (needsFetchingScroll()) {
return new FetchingScrollableResultsImpl(rs, st, session, this, queryParameters, returnTypes, holderInstantiator);
} else {
return new ScrollableResultsImpl(rs, st, session, this, queryParameters, returnTypes, holderInstantiator);
}
} catch (SQLException sqle) {
throw factory.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not execute query using scroll", getSQLString());
}
}
Aggregations