HHH-17720 - Add common JAXB contracts for named queries

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2024-07-25 00:34:19 +02:00 committed by Steve Ebersole
parent b7bac9464a
commit 02096bd1a5
11 changed files with 58 additions and 28 deletions

View File

@ -142,7 +142,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToManyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToOneImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToOneImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyColumnImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNaturalIdImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNaturalIdImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToManyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToManyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToOneImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToOneImpl;
@ -927,8 +927,8 @@ public class HbmXmlTransformer {
} }
} }
private static JaxbNamedQueryImpl transformNamedQuery(JaxbHbmNamedQueryType hbmQuery, String name) { private static JaxbNamedHqlQueryImpl transformNamedQuery(JaxbHbmNamedQueryType hbmQuery, String name) {
final JaxbNamedQueryImpl query = new JaxbNamedQueryImpl(); final JaxbNamedHqlQueryImpl query = new JaxbNamedHqlQueryImpl();
query.setName( name ); query.setName( name );
query.setCacheable( hbmQuery.isCacheable() ); query.setCacheable( hbmQuery.isCacheable() );
query.setCacheMode( hbmQuery.getCacheMode() ); query.setCacheMode( hbmQuery.getCacheMode() );

View File

@ -96,7 +96,7 @@ public interface JaxbEntity extends JaxbEntityOrMappedSuperclass {
@Nullable JaxbGenericIdGeneratorImpl getGenericGenerator(); @Nullable JaxbGenericIdGeneratorImpl getGenericGenerator();
List<JaxbNamedQueryImpl> getNamedQueries(); List<JaxbNamedHqlQueryImpl> getNamedQueries();
List<JaxbNamedNativeQueryImpl> getNamedNativeQueries(); List<JaxbNamedNativeQueryImpl> getNamedNativeQueries();
List<JaxbNamedStoredProcedureQueryImpl> getNamedStoredProcedureQueries(); List<JaxbNamedStoredProcedureQueryImpl> getNamedStoredProcedureQueries();
List<JaxbSqlResultSetMappingImpl> getSqlResultSetMappings(); List<JaxbSqlResultSetMappingImpl> getSqlResultSetMappings();

View File

@ -0,0 +1,28 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.boot.jaxb.mapping.spi;
import java.util.List;
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
/**
* @author Jan Schatteman
*/
public interface JaxbNamedQuery extends JaxbQueryHintContainer {
String getQuery();
String getComment();
Integer getTimeout();
Boolean isCacheable();
String getCacheRegion();
Integer getFetchSize();
Boolean isReadOnly();
List<JaxbQueryParamTypeImpl> getQueryParam();
CacheMode getCacheMode();
FlushMode getFlushMode();
}

View File

@ -11,7 +11,8 @@ import java.util.List;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface JaxbNamedQueryBase { public interface JaxbQueryHintContainer {
String getName(); String getName();
String getDescription();
List<? extends JaxbQueryHint> getHints(); List<? extends JaxbQueryHint> getHints();
} }

View File

@ -11,7 +11,7 @@ import java.lang.annotation.Annotation;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.FlushModeType;
import org.hibernate.annotations.NamedQuery; import org.hibernate.annotations.NamedQuery;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.SourceModelBuildingContext;
@ -209,7 +209,7 @@ public class NamedQueryAnnotation implements NamedQuery {
} }
public void apply(JaxbNamedQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { public void apply(JaxbNamedHqlQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) {
name( jaxbNamedQuery.getName() ); name( jaxbNamedQuery.getName() );
query( jaxbNamedQuery.getQuery() ); query( jaxbNamedQuery.getQuery() );

View File

@ -8,7 +8,7 @@ package org.hibernate.boot.models.annotations.internal;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.xml.internal.QueryProcessing; import org.hibernate.boot.models.xml.internal.QueryProcessing;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
@ -117,7 +117,7 @@ public class NamedQueryJpaAnnotation implements NamedQuery {
} }
public void apply(JaxbNamedQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { public void apply(JaxbNamedHqlQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) {
name( jaxbNamedQuery.getName() ); name( jaxbNamedQuery.getName() );
query( jaxbNamedQuery.getQuery() ); query( jaxbNamedQuery.getQuery() );
lockMode( coalesce( jaxbNamedQuery.getLockMode(), jakarta.persistence.LockModeType.NONE ) ); lockMode( coalesce( jaxbNamedQuery.getLockMode(), jakarta.persistence.LockModeType.NONE ) );

View File

@ -32,8 +32,8 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbGenericIdGeneratorImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryBase; import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHintContainer;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint; import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint;
import org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGeneratorImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGeneratorImpl;
@ -965,7 +965,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
} ); } );
} }
private void collectNamedQueries(List<JaxbNamedQueryImpl> jaxbNamedQueries, XmlDocumentContext xmlDocumentContext) { private void collectNamedQueries(List<JaxbNamedHqlQueryImpl> jaxbNamedQueries, XmlDocumentContext xmlDocumentContext) {
if ( isEmpty( jaxbNamedQueries ) ) { if ( isEmpty( jaxbNamedQueries ) ) {
return; return;
} }
@ -974,7 +974,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
namedQueryRegistrations = new HashMap<>(); namedQueryRegistrations = new HashMap<>();
} }
for ( JaxbNamedQueryImpl jaxbNamedQuery : jaxbNamedQueries ) { for ( JaxbNamedHqlQueryImpl jaxbNamedQuery : jaxbNamedQueries ) {
final NamedQueryJpaAnnotation queryAnnotation = JpaAnnotations.NAMED_QUERY.createUsage( xmlDocumentContext.getModelBuildingContext() ); final NamedQueryJpaAnnotation queryAnnotation = JpaAnnotations.NAMED_QUERY.createUsage( xmlDocumentContext.getModelBuildingContext() );
namedQueryRegistrations.put( namedQueryRegistrations.put(
jaxbNamedQuery.getName(), jaxbNamedQuery.getName(),
@ -995,7 +995,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
} }
} }
private QueryHint[] collectQueryHints(JaxbNamedQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { private QueryHint[] collectQueryHints(JaxbNamedHqlQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) {
final List<QueryHint> hints = extractQueryHints( jaxbNamedQuery ); final List<QueryHint> hints = extractQueryHints( jaxbNamedQuery );
if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) { if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) {
@ -1183,7 +1183,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
} }
} }
private List<QueryHint> extractQueryHints(JaxbNamedQueryBase jaxbQuery) { private List<QueryHint> extractQueryHints(JaxbQueryHintContainer jaxbQuery) {
final List<QueryHint> hints = new ArrayList<>(); final List<QueryHint> hints = new ArrayList<>();
for ( JaxbQueryHint jaxbHint : jaxbQuery.getHints() ) { for ( JaxbQueryHint jaxbHint : jaxbQuery.getHints() ) {
final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext );

View File

@ -20,7 +20,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResultImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbFieldResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbFieldResultImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint; import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint;
import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHintImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHintImpl;
@ -80,7 +80,7 @@ public class QueryProcessing {
List<NamedQueryJpaAnnotation> namedJpqlQueryList = null; List<NamedQueryJpaAnnotation> namedJpqlQueryList = null;
for ( int i = 0; i < jaxbEntity.getNamedQueries().size(); i++ ) { for ( int i = 0; i < jaxbEntity.getNamedQueries().size(); i++ ) {
final JaxbNamedQueryImpl jaxbNamedQuery = jaxbEntity.getNamedQueries().get( i ); final JaxbNamedHqlQueryImpl jaxbNamedQuery = jaxbEntity.getNamedQueries().get( i );
if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getHints() ) ) { if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getHints() ) ) {
// treat this as a Jakarta Persistence named-query // treat this as a Jakarta Persistence named-query

View File

@ -25,7 +25,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl;
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
@ -52,7 +52,7 @@ public class XmlDocumentImpl implements XmlDocument {
private final List<JaxbCompositeUserTypeRegistrationImpl> compositeUserTypeRegistrations; private final List<JaxbCompositeUserTypeRegistrationImpl> compositeUserTypeRegistrations;
private final List<JaxbCollectionUserTypeRegistrationImpl> collectionUserTypeRegistrations; private final List<JaxbCollectionUserTypeRegistrationImpl> collectionUserTypeRegistrations;
private final List<JaxbEmbeddableInstantiatorRegistrationImpl> embeddableInstantiatorRegistrations; private final List<JaxbEmbeddableInstantiatorRegistrationImpl> embeddableInstantiatorRegistrations;
private final Map<String, JaxbNamedQueryImpl> jpaNamedQueries; private final Map<String, JaxbNamedHqlQueryImpl> jpaNamedQueries;
private final Map<String, JaxbNamedNativeQueryImpl> jpaNamedNativeQueries; private final Map<String, JaxbNamedNativeQueryImpl> jpaNamedNativeQueries;
private final Map<String, JaxbHbmNamedQueryType> hibernateNamedQueries; private final Map<String, JaxbHbmNamedQueryType> hibernateNamedQueries;
private final Map<String, JaxbHbmNamedNativeQueryType> hibernateNamedNativeQueries; private final Map<String, JaxbHbmNamedNativeQueryType> hibernateNamedNativeQueries;
@ -71,7 +71,7 @@ public class XmlDocumentImpl implements XmlDocument {
List<JaxbCompositeUserTypeRegistrationImpl> compositeUserTypeRegistrations, List<JaxbCompositeUserTypeRegistrationImpl> compositeUserTypeRegistrations,
List<JaxbCollectionUserTypeRegistrationImpl> collectionUserTypeRegistrations, List<JaxbCollectionUserTypeRegistrationImpl> collectionUserTypeRegistrations,
List<JaxbEmbeddableInstantiatorRegistrationImpl> embeddableInstantiatorRegistrations, List<JaxbEmbeddableInstantiatorRegistrationImpl> embeddableInstantiatorRegistrations,
Map<String, JaxbNamedQueryImpl> jpaNamedQueries, Map<String, JaxbNamedHqlQueryImpl> jpaNamedQueries,
Map<String, JaxbNamedNativeQueryImpl> jpaNamedNativeQueries, Map<String, JaxbNamedNativeQueryImpl> jpaNamedNativeQueries,
Map<String, JaxbNamedStoredProcedureQueryImpl> namedStoredProcedureQueries, Map<String, JaxbNamedStoredProcedureQueryImpl> namedStoredProcedureQueries,
Map<String, JaxbHbmNamedQueryType> hibernateNamedQueries, Map<String, JaxbHbmNamedQueryType> hibernateNamedQueries,
@ -156,7 +156,7 @@ public class XmlDocumentImpl implements XmlDocument {
} }
@Override @Override
public Map<String, JaxbNamedQueryImpl> getJpaNamedQueries() { public Map<String, JaxbNamedHqlQueryImpl> getJpaNamedQueries() {
return jpaNamedQueries; return jpaNamedQueries;
} }
@ -277,12 +277,12 @@ public class XmlDocumentImpl implements XmlDocument {
); );
} }
private static Map<String, JaxbNamedQueryImpl> toNamedQueryMap(List<JaxbNamedQueryImpl> namedQueries) { private static Map<String, JaxbNamedHqlQueryImpl> toNamedQueryMap(List<JaxbNamedHqlQueryImpl> namedQueries) {
if ( isEmpty( namedQueries ) ) { if ( isEmpty( namedQueries ) ) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
final Map<String, JaxbNamedQueryImpl> map = new HashMap<>(); final Map<String, JaxbNamedHqlQueryImpl> map = new HashMap<>();
namedQueries.forEach( (query) -> map.put( query.getName(), query ) ); namedQueries.forEach( (query) -> map.put( query.getName(), query ) );
return map; return map;
} }

View File

@ -22,7 +22,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJdbcTypeRegistrationImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedHqlQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl;
@ -54,7 +54,7 @@ public interface XmlDocument {
List<JaxbEmbeddableInstantiatorRegistrationImpl> getEmbeddableInstantiatorRegistrations(); List<JaxbEmbeddableInstantiatorRegistrationImpl> getEmbeddableInstantiatorRegistrations();
Map<String, JaxbNamedQueryImpl> getJpaNamedQueries(); Map<String, JaxbNamedHqlQueryImpl> getJpaNamedQueries();
Map<String, JaxbNamedNativeQueryImpl> getJpaNamedNativeQueries(); Map<String, JaxbNamedNativeQueryImpl> getJpaNamedNativeQueries();

View File

@ -598,14 +598,15 @@
</bindings> </bindings>
<bindings node="//xsd:complexType[@name='named-query']"> <bindings node="//xsd:complexType[@name='named-query']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryBase</inheritance:implements> <inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQuery</inheritance:implements>
<bindings node=".//xsd:element[@name='hint']"> <bindings node=".//xsd:element[@name='hint']">
<property name="hints"/> <property name="hints"/>
</bindings> </bindings>
<class name="JaxbNamedHqlQueryImpl"/>
</bindings> </bindings>
<bindings node="//xsd:complexType[@name='named-native-query']"> <bindings node="//xsd:complexType[@name='named-native-query']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryBase</inheritance:implements> <inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQuery</inheritance:implements>
<bindings node=".//xsd:element[@name='synchronize']"> <bindings node=".//xsd:element[@name='synchronize']">
<property name="synchronizations"/> <property name="synchronizations"/>
</bindings> </bindings>
@ -615,7 +616,7 @@
</bindings> </bindings>
<bindings node="//xsd:complexType[@name='named-stored-procedure-query']"> <bindings node="//xsd:complexType[@name='named-stored-procedure-query']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryBase</inheritance:implements> <inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHintContainer</inheritance:implements>
<bindings node=".//xsd:element[@name='hint']"> <bindings node=".//xsd:element[@name='hint']">
<property name="hints"/> <property name="hints"/>
</bindings> </bindings>