Search in sources :

Example 1 with ReactiveLoader

use of org.hibernate.reactive.loader.ReactiveLoader in project hibernate-reactive by hibernate.

the class ReactivePlanEntityLoader method load.

@Override
public CompletionStage<Object> load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions, Boolean readOnly) {
    final QueryParameters parameters = buildQueryParameters(id, optionalObject, lockOptions, readOnly);
    // Filters get applied just before the query is executed. The parameter processor is not smart enough
    // to count deal with the additional parameters in a second pass and we have to wait until the query
    // is complete before processing it. See: ReactiveLoader#executeReactiveQueryStatement
    String sql = hasFilters(session) ? getStaticLoadQuery().getSqlStatement() : processedSQL;
    return doReactiveQueryAndInitializeNonLazyCollections(sql, session, parameters).thenApply(results -> extractEntityResult(results, id)).handle((list, err) -> {
        logSqlException(err, () -> "could not load an entity: " + infoString(persister, id, persister.getIdentifierType(), getFactory()), sql);
        return returnOrRethrow(err, list);
    });
}
Also used : PostLoadEvent(org.hibernate.event.spi.PostLoadEvent) CompletionStages.logSqlException(org.hibernate.reactive.util.impl.CompletionStages.logSqlException) EventSource(org.hibernate.event.spi.EventSource) EntityLoadQueryDetails(org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails) PreLoadEvent(org.hibernate.event.spi.PreLoadEvent) ReactiveResultSetProcessor(org.hibernate.reactive.loader.ReactiveResultSetProcessor) SQLException(java.sql.SQLException) HydratedEntityRegistration(org.hibernate.loader.plan.exec.process.internal.HydratedEntityRegistration) ReactiveUniqueEntityLoader(org.hibernate.reactive.loader.entity.ReactiveUniqueEntityLoader) ResultSet(java.sql.ResultSet) ReactiveLoader(org.hibernate.reactive.loader.ReactiveLoader) CompletionStages.voidFuture(org.hibernate.reactive.util.impl.CompletionStages.voidFuture) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ResultSetProcessorImpl(org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl) AbstractRowReader(org.hibernate.loader.plan.exec.process.internal.AbstractRowReader) QueryParameters(org.hibernate.engine.spi.QueryParameters) LockMode(org.hibernate.LockMode) LockOptions(org.hibernate.LockOptions) Parameters(org.hibernate.reactive.pool.impl.Parameters) AliasResolutionContext(org.hibernate.loader.plan.exec.spi.AliasResolutionContext) QueryBuildingParameters(org.hibernate.loader.plan.exec.query.spi.QueryBuildingParameters) ResultSetProcessingContextImpl(org.hibernate.loader.plan.exec.process.internal.ResultSetProcessingContextImpl) CompletionStages.returnOrRethrow(org.hibernate.reactive.util.impl.CompletionStages.returnOrRethrow) NamedParameterContext(org.hibernate.loader.plan.exec.query.spi.NamedParameterContext) AbstractLoadPlanBasedEntityLoader(org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader) Serializable(java.io.Serializable) AfterLoadAction(org.hibernate.loader.spi.AfterLoadAction) LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) MessageHelper.infoString(org.hibernate.pretty.MessageHelper.infoString) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) OuterJoinLoadable(org.hibernate.persister.entity.OuterJoinLoadable) MappingException(org.hibernate.MappingException) ReaderCollector(org.hibernate.loader.plan.exec.process.spi.ReaderCollector) QueryBuildingParametersImpl(org.hibernate.loader.plan.exec.query.internal.QueryBuildingParametersImpl) ResultTransformer(org.hibernate.transform.ResultTransformer) Type(org.hibernate.type.Type) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) CompletionStages(org.hibernate.reactive.util.impl.CompletionStages) QueryParameters(org.hibernate.engine.spi.QueryParameters) MessageHelper.infoString(org.hibernate.pretty.MessageHelper.infoString)

Aggregations

Serializable (java.io.Serializable)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 CompletionStage (java.util.concurrent.CompletionStage)1 LockMode (org.hibernate.LockMode)1 LockOptions (org.hibernate.LockOptions)1 MappingException (org.hibernate.MappingException)1 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)1 QueryParameters (org.hibernate.engine.spi.QueryParameters)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)1 EventSource (org.hibernate.event.spi.EventSource)1 PostLoadEvent (org.hibernate.event.spi.PostLoadEvent)1 PreLoadEvent (org.hibernate.event.spi.PreLoadEvent)1 AbstractLoadPlanBasedEntityLoader (org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader)1 EntityLoadQueryDetails (org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails)1 AbstractRowReader (org.hibernate.loader.plan.exec.process.internal.AbstractRowReader)1 HydratedEntityRegistration (org.hibernate.loader.plan.exec.process.internal.HydratedEntityRegistration)1 ResultSetProcessingContextImpl (org.hibernate.loader.plan.exec.process.internal.ResultSetProcessingContextImpl)1