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);
}
}
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;
}
Aggregations