Search in sources :

Example 1 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class QueryEngine method from.

public static QueryEngine from(SessionFactoryImplementor sessionFactory, MetadataImplementor metadata) {
    final QueryEngineOptions queryEngineOptions = sessionFactory.getSessionFactoryOptions();
    final SqmCreationOptions sqmCreationOptions = new SqmCreationOptionsStandard(sessionFactory);
    final Dialect dialect = sessionFactory.getJdbcServices().getDialect();
    final HqlTranslator hqlTranslator = resolveHqlTranslator(queryEngineOptions, dialect, sessionFactory, sqmCreationOptions);
    final SqmTranslatorFactory sqmTranslatorFactory = resolveSqmTranslatorFactory(queryEngineOptions, dialect);
    final SqmFunctionRegistry customSqmFunctionRegistry;
    if (queryEngineOptions.getCustomSqmFunctionRegistry() == null) {
        final Map<String, SqmFunctionDescriptor> customSqlFunctionMap = queryEngineOptions.getCustomSqlFunctionMap();
        if (customSqlFunctionMap == null || customSqlFunctionMap.isEmpty()) {
            customSqmFunctionRegistry = null;
        } else {
            customSqmFunctionRegistry = new SqmFunctionRegistry();
            customSqlFunctionMap.forEach(customSqmFunctionRegistry::register);
        }
    } else {
        customSqmFunctionRegistry = queryEngineOptions.getCustomSqmFunctionRegistry();
    }
    return new QueryEngine(sessionFactory.getUuid(), sessionFactory.getName(), sessionFactory.getSessionFactoryOptions().getJpaCompliance(), () -> sessionFactory.getRuntimeMetamodels().getJpaMetamodel(), sessionFactory.getSessionFactoryOptions().getCriteriaValueHandlingMode(), sessionFactory.getSessionFactoryOptions().getPreferredSqlTypeCodeForBoolean(), metadata.buildNamedQueryRepository(sessionFactory), hqlTranslator, sqmTranslatorFactory, sessionFactory.getServiceRegistry().getService(NativeQueryInterpreter.class), buildInterpretationCache(sessionFactory::getStatistics, sessionFactory.getProperties()), metadata.getTypeConfiguration(), dialect, customSqmFunctionRegistry, sessionFactory.getServiceRegistry());
}
Also used : SqmCreationOptionsStandard(org.hibernate.query.sqm.internal.SqmCreationOptionsStandard) SqmFunctionDescriptor(org.hibernate.query.sqm.function.SqmFunctionDescriptor) NativeQueryInterpreter(org.hibernate.engine.query.spi.NativeQueryInterpreter) SqmCreationOptions(org.hibernate.query.hql.spi.SqmCreationOptions) HqlTranslator(org.hibernate.query.hql.HqlTranslator) StandardHqlTranslator(org.hibernate.query.hql.internal.StandardHqlTranslator) Dialect(org.hibernate.dialect.Dialect) StandardSqmTranslatorFactory(org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory) SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry)

Example 2 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class ConcreteSqmSelectQueryPlan method buildCacheableSqmInterpretation.

private static CacheableSqmInterpretation buildCacheableSqmInterpretation(SqmSelectStatement<?> sqm, DomainParameterXref domainParameterXref, DomainQueryExecutionContext executionContext) {
    final SharedSessionContractImplementor session = executionContext.getSession();
    final SessionFactoryImplementor sessionFactory = session.getFactory();
    final QueryEngine queryEngine = sessionFactory.getQueryEngine();
    final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory();
    final SqmTranslator<SelectStatement> sqmConverter = sqmTranslatorFactory.createSelectTranslator(sqm, executionContext.getQueryOptions(), domainParameterXref, executionContext.getQueryParameterBindings(), executionContext.getSession().getLoadQueryInfluencers(), sessionFactory, true);
    // tableGroupAccess = sqmConverter.getFromClauseAccess();
    final SqmTranslation<SelectStatement> sqmInterpretation = sqmConverter.translate();
    final FromClauseAccess tableGroupAccess = sqmConverter.getFromClauseAccess();
    final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
    final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
    final SqlAstTranslatorFactory sqlAstTranslatorFactory = jdbcEnvironment.getSqlAstTranslatorFactory();
    final SqlAstTranslator<JdbcSelect> selectTranslator = sqlAstTranslatorFactory.buildSelectTranslator(sessionFactory, sqmInterpretation.getSqlAst());
    final Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref = SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam);
    final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(executionContext.getQueryParameterBindings(), domainParameterXref, jdbcParamsXref, session.getFactory().getRuntimeMetamodels().getMappingMetamodel(), tableGroupAccess::findTableGroup, new SqmParameterMappingModelResolutionAccess() {

        @Override
        @SuppressWarnings("unchecked")
        public <T> MappingModelExpressible<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
            return (MappingModelExpressible<T>) sqmInterpretation.getSqmParameterMappingModelTypeResolutions().get(parameter);
        }
    }, session);
    final JdbcSelect jdbcSelect = selectTranslator.translate(jdbcParameterBindings, executionContext.getQueryOptions());
    return new CacheableSqmInterpretation(sqmInterpretation.getSqlAst(), jdbcSelect, tableGroupAccess, jdbcParamsXref, sqmInterpretation.getSqmParameterMappingModelTypeResolutions(), jdbcParameterBindings);
}
Also used : MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) QueryEngine(org.hibernate.query.spi.QueryEngine) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) ArrayList(java.util.ArrayList) List(java.util.List) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory) JdbcSelect(org.hibernate.sql.exec.spi.JdbcSelect) SqmParameterMappingModelResolutionAccess(org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) SqlAstTranslatorFactory(org.hibernate.sql.ast.SqlAstTranslatorFactory) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) QueryParameterImplementor(org.hibernate.query.spi.QueryParameterImplementor) Map(java.util.Map) JdbcParameterBindings(org.hibernate.sql.exec.spi.JdbcParameterBindings)

Example 3 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class SimpleDeleteQueryPlan method createDeleteTranslator.

private SqlAstTranslator<JdbcDelete> createDeleteTranslator(DomainQueryExecutionContext executionContext) {
    final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
    final QueryEngine queryEngine = factory.getQueryEngine();
    final SqmTranslatorFactory translatorFactory = queryEngine.getSqmTranslatorFactory();
    final SqmTranslator<DeleteStatement> translator = translatorFactory.createSimpleDeleteTranslator(sqmDelete, executionContext.getQueryOptions(), domainParameterXref, executionContext.getQueryParameterBindings(), executionContext.getSession().getLoadQueryInfluencers(), factory);
    sqmInterpretation = translator.translate();
    this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam);
    return factory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory().buildDeleteTranslator(factory, sqmInterpretation.getSqlAst());
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) QueryEngine(org.hibernate.query.spi.QueryEngine) SqmDeleteStatement(org.hibernate.query.sqm.tree.delete.SqmDeleteStatement) DeleteStatement(org.hibernate.sql.ast.tree.delete.DeleteStatement) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory)

Example 4 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class SimpleUpdateQueryPlan method createUpdateTranslator.

private SqlAstTranslator<JdbcUpdate> createUpdateTranslator(DomainQueryExecutionContext executionContext) {
    final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
    final QueryEngine queryEngine = factory.getQueryEngine();
    final SqmTranslatorFactory translatorFactory = queryEngine.getSqmTranslatorFactory();
    final SqmTranslator<UpdateStatement> translator = translatorFactory.createSimpleUpdateTranslator(sqmUpdate, executionContext.getQueryOptions(), domainParameterXref, executionContext.getQueryParameterBindings(), executionContext.getSession().getLoadQueryInfluencers(), factory);
    final SqmTranslation<UpdateStatement> sqmInterpretation = translator.translate();
    tableGroupAccess = sqmInterpretation.getFromClauseAccess();
    this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam);
    this.sqmParamMappingTypeResolutions = sqmInterpretation.getSqmParameterMappingModelTypeResolutions();
    return factory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory().buildUpdateTranslator(factory, sqmInterpretation.getSqlAst());
}
Also used : UpdateStatement(org.hibernate.sql.ast.tree.update.UpdateStatement) SqmUpdateStatement(org.hibernate.query.sqm.tree.update.SqmUpdateStatement) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) QueryEngine(org.hibernate.query.spi.QueryEngine) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory)

Example 5 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class SimpleInsertQueryPlan method createInsertTranslator.

private SqlAstTranslator<JdbcInsert> createInsertTranslator(DomainQueryExecutionContext executionContext) {
    final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
    final QueryEngine queryEngine = factory.getQueryEngine();
    final SqmTranslatorFactory translatorFactory = queryEngine.getSqmTranslatorFactory();
    final SqmTranslator<InsertStatement> translator = translatorFactory.createInsertTranslator(sqmInsert, executionContext.getQueryOptions(), domainParameterXref, executionContext.getQueryParameterBindings(), executionContext.getSession().getLoadQueryInfluencers(), factory);
    final SqmTranslation<InsertStatement> sqmInterpretation = translator.translate();
    tableGroupAccess = sqmInterpretation.getFromClauseAccess();
    this.jdbcParamsXref = SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam);
    this.paramTypeResolutions = sqmInterpretation.getSqmParameterMappingModelTypeResolutions();
    return factory.getJdbcServices().getJdbcEnvironment().getSqlAstTranslatorFactory().buildInsertTranslator(factory, sqmInterpretation.getSqlAst());
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) QueryEngine(org.hibernate.query.spi.QueryEngine) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory) SqmInsertStatement(org.hibernate.query.sqm.tree.insert.SqmInsertStatement) InsertStatement(org.hibernate.sql.ast.tree.insert.InsertStatement)

Aggregations

SqmTranslatorFactory (org.hibernate.query.sqm.sql.SqmTranslatorFactory)7 QueryEngine (org.hibernate.query.spi.QueryEngine)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)5 SqmSelectStatement (org.hibernate.query.sqm.tree.select.SqmSelectStatement)3 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)3 HqlTranslator (org.hibernate.query.hql.HqlTranslator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Dialect (org.hibernate.dialect.Dialect)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 NativeQueryInterpreter (org.hibernate.engine.query.spi.NativeQueryInterpreter)1 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)1 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)1 MappingModelExpressible (org.hibernate.metamodel.mapping.MappingModelExpressible)1 StandardHqlTranslator (org.hibernate.query.hql.internal.StandardHqlTranslator)1 SqmCreationOptions (org.hibernate.query.hql.spi.SqmCreationOptions)1 QueryParameterImplementor (org.hibernate.query.spi.QueryParameterImplementor)1 SqmFunctionDescriptor (org.hibernate.query.sqm.function.SqmFunctionDescriptor)1