Search in sources :

Example 6 with NamedObjectRepository

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);
}
Also used : NamedSqmQueryMemento(org.hibernate.query.sqm.spi.NamedSqmQueryMemento) NamedObjectRepository(org.hibernate.query.named.NamedObjectRepository) NamedNativeQueryMemento(org.hibernate.query.sql.spi.NamedNativeQueryMemento) UnknownNamedQueryException(org.hibernate.query.UnknownNamedQueryException)

Aggregations

NamedObjectRepository (org.hibernate.query.named.NamedObjectRepository)6 NamedSqmQueryMemento (org.hibernate.query.sqm.spi.NamedSqmQueryMemento)3 Test (org.junit.jupiter.api.Test)3 NamedResultSetMappingMemento (org.hibernate.query.named.NamedResultSetMappingMemento)2 PersistenceException (jakarta.persistence.PersistenceException)1 UnknownNamedQueryException (org.hibernate.query.UnknownNamedQueryException)1 UnknownSqlResultSetMappingException (org.hibernate.query.UnknownSqlResultSetMappingException)1 SqmQueryImplementor (org.hibernate.query.hql.spi.SqmQueryImplementor)1 ResultSetMappingResolutionContext (org.hibernate.query.internal.ResultSetMappingResolutionContext)1 NamedQueryMemento (org.hibernate.query.named.NamedQueryMemento)1 ResultBuilderBasicValued (org.hibernate.query.results.ResultBuilderBasicValued)1 ResultSetMapping (org.hibernate.query.results.ResultSetMapping)1 ResultSetMappingImpl (org.hibernate.query.results.ResultSetMappingImpl)1 QueryEngine (org.hibernate.query.spi.QueryEngine)1 NamedNativeQueryMemento (org.hibernate.query.sql.spi.NamedNativeQueryMemento)1 NativeQueryImplementor (org.hibernate.query.sql.spi.NativeQueryImplementor)1