Search in sources :

Example 1 with ScrollableResultsImpl

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());
    }
}
Also used : SQLException(java.sql.SQLException) AfterLoadAction(org.hibernate.loader.spi.AfterLoadAction) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) FetchingScrollableResultsImpl(org.hibernate.internal.FetchingScrollableResultsImpl) FetchingScrollableResultsImpl(org.hibernate.internal.FetchingScrollableResultsImpl) ScrollableResultsImpl(org.hibernate.internal.ScrollableResultsImpl)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 FetchingScrollableResultsImpl (org.hibernate.internal.FetchingScrollableResultsImpl)1 ScrollableResultsImpl (org.hibernate.internal.ScrollableResultsImpl)1 AfterLoadAction (org.hibernate.loader.spi.AfterLoadAction)1