HHH-17460 - Ongoing JPA 32 work

This commit is contained in:
Steve Ebersole 2024-03-21 14:04:41 -05:00
parent 42ab732328
commit c891d1ab5c
6 changed files with 58 additions and 23 deletions

View File

@ -6,9 +6,11 @@
*/
package org.hibernate.boot.jaxb.mapping.spi.db;
import java.util.List;
import org.hibernate.boot.jaxb.mapping.spi.JaxbIndexImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbSchemaAware;
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCheckable;
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbDatabaseObject;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUniqueConstraintImpl;
/**
* @author Steve Ebersole
@ -16,4 +18,7 @@ import org.hibernate.boot.jaxb.mapping.spi.db.JaxbDatabaseObject;
public interface JaxbTableMapping extends JaxbSchemaAware, JaxbCheckable, JaxbDatabaseObject {
String getComment();
String getOptions();
List<JaxbIndexImpl> getIndexes();
List<JaxbUniqueConstraintImpl> getUniqueConstraints();
}

View File

@ -123,6 +123,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.IdClass;
import jakarta.persistence.Index;
import jakarta.persistence.Inheritance;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
@ -444,8 +445,21 @@ public class EntityBinder {
TableBinder.addIndexes( appliedTable, usage.getList( "indexes" ), context );
} );
annotatedClass.forEachAnnotationUsage( jakarta.persistence.Table.class, (usage) -> {
TableBinder.addJpaIndexes( persistentClass.getTable(), usage.getList( "indexes" ), context );
final AnnotationUsage<jakarta.persistence.Table> jpaTableUsage = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class );
if ( jpaTableUsage != null ) {
TableBinder.addJpaIndexes( persistentClass.getTable(), jpaTableUsage.getList( "indexes" ), context );
}
final InFlightMetadataCollector.EntityTableXref entityTableXref = context
.getMetadataCollector()
.getEntityTableXref( persistentClass.getEntityName() );
annotatedClass.forEachAnnotationUsage( jakarta.persistence.SecondaryTable.class, (usage) -> {
final Identifier secondaryTableLogicalName = toIdentifier( usage.getString( "name" ) );
final Table table = entityTableXref.resolveTable( secondaryTableLogicalName );
assert table != null;
TableBinder.addJpaIndexes( table, usage.getList( "indexes" ), context );
} );
}

View File

@ -979,8 +979,8 @@ public class JPAXMLOverriddenAnnotationReader implements AnnotationReader {
&& isEmpty( (String) annotation.valueOf( "schema" ) ) ) {
annotation.setValue( "schema", defaults.getSchema() );
}
buildUniqueConstraints( annotation, subelement.getUniqueConstraint() );
buildIndex( annotation, subelement.getIndex() );
buildUniqueConstraints( annotation, subelement.getUniqueConstraints() );
buildIndex( annotation, subelement.getIndexes() );
annotation.setValue( "joinColumns", getJoinColumns( subelement.getJoinColumn(), false ) );
annotation.setValue( "inverseJoinColumns", getJoinColumns( subelement.getInverseJoinColumn(), true ) );
return AnnotationFactory.create( annotation );
@ -2772,7 +2772,7 @@ public class JPAXMLOverriddenAnnotationReader implements AnnotationReader {
copyAttribute( ad, "pk-column-value", element.getPkColumnValue(), false );
copyAttribute( ad, "initial-value", element.getInitialValue(), false );
copyAttribute( ad, "allocation-size", element.getAllocationSize(), false );
buildUniqueConstraints( ad, element.getUniqueConstraint() );
buildUniqueConstraints( ad, element.getUniqueConstraints() );
if ( isEmpty( (String) ad.valueOf( "schema" ) )
&& isNotEmpty( defaults.getSchema() ) ) {
ad.setValue( "schema", defaults.getSchema() );
@ -3055,8 +3055,8 @@ public class JPAXMLOverriddenAnnotationReader implements AnnotationReader {
&& isEmpty( (String) annotation.valueOf( "schema" ) ) ) {
annotation.setValue( "schema", defaults.getSchema() );
}
buildUniqueConstraints( annotation, element.getUniqueConstraint() );
buildIndex( annotation, element.getIndex() );
buildUniqueConstraints( annotation, element.getUniqueConstraints() );
buildIndex( annotation, element.getIndexes() );
return AnnotationFactory.create( annotation );
}
}

View File

@ -723,8 +723,8 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
applyStringAttributeIfSpecified( "pkColumnValue", generator.getPkColumnValue(), annotationUsage );
applyAttributeIfSpecified( "initialValue", generator.getInitialValue(), annotationUsage );
applyAttributeIfSpecified( "allocationSize", generator.getAllocationSize(), annotationUsage );
applyAttributeIfSpecified( "uniqueConstraints", generator.getUniqueConstraint(), annotationUsage );
applyAttributeIfSpecified( "indexes", generator.getIndex(), annotationUsage );
applyAttributeIfSpecified( "uniqueConstraints", generator.getUniqueConstraints(), annotationUsage );
applyAttributeIfSpecified( "indexes", generator.getIndexes(), annotationUsage );
applyStringAttributeIfSpecified( "options", generator.getOptions(), annotationUsage );
collectTableGenerator( new TableGeneratorRegistration( generator.getName(), annotationUsage ) );

View File

@ -88,6 +88,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbUuidGeneratorImpl;
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCheckable;
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnJoined;
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbTableMapping;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.categorize.spi.JpaEventListener;
import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle;
import org.hibernate.boot.models.internal.AnnotationUsageHelper;
@ -616,15 +617,14 @@ public class XmlAnnotationHelper {
}
final List<AnnotationUsage<Index>> indexes = new ArrayList<>( jaxbIndexes.size() );
final AnnotationDescriptor<Index> indexDescriptor = xmlDocumentContext.getModelBuildingContext()
.getAnnotationDescriptorRegistry()
.getDescriptor( Index.class );
jaxbIndexes.forEach( jaxbIndex -> {
final MutableAnnotationUsage<Index> indexAnn = XmlProcessingHelper.getOrMakeAnnotation(
Index.class,
final MutableAnnotationUsage<Index> indexAnn = indexDescriptor.createUsage(
target,
xmlDocumentContext
xmlDocumentContext.getModelBuildingContext()
);
final AnnotationDescriptor<Index> indexDescriptor = xmlDocumentContext.getModelBuildingContext()
.getAnnotationDescriptorRegistry()
.getDescriptor( Index.class );
applyOr( jaxbIndex, JaxbIndexImpl::getName, "name", indexAnn, indexDescriptor );
applyOr( jaxbIndex, JaxbIndexImpl::getColumnList, "columnList", indexAnn, indexDescriptor );
applyOr( jaxbIndex, JaxbIndexImpl::isUnique, "unique", indexAnn, indexDescriptor );
@ -677,10 +677,6 @@ public class XmlAnnotationHelper {
);
}
applyUniqueConstraints( jaxbJoinTable.getUniqueConstraint(), memberDetails, joinTableAnn, xmlDocumentContext );
applyIndexes( jaxbJoinTable.getIndex(), memberDetails, joinTableAnn, xmlDocumentContext );
return joinTableAnn;
}
@ -836,8 +832,8 @@ public class XmlAnnotationHelper {
XmlProcessingHelper.applyAttributeIfSpecified( "pkColumnValue", jaxbGenerator.getPkColumnValue(), annotationUsage );
XmlProcessingHelper.applyAttributeIfSpecified( "initialValue", jaxbGenerator.getInitialValue(), annotationUsage );
XmlProcessingHelper.applyAttributeIfSpecified( "allocationSize", jaxbGenerator.getInitialValue(), annotationUsage );
applyUniqueConstraints( jaxbGenerator.getUniqueConstraint(), memberDetails, annotationUsage, xmlDocumentContext );
applyIndexes( jaxbGenerator.getIndex(), memberDetails, annotationUsage, xmlDocumentContext );
applyUniqueConstraints( jaxbGenerator.getUniqueConstraints(), memberDetails, annotationUsage, xmlDocumentContext );
applyIndexes( jaxbGenerator.getIndexes(), memberDetails, annotationUsage, xmlDocumentContext );
}
public static void applyUuidGenerator(
@ -1042,6 +1038,8 @@ public class XmlAnnotationHelper {
applyOr( jaxbTable, JaxbTableMapping::getOptions, "options", tableAnn, annotationDescriptor );
applyOr( jaxbTable, JaxbTableMapping::getComment, "comment", tableAnn, annotationDescriptor );
applyCheckConstraints( jaxbTable, target, tableAnn, xmlDocumentContext );
applyUniqueConstraints( jaxbTable.getUniqueConstraints(), target, tableAnn, xmlDocumentContext );
applyIndexes( jaxbTable.getIndexes(), target, tableAnn, xmlDocumentContext );
}
public static void applyNaturalId(

View File

@ -412,6 +412,12 @@
<bindings node="//xsd:complexType[@name='table']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.db.JaxbTableMapping</inheritance:implements>
<bindings node=".//xsd:element[@name='unique-constraint']">
<property name="uniqueConstraints"/>
</bindings>
<bindings node=".//xsd:element[@name='index']">
<property name="indexes"/>
</bindings>
</bindings>
<bindings node="//xsd:complexType[@name='check-constraint']">
@ -484,6 +490,12 @@
<bindings node="//xsd:complexType[@name='join-table']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.db.JaxbTableMapping</inheritance:implements>
<bindings node=".//xsd:element[@name='unique-constraint']">
<property name="uniqueConstraints"/>
</bindings>
<bindings node=".//xsd:element[@name='index']">
<property name="indexes"/>
</bindings>
</bindings>
<bindings node="//xsd:complexType[@name='collection-table']">
@ -503,6 +515,12 @@
</bindings>
<bindings node="//xsd:complexType[@name='table-generator']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.db.JaxbTableMapping</inheritance:implements>
<bindings node=".//xsd:element[@name='unique-constraint']">
<property name="uniqueConstraints"/>
</bindings>
<bindings node=".//xsd:element[@name='index']">
<property name="indexes"/>
</bindings>
</bindings>
<bindings node="//xsd:complexType[@name='sequence-generator']">
<inheritance:implements>org.hibernate.boot.jaxb.mapping.spi.JaxbSchemaAware</inheritance:implements>