Search in sources :

Example 1 with HolderInstantiator

use of org.hibernate.hql.internal.HolderInstantiator 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)

Example 2 with HolderInstantiator

use of org.hibernate.hql.internal.HolderInstantiator in project hibernate-orm by hibernate.

the class CustomLoader method getResultList.

@Override
@SuppressWarnings("unchecked")
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException {
    // meant to handle dynamic instantiation queries...(Copy from QueryLoader)
    HolderInstantiator holderInstantiator = HolderInstantiator.getHolderInstantiator(null, resultTransformer, getReturnAliasesForTransformer());
    if (holderInstantiator.isRequired()) {
        for (int i = 0; i < results.size(); i++) {
            Object[] row = (Object[]) results.get(i);
            Object result = holderInstantiator.instantiate(row);
            results.set(i, result);
        }
        return resultTransformer.transformList(results);
    } else {
        return results;
    }
}
Also used : HolderInstantiator(org.hibernate.hql.internal.HolderInstantiator)

Example 3 with HolderInstantiator

use of org.hibernate.hql.internal.HolderInstantiator in project hibernate-orm by hibernate.

the class QueryLoader method getResultList.

@SuppressWarnings("unchecked")
@Override
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException {
    // meant to handle dynamic instantiation queries...
    HolderInstantiator holderInstantiator = buildHolderInstantiator(resultTransformer);
    if (holderInstantiator.isRequired()) {
        for (int i = 0; i < results.size(); i++) {
            Object[] row = (Object[]) results.get(i);
            Object result = holderInstantiator.instantiate(row);
            results.set(i, result);
        }
        if (!hasSelectNew() && resultTransformer != null) {
            return resultTransformer.transformList(results);
        } else {
            return results;
        }
    } else {
        return results;
    }
}
Also used : HolderInstantiator(org.hibernate.hql.internal.HolderInstantiator)

Aggregations

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