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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations