use of org.hibernate.query.spi.QueryInterpretationCache in project hibernate-orm by hibernate.
the class NamedObjectRepositoryImpl method checkNamedQueries.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Named query checking
public Map<String, HibernateException> checkNamedQueries(QueryEngine queryEngine) {
Map<String, HibernateException> errors = new HashMap<>();
final HqlTranslator sqmProducer = queryEngine.getHqlTranslator();
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
final boolean cachingEnabled = interpretationCache.isEnabled();
// Check named HQL queries
log.debugf("Checking %s named HQL queries", sqmMementoMap.size());
for (NamedSqmQueryMemento hqlMemento : sqmMementoMap.values()) {
try {
log.debugf("Checking named HQL query: %s", hqlMemento.getRegistrationName());
String queryString = hqlMemento.getHqlString();
interpretationCache.resolveHqlInterpretation(queryString, s -> queryEngine.getHqlTranslator().translate(queryString));
} catch (HibernateException e) {
errors.put(hqlMemento.getRegistrationName(), e);
}
}
// Check native-sql queries
log.debugf("Checking %s named SQL queries", sqlMementoMap.size());
for (NamedNativeQueryMemento memento : sqlMementoMap.values()) {
memento.validate(queryEngine);
// // this will throw an error if there's something wrong.
// try {
// log.debugf( "Checking named SQL query: %s", memento.getRegistrationName() );
// // TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
// // currently not doable though because of the resultset-ref stuff...
// NativeSQLQuerySpecification spec;
// if ( memento.getResultSetMappingName() != null ) {
// NamedResultSetMappingMemento resultSetMappingMemento = getResultSetMappingMemento( memento.getResultSetMappingName() );
// if ( resultSetMappingMemento == null ) {
// throw new MappingException( "Unable to find resultset-ref resultSetMappingMemento: " + memento.getResultSetMappingName() );
// }
// spec = new NativeSQLQuerySpecification(
// namedSQLQueryDefinition.getQueryString(),
// resultSetMappingMemento.getQueryReturns(),
// namedSQLQueryDefinition.getQuerySpaces()
// );
// }
// else {
// spec = new NativeSQLQuerySpecification(
// namedSQLQueryDefinition.getQueryString(),
// namedSQLQueryDefinition.getQueryReturns(),
// namedSQLQueryDefinition.getQuerySpaces()
// );
// }
// queryEngine.getNativeSQLQueryPlan( spec );
// }
// catch ( HibernateException e ) {
// errors.put( namedSQLQueryDefinition.getName(), e );
// }
}
return errors;
}
use of org.hibernate.query.spi.QueryInterpretationCache 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.QueryInterpretationCache in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method createSelectionQuery.
@Override
public SelectionQuery<?> createSelectionQuery(String hqlString) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();
try {
final QueryEngine queryEngine = getFactory().getQueryEngine();
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
final HqlInterpretation hqlInterpretation = interpretationCache.resolveHqlInterpretation(hqlString, s -> queryEngine.getHqlTranslator().translate(hqlString));
if (!(hqlInterpretation.getSqmStatement() instanceof SqmSelectStatement)) {
throw new IllegalSelectQueryException("Expecting a selection query, but found `" + hqlString + "`", hqlString);
}
final SqmSelectionQuery<?> query = new SqmSelectionQueryImpl<>(hqlString, hqlInterpretation, this);
query.setComment(hqlString);
applyQuerySettingsAndHints(query);
return query;
} catch (RuntimeException e) {
markForRollbackOnly();
throw e;
}
}
use of org.hibernate.query.spi.QueryInterpretationCache in project hibernate-orm by hibernate.
the class NativeQueryImpl method resolveParameterInterpretation.
private ParameterInterpretation resolveParameterInterpretation(String sqlString, SharedSessionContractImplementor session) {
final SessionFactoryImplementor sessionFactory = session.getFactory();
final QueryEngine queryEngine = sessionFactory.getQueryEngine();
final QueryInterpretationCache interpretationCache = queryEngine.getInterpretationCache();
return interpretationCache.resolveNativeQueryParameters(sqlString, s -> {
final ParameterRecognizerImpl parameterRecognizer = new ParameterRecognizerImpl();
session.getFactory().getServiceRegistry().getService(NativeQueryInterpreter.class).recognizeParameters(sqlString, parameterRecognizer);
return new ParameterInterpretationImpl(parameterRecognizer);
});
}
Aggregations