Search in sources :

Example 1 with NamedHqlQueryDefinition

use of org.hibernate.boot.query.NamedHqlQueryDefinition in project hibernate-orm by hibernate.

the class QueryBinder method bindQuery.

public static void bindQuery(NamedQuery queryAnn, MetadataBuildingContext context, boolean isDefault) {
    if (queryAnn == null) {
        return;
    }
    if (BinderHelper.isEmptyAnnotationValue(queryAnn.name())) {
        throw new AnnotationException("A named query must have a name when used in class or package level");
    }
    final String queryName = queryAnn.name();
    final String queryString = queryAnn.query();
    if (LOG.isDebugEnabled()) {
        LOG.debugf("Binding named query: %s => %s", queryName, queryString);
    }
    final QueryHintDefinition hints = new QueryHintDefinition(queryName, queryAnn.hints());
    final NamedHqlQueryDefinition queryMapping = new NamedHqlQueryDefinitionImpl.Builder(queryName).setHqlString(queryString).setCacheable(hints.getCacheability()).setCacheMode(hints.getCacheMode()).setCacheRegion(hints.getString(HibernateHints.HINT_CACHE_REGION)).setTimeout(hints.getTimeout()).setFetchSize(hints.getInteger(HibernateHints.HINT_FETCH_SIZE)).setFlushMode(hints.getFlushMode()).setReadOnly(hints.getBoolean(HibernateHints.HINT_READ_ONLY)).setLockOptions(hints.determineLockOptions(queryAnn)).setComment(hints.getString(HibernateHints.HINT_COMMENT)).build();
    if (isDefault) {
        context.getMetadataCollector().addDefaultQuery(queryMapping);
    } else {
        context.getMetadataCollector().addNamedQuery(queryMapping);
    }
}
Also used : NamedHqlQueryDefinition(org.hibernate.boot.query.NamedHqlQueryDefinition) NamedHqlQueryDefinitionImpl(org.hibernate.boot.internal.NamedHqlQueryDefinitionImpl) AnnotationException(org.hibernate.AnnotationException)

Example 2 with NamedHqlQueryDefinition

use of org.hibernate.boot.query.NamedHqlQueryDefinition in project hibernate-orm by hibernate.

the class NamedObjectRepositoryImpl method resolve.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Prepare repository for use
@Override
public NamedQueryMemento resolve(SessionFactoryImplementor sessionFactory, MetadataImplementor bootMetamodel, String registrationName) {
    NamedQueryMemento namedQuery = sqlMementoMap.get(registrationName);
    if (namedQuery != null) {
        return namedQuery;
    }
    namedQuery = sqmMementoMap.get(registrationName);
    if (namedQuery != null) {
        return namedQuery;
    }
    namedQuery = callableMementoMap.get(registrationName);
    if (namedQuery != null) {
        return namedQuery;
    }
    final NamedHqlQueryDefinition namedHqlQueryDefinition = bootMetamodel.getNamedHqlQueryMapping(registrationName);
    if (namedHqlQueryDefinition != null) {
        final NamedSqmQueryMemento resolved = namedHqlQueryDefinition.resolve(sessionFactory);
        sqmMementoMap.put(namedHqlQueryDefinition.getRegistrationName(), resolved);
        return resolved;
    }
    final NamedNativeQueryDefinition namedNativeQueryDefinition = bootMetamodel.getNamedNativeQueryMapping(registrationName);
    if (namedNativeQueryDefinition != null) {
        final NamedNativeQueryMemento resolved = namedNativeQueryDefinition.resolve(sessionFactory);
        sqlMementoMap.put(namedNativeQueryDefinition.getRegistrationName(), resolved);
        return resolved;
    }
    final NamedProcedureCallDefinition namedCallableQueryDefinition = bootMetamodel.getNamedProcedureCallMapping(registrationName);
    if (namedCallableQueryDefinition != null) {
        final NamedCallableQueryMemento resolved = namedCallableQueryDefinition.resolve(sessionFactory);
        callableMementoMap.put(namedCallableQueryDefinition.getRegistrationName(), resolved);
        return resolved;
    }
    return null;
}
Also used : NamedSqmQueryMemento(org.hibernate.query.sqm.spi.NamedSqmQueryMemento) NamedHqlQueryDefinition(org.hibernate.boot.query.NamedHqlQueryDefinition) NamedNativeQueryMemento(org.hibernate.query.sql.spi.NamedNativeQueryMemento) NamedCallableQueryMemento(org.hibernate.procedure.spi.NamedCallableQueryMemento) NamedNativeQueryDefinition(org.hibernate.boot.query.NamedNativeQueryDefinition) NamedQueryMemento(org.hibernate.query.named.NamedQueryMemento) NamedProcedureCallDefinition(org.hibernate.boot.query.NamedProcedureCallDefinition)

Aggregations

NamedHqlQueryDefinition (org.hibernate.boot.query.NamedHqlQueryDefinition)2 AnnotationException (org.hibernate.AnnotationException)1 NamedHqlQueryDefinitionImpl (org.hibernate.boot.internal.NamedHqlQueryDefinitionImpl)1 NamedNativeQueryDefinition (org.hibernate.boot.query.NamedNativeQueryDefinition)1 NamedProcedureCallDefinition (org.hibernate.boot.query.NamedProcedureCallDefinition)1 NamedCallableQueryMemento (org.hibernate.procedure.spi.NamedCallableQueryMemento)1 NamedQueryMemento (org.hibernate.query.named.NamedQueryMemento)1 NamedNativeQueryMemento (org.hibernate.query.sql.spi.NamedNativeQueryMemento)1 NamedSqmQueryMemento (org.hibernate.query.sqm.spi.NamedSqmQueryMemento)1