Search in sources :

Example 1 with IteratorImpl

use of org.hibernate.internal.IteratorImpl in project hibernate-orm by hibernate.

the class QueryLoader method iterate.

public Iterator iterate(QueryParameters queryParameters, EventSource session) throws HibernateException {
    checkQuery(queryParameters);
    final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
    long startTime = 0;
    if (stats) {
        startTime = System.nanoTime();
    }
    try {
        if (queryParameters.isCallable()) {
            throw new QueryException("iterate() not supported for callable statements");
        }
        final SqlStatementWrapper wrapper = executeQueryStatement(queryParameters, false, Collections.emptyList(), session);
        final ResultSet rs = wrapper.getResultSet();
        final PreparedStatement st = (PreparedStatement) wrapper.getStatement();
        final Iterator result = new IteratorImpl(rs, st, session, queryParameters.isReadOnly(session), queryReturnTypes, queryTranslator.getColumnNames(), buildHolderInstantiator(queryParameters.getResultTransformer()));
        if (stats) {
            final long endTime = System.nanoTime();
            final long milliseconds = TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS);
            session.getFactory().getStatistics().queryExecuted(//						"HQL: " + queryTranslator.getQueryString(),
            getQueryIdentifier(), 0, milliseconds);
        }
        return result;
    } catch (SQLException sqle) {
        throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not execute query using iterate", getSQLString());
    }
}
Also used : QueryException(org.hibernate.QueryException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) IteratorImpl(org.hibernate.internal.IteratorImpl)

Example 2 with IteratorImpl

use of org.hibernate.internal.IteratorImpl in project hibernate-orm by hibernate.

the class QueryTranslatorImpl method iterate.

/**
	 * Return the query results as an iterator
	 */
@Override
public Iterator iterate(QueryParameters queryParameters, EventSource session) throws HibernateException {
    boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
    long startTime = 0;
    if (stats) {
        startTime = System.nanoTime();
    }
    try {
        final List<AfterLoadAction> afterLoadActions = new ArrayList<AfterLoadAction>();
        final SqlStatementWrapper wrapper = executeQueryStatement(queryParameters, false, afterLoadActions, session);
        final ResultSet rs = wrapper.getResultSet();
        final PreparedStatement st = (PreparedStatement) wrapper.getStatement();
        HolderInstantiator hi = HolderInstantiator.createClassicHolderInstantiator(holderConstructor, queryParameters.getResultTransformer());
        Iterator result = new IteratorImpl(rs, st, session, queryParameters.isReadOnly(session), returnTypes, getColumnNames(), hi);
        if (stats) {
            final long endTime = System.nanoTime();
            final long milliseconds = TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS);
            session.getFactory().getStatistics().queryExecuted("HQL: " + queryString, 0, milliseconds);
        }
        return result;
    } catch (SQLException sqle) {
        throw getFactory().getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not execute query using iterate", getSQLString());
    }
}
Also used : HolderInstantiator(org.hibernate.hql.internal.HolderInstantiator) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) AfterLoadAction(org.hibernate.loader.spi.AfterLoadAction) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) IteratorImpl(org.hibernate.internal.IteratorImpl)

Aggregations

PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 IteratorImpl (org.hibernate.internal.IteratorImpl)2 ArrayList (java.util.ArrayList)1 QueryException (org.hibernate.QueryException)1 HolderInstantiator (org.hibernate.hql.internal.HolderInstantiator)1 AfterLoadAction (org.hibernate.loader.spi.AfterLoadAction)1