use of org.hibernate.query.named.NamedObjectRepository in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method buildNamedQuery.
@SuppressWarnings("rawtypes")
protected QueryImplementor buildNamedQuery(String queryName, Function<NamedSqmQueryMemento, SqmQueryImplementor> namedSqmHandler, Function<NamedNativeQueryMemento, NativeQueryImplementor> namedNativeHandler) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();
// this method can be called for either a named HQL query or a named native query
// first see if it is a named HQL query
final NamedObjectRepository namedObjectRepository = getFactory().getQueryEngine().getNamedObjectRepository();
final NamedSqmQueryMemento namedSqmQueryMemento = namedObjectRepository.getSqmQueryMemento(queryName);
if (namedSqmQueryMemento != null) {
return namedSqmHandler.apply(namedSqmQueryMemento);
}
// otherwise, see if it is a named native query
final NamedNativeQueryMemento namedNativeDescriptor = namedObjectRepository.getNativeQueryMemento(queryName);
if (namedNativeDescriptor != null) {
return namedNativeHandler.apply(namedNativeDescriptor);
}
throw new UnknownNamedQueryException(queryName);
}
Aggregations