use of org.hibernate.query.spi.QueryEngine in project hibernate-orm by hibernate.
the class OrderingExpression method applyCollation.
static Expression applyCollation(Expression expression, String collation, SqlAstCreationState creationState) {
final Expression sortExpression;
if (collation == null) {
sortExpression = expression;
} else {
final QueryEngine queryEngine = creationState.getCreationContext().getSessionFactory().getQueryEngine();
final SqmToSqlAstConverter converter;
if (creationState instanceof SqmToSqlAstConverter) {
converter = (SqmToSqlAstConverter) creationState;
} else {
converter = new FakeSqmToSqlAstConverter(creationState);
}
sortExpression = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("collate").generateSqmExpression(new SqmSelfRenderingExpression<>(walker -> expression, null, null), null, queryEngine, queryEngine.getTypeConfiguration()).convertToSqlAst(converter);
}
return sortExpression;
}
use of org.hibernate.query.spi.QueryEngine in project hibernate-orm by hibernate.
the class InformixDialectTestCase method init.
@BeforeClass
public static void init() {
final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl(new TypeConfiguration(), new JpaComplianceStub());
ssr = new StandardServiceRegistryBuilder().build();
queryEngine = new QueryEngine(null, null, jpaMetamodel, ValueHandlingMode.BIND, dialect.getPreferredSqlTypeCodeForBoolean(), false, new NamedObjectRepositoryImpl(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()), null, dialect, ssr);
}
use of org.hibernate.query.spi.QueryEngine in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method createQuery.
@Override
public <T> QueryImplementor<T> createQuery(String queryString, Class<T> resultClass) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();
try {
final QueryEngine queryEngine = getFactory().getQueryEngine();
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
final QuerySqmImpl<T> query = new QuerySqmImpl<>(queryString, interpretationCache.resolveHqlInterpretation(queryString, s -> queryEngine.getHqlTranslator().translate(queryString)), resultClass, this);
applyQuerySettingsAndHints(query);
query.setComment(queryString);
return query;
} catch (RuntimeException e) {
markForRollbackOnly();
throw getExceptionConverter().convert(e);
}
}
use of org.hibernate.query.spi.QueryEngine 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.spi.QueryEngine 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());
}
Aggregations