Search in sources :

Example 6 with QueryParameters

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;
}
Also used : SQLException(java.sql.SQLException) List(java.util.List) QueryParameters(org.hibernate.engine.spi.QueryParameters)

Example 7 with QueryParameters

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;
}
Also used : Type(org.hibernate.type.Type) QueryParameters(org.hibernate.engine.spi.QueryParameters)

Example 8 with QueryParameters

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());
    }
}
Also used : SQLException(java.sql.SQLException) List(java.util.List) QueryParameters(org.hibernate.engine.spi.QueryParameters)

Example 9 with QueryParameters

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;
}
Also used : SQLException(java.sql.SQLException) List(java.util.List) ArrayList(java.util.ArrayList) QueryParameters(org.hibernate.engine.spi.QueryParameters)

Example 10 with QueryParameters

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");
}
Also used : Serializable(java.io.Serializable) SQLException(java.sql.SQLException) QueryParameters(org.hibernate.engine.spi.QueryParameters)

Aggregations

QueryParameters (org.hibernate.engine.spi.QueryParameters)35 List (java.util.List)20 ArrayList (java.util.ArrayList)17 SQLException (java.sql.SQLException)14 PreparedStatement (java.sql.PreparedStatement)10 Session (org.hibernate.Session)10 Type (org.hibernate.type.Type)10 Test (org.junit.Test)9 EntityPersister (org.hibernate.persister.entity.EntityPersister)8 Connection (java.sql.Connection)7 ResultSet (java.sql.ResultSet)7 Work (org.hibernate.jdbc.Work)7 ResultSetProcessor (org.hibernate.loader.plan.exec.process.spi.ResultSetProcessor)7 NamedParameterContext (org.hibernate.loader.plan.exec.query.spi.NamedParameterContext)7 LoadQueryDetails (org.hibernate.loader.plan.exec.spi.LoadQueryDetails)7 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)7 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)6 AssociationType (org.hibernate.type.AssociationType)5 Serializable (java.io.Serializable)4 EntityType (org.hibernate.type.EntityType)4