use of org.hibernate.loader.spi.AfterLoadAction 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());
}
}
use of org.hibernate.loader.spi.AfterLoadAction in project hibernate-orm by hibernate.
the class CustomLoader method applyLocks.
@Override
protected String applyLocks(String sql, QueryParameters parameters, Dialect dialect, List<AfterLoadAction> afterLoadActions) throws QueryException {
final LockOptions lockOptions = parameters.getLockOptions();
if (lockOptions == null || (lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0)) {
return sql;
}
// user is request locking, lets see if we can apply locking directly to the SQL...
// some dialects wont allow locking with paging...
afterLoadActions.add(new AfterLoadAction() {
private final LockOptions originalLockOptions = lockOptions.makeCopy();
@Override
public void afterLoad(SharedSessionContractImplementor session, Object entity, Loadable persister) {
((Session) session).buildLockRequest(originalLockOptions).lock(persister.getEntityName(), entity);
}
});
parameters.getLockOptions().setLockMode(LockMode.READ);
return sql;
}
Aggregations