use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class AbstractLoadPlanBasedEntityLoader method load.
@Override
public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions) {
final Object result;
try {
final QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes(new Type[] { entityPersister.getIdentifierType() });
qp.setPositionalParameterValues(new Object[] { id });
qp.setOptionalObject(optionalObject);
qp.setOptionalEntityName(entityPersister.getEntityName());
qp.setOptionalId(id);
qp.setLockOptions(lockOptions);
final List results = executeLoad(session, qp, staticLoadQuery, false, null);
result = extractEntityResult(results);
} catch (SQLException sqle) {
throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not load an entity: " + MessageHelper.infoString(entityPersister, id, entityPersister.getIdentifierType(), getFactory()), staticLoadQuery.getSqlStatement());
}
log.debugf("Done entity load : %s#%s", getEntityName(), id);
return result;
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class BatchingEntityLoader method buildQueryParameters.
protected QueryParameters buildQueryParameters(Serializable id, Serializable[] ids, Object optionalObject, LockOptions lockOptions) {
Type[] types = new Type[ids.length];
Arrays.fill(types, persister().getIdentifierType());
QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes(types);
qp.setPositionalParameterValues(ids);
qp.setOptionalObject(optionalObject);
qp.setOptionalEntityName(persister().getEntityName());
qp.setOptionalId(id);
qp.setLockOptions(lockOptions);
return qp;
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class BatchingEntityLoader method doBatchLoad.
protected Object doBatchLoad(Serializable id, Loader loaderToUse, SharedSessionContractImplementor session, Serializable[] ids, Object optionalObject, LockOptions lockOptions) {
if (log.isDebugEnabled()) {
log.debugf("Batch loading entity: %s", MessageHelper.infoString(persister, ids, session.getFactory()));
}
QueryParameters qp = buildQueryParameters(id, ids, optionalObject, lockOptions);
try {
final List results = loaderToUse.doQueryAndInitializeNonLazyCollections(session, qp, false);
log.debug("Done entity batch load");
return getObjectFromList(results, id, session);
} catch (SQLException sqle) {
throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not load an entity batch: " + MessageHelper.infoString(persister(), ids, session.getFactory()), loaderToUse.getSQLString());
}
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class Loader method loadEntity.
/**
* Called by subclasses that load entities
*/
protected final List loadEntity(final SharedSessionContractImplementor session, final Object id, final Type identifierType, final Object optionalObject, final String optionalEntityName, final Serializable optionalIdentifier, final EntityPersister persister, LockOptions lockOptions) throws HibernateException {
if (LOG.isDebugEnabled()) {
LOG.debugf("Loading entity: %s", MessageHelper.infoString(persister, id, identifierType, getFactory()));
}
List result;
try {
QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes(new Type[] { identifierType });
qp.setPositionalParameterValues(new Object[] { id });
qp.setOptionalObject(optionalObject);
qp.setOptionalEntityName(optionalEntityName);
qp.setOptionalId(optionalIdentifier);
qp.setLockOptions(lockOptions);
result = doQueryAndInitializeNonLazyCollections(session, qp, false);
} catch (SQLException sqle) {
final Loadable[] persisters = getEntityPersisters();
throw factory.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not load an entity: " + MessageHelper.infoString(persisters[persisters.length - 1], id, identifierType, getFactory()), getSQLString());
}
LOG.debug("Done entity load");
return result;
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class AbstractLoadPlanBasedCollectionInitializer method initialize.
@Override
public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
if (log.isDebugEnabled()) {
log.debugf("Loading collection: %s", MessageHelper.collectionInfoString(collectionPersister, id, getFactory()));
}
final Serializable[] ids = new Serializable[] { id };
try {
final QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes(new Type[] { collectionPersister.getKeyType() });
qp.setPositionalParameterValues(ids);
qp.setCollectionKeys(ids);
qp.setLockOptions(lockOptions);
executeLoad(session, qp, staticLoadQuery, true, null);
} catch (SQLException sqle) {
throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not initialize a collection: " + MessageHelper.collectionInfoString(collectionPersister, id, getFactory()), staticLoadQuery.getSqlStatement());
}
log.debug("Done loading collection");
}
Aggregations