use of org.hibernate.boot.query.NamedProcedureCallDefinition in project hibernate-orm by hibernate.
the class NamedQueryBinder method processNamedNativeQuery.
public static void processNamedNativeQuery(final HbmLocalMetadataBuildingContext context, JaxbHbmNamedNativeQueryType namedQueryBinding, String prefix) {
if (namedQueryBinding.isCallable()) {
DeprecationLogger.DEPRECATION_LOGGER.warn("Marking named native queries as callable is no longer supported; use `@jakarta.persistence.NamedStoredProcedureQuery` instead. Ignoring.");
}
final String registrationName = prefix + namedQueryBinding.getName();
final NamedNativeQueryDefinitionBuilder builder = new NamedNativeQueryDefinitionBuilder(registrationName).setComment(namedQueryBinding.getComment()).setCacheable(namedQueryBinding.isCacheable()).setCacheMode(namedQueryBinding.getCacheMode()).setCacheRegion(namedQueryBinding.getCacheRegion()).setTimeout(namedQueryBinding.getTimeout()).setReadOnly(namedQueryBinding.isReadOnly()).setFlushMode(namedQueryBinding.getFlushMode()).setFetchSize(namedQueryBinding.getFetchSize()).setResultSetMappingName(namedQueryBinding.getResultsetRef());
final ImplicitHbmResultSetMappingDescriptorBuilder implicitResultSetMappingBuilder = new ImplicitHbmResultSetMappingDescriptorBuilder(registrationName, context);
boolean foundQuery = false;
for (Object content : namedQueryBinding.getContent()) {
final boolean wasQuery = processNamedQueryContentItem(content, builder, implicitResultSetMappingBuilder, namedQueryBinding, context);
if (wasQuery) {
foundQuery = true;
}
}
if (!foundQuery) {
throw new org.hibernate.boot.MappingException(String.format("Named native query [%s] did not specify query string", namedQueryBinding.getName()), context.getOrigin());
}
if (implicitResultSetMappingBuilder.hasAnyReturns()) {
if (StringHelper.isNotEmpty(namedQueryBinding.getResultsetRef())) {
throw new org.hibernate.boot.MappingException(String.format("Named native query [%s] specified both a resultset-ref and an inline mapping of results", namedQueryBinding.getName()), context.getOrigin());
}
context.getMetadataCollector().addResultSetMapping(implicitResultSetMappingBuilder.build(context));
builder.setResultSetMappingName(implicitResultSetMappingBuilder.getRegistrationName());
}
if (namedQueryBinding.isCallable()) {
final NamedProcedureCallDefinition definition = QueryBinder.createStoredProcedure(builder, context, () -> illegalCallSyntax(context, namedQueryBinding, builder.getSqlString()));
context.getMetadataCollector().addNamedProcedureCallDefinition(definition);
DeprecationLogger.DEPRECATION_LOGGER.warn("Marking named native queries as callable is deprecated; use `<named-stored-procedure-query/>` instead.");
} else {
context.getMetadataCollector().addNamedNativeQuery(builder.build());
}
}
use of org.hibernate.boot.query.NamedProcedureCallDefinition in project hibernate-orm by hibernate.
the class QueryBinder method bindNativeQuery.
public static void bindNativeQuery(org.hibernate.annotations.NamedNativeQuery queryAnn, MetadataBuildingContext context) {
if (queryAnn == null) {
return;
}
final String registrationName = queryAnn.name();
// ResultSetMappingDefinition mappingDefinition = mappings.getJdbcValuesMappingProducer( queryAnn.resultSetMapping() );
if (BinderHelper.isEmptyAnnotationValue(registrationName)) {
throw new AnnotationException("A named query must have a name when used in class or package level");
}
final String resultSetMappingName = queryAnn.resultSetMapping();
final String resultSetMappingClassName = void.class.equals(queryAnn.resultClass()) ? null : queryAnn.resultClass().getName();
final NamedNativeQueryDefinitionBuilder builder = new NamedNativeQueryDefinitionBuilder(registrationName).setSqlString(queryAnn.query()).setResultSetMappingName(resultSetMappingName).setResultSetMappingClassName(resultSetMappingClassName).setQuerySpaces(null).setCacheable(queryAnn.cacheable()).setCacheRegion(BinderHelper.getAnnotationValueStringOrNull(queryAnn.cacheRegion())).setCacheMode(getCacheMode(queryAnn.cacheMode())).setTimeout(queryAnn.timeout() < 0 ? null : queryAnn.timeout()).setFetchSize(queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize()).setFlushMode(getFlushMode(queryAnn.flushMode())).setReadOnly(queryAnn.readOnly()).setQuerySpaces(CollectionHelper.setOf(queryAnn.querySpaces())).setComment(BinderHelper.getAnnotationValueStringOrNull(queryAnn.comment()));
if (queryAnn.callable()) {
final NamedProcedureCallDefinition definition = createStoredProcedure(builder, context, () -> illegalCallSyntax(queryAnn, queryAnn.query()));
context.getMetadataCollector().addNamedProcedureCallDefinition(definition);
DeprecationLogger.DEPRECATION_LOGGER.warn("Marking named native queries as callable is no longer supported; use `@jakarta.persistence.NamedStoredProcedureQuery` instead. Ignoring.");
} else {
final NamedNativeQueryDefinition queryDefinition = builder.build();
if (LOG.isDebugEnabled()) {
LOG.debugf("Binding named native query: %s => %s", queryDefinition.getRegistrationName(), queryDefinition.getSqlQueryString());
}
context.getMetadataCollector().addNamedNativeQuery(queryDefinition);
}
}
use of org.hibernate.boot.query.NamedProcedureCallDefinition in project hibernate-orm by hibernate.
the class InFlightMetadataCollectorImpl method addNamedProcedureCallDefinition.
@Override
public void addNamedProcedureCallDefinition(NamedProcedureCallDefinition definition) {
if (definition == null) {
throw new IllegalArgumentException("Named query definition is null");
}
final String name = definition.getRegistrationName();
if (defaultNamedProcedureNames.contains(name)) {
return;
}
final NamedProcedureCallDefinition previous = namedProcedureCallMap.put(name, definition);
if (previous != null) {
throw new DuplicateMappingException(DuplicateMappingException.Type.PROCEDURE, name);
}
}
use of org.hibernate.boot.query.NamedProcedureCallDefinition 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