Search in sources :

Example 1 with Parameters

use of org.hibernate.reactive.pool.impl.Parameters in project hibernate-reactive by hibernate.

the class ReactiveImprovedExtractionContextImpl method getQueryResultSet.

private ResultSet getQueryResultSet(String queryString, Object[] positionalParameters, CompletionStage<ReactiveConnection> connectionStage) {
    final Object[] parametersToUse = positionalParameters != null ? positionalParameters : new Object[0];
    final Parameters parametersDialectSpecific = Parameters.instance(getJdbcEnvironment().getDialect());
    final String queryToUse = parametersDialectSpecific.process(queryString, parametersToUse.length);
    return connectionStage.thenCompose(c -> c.selectJdbcOutsideTransaction(queryToUse, parametersToUse)).whenComplete((resultSet, err) -> logSqlException(err, () -> "could not execute query ", queryToUse)).thenApply(ResultSetWorkaround::new).toCompletableFuture().join();
}
Also used : JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) Connection(java.sql.Connection) Time(java.sql.Time) SqlStringGenerationContext(org.hibernate.boot.model.relational.SqlStringGenerationContext) URL(java.net.URL) CompletionStages.logSqlException(org.hibernate.reactive.util.impl.CompletionStages.logSqlException) SQLXML(java.sql.SQLXML) DatabaseMetaData(java.sql.DatabaseMetaData) ImprovedExtractionContextImpl(org.hibernate.tool.schema.internal.exec.ImprovedExtractionContextImpl) ReactiveConnectionPool(org.hibernate.reactive.pool.ReactiveConnectionPool) Array(java.sql.Array) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) DdlTransactionIsolator(org.hibernate.resource.transaction.spi.DdlTransactionIsolator) ResultSet(java.sql.ResultSet) Map(java.util.Map) JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) SQLType(java.sql.SQLType) Struct(java.sql.Struct) NClob(java.sql.NClob) SQLWarning(java.sql.SQLWarning) CompletionStages.voidFuture(org.hibernate.reactive.util.impl.CompletionStages.voidFuture) Clob(java.sql.Clob) Properties(java.util.Properties) Parameters(org.hibernate.reactive.pool.impl.Parameters) Executor(java.util.concurrent.Executor) Timestamp(java.sql.Timestamp) Reader(java.io.Reader) PreparedStatement(java.sql.PreparedStatement) Savepoint(java.sql.Savepoint) ServiceRegistry(org.hibernate.service.ServiceRegistry) Date(java.sql.Date) CompletionStage(java.util.concurrent.CompletionStage) RowId(java.sql.RowId) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Ref(java.sql.Ref) Blob(java.sql.Blob) ResultSetMetaData(java.sql.ResultSetMetaData) InputStream(java.io.InputStream) ReactiveConnection(org.hibernate.reactive.pool.ReactiveConnection) Parameters(org.hibernate.reactive.pool.impl.Parameters)

Example 2 with Parameters

use of org.hibernate.reactive.pool.impl.Parameters in project hibernate-reactive by hibernate.

the class TableReactiveIdentifierGenerator method configure.

@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) {
    JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
    Dialect dialect = jdbcEnvironment.getDialect();
    QualifiedName qualifiedTableName = determineTableName(params, serviceRegistry);
    segmentColumnName = determineSegmentColumnName(params, jdbcEnvironment);
    valueColumnName = determineValueColumnNameForTable(params, jdbcEnvironment);
    segmentValue = determineSegmentValue(params);
    initialValue = determineInitialValue(params);
    increment = determineIncrement(params);
    storeLastUsedValue = determineStoreLastUsedValue(serviceRegistry);
    // allow physical naming strategies a chance to kick in
    renderedTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(qualifiedTableName, dialect);
    Parameters parameters = Parameters.instance(dialect);
    selectQuery = parameters.process(applyLocksToSelect(dialect, "tbl", buildSelectQuery()));
    updateQuery = parameters.process(buildUpdateQuery());
    insertQuery = parameters.process(buildInsertQuery());
}
Also used : Parameters(org.hibernate.reactive.pool.impl.Parameters) QualifiedName(org.hibernate.boot.model.relational.QualifiedName) Dialect(org.hibernate.dialect.Dialect) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 3 with Parameters

use of org.hibernate.reactive.pool.impl.Parameters 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

Parameters (org.hibernate.reactive.pool.impl.Parameters)3 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 CompletionStage (java.util.concurrent.CompletionStage)2 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)2 CompletionStages.logSqlException (org.hibernate.reactive.util.impl.CompletionStages.logSqlException)2 CompletionStages.voidFuture (org.hibernate.reactive.util.impl.CompletionStages.voidFuture)2 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 Serializable (java.io.Serializable)1 BigDecimal (java.math.BigDecimal)1 URL (java.net.URL)1 Array (java.sql.Array)1 Blob (java.sql.Blob)1 CallableStatement (java.sql.CallableStatement)1 Clob (java.sql.Clob)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Date (java.sql.Date)1 NClob (java.sql.NClob)1