HHH-17460 - Ongoing JPA 32 work
This commit is contained in:
parent
e086674878
commit
872b834047
|
@ -162,6 +162,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -176,6 +178,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -193,6 +197,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -208,6 +214,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -220,6 +228,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -232,6 +242,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -250,6 +262,8 @@ public class ManagedTypeProcessor {
|
|||
attributeJavaType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
@ -257,94 +271,120 @@ public class ManagedTypeProcessor {
|
|||
}
|
||||
|
||||
final JaxbAttributesContainer attributes = jaxbManagedType.getAttributes();
|
||||
|
||||
// <basic/>
|
||||
attributes.getBasicAttributes().forEach( (jaxbBasic) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbBasic.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbBasic, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <embedded/>
|
||||
attributes.getEmbeddedAttributes().forEach( (jaxbEmbedded) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbEmbedded.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbEmbedded, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <one-to-one/>
|
||||
attributes.getOneToOneAttributes().forEach( (jaxbOneToOne) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbOneToOne.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbOneToOne, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <many-to-one/>
|
||||
attributes.getManyToOneAttributes().forEach( (jaxbManyToOne) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbManyToOne.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbManyToOne, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <any/>
|
||||
attributes.getAnyMappingAttributes().forEach( (jaxbAnyMapping) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbAnyMapping.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbAnyMapping, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
false,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <element-collection/>
|
||||
attributes.getElementCollectionAttributes().forEach( (jaxbElementCollection) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbElementCollection.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbElementCollection, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
true,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <one-to-many/>
|
||||
attributes.getOneToManyAttributes().forEach( (jaxbOneToMany) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbOneToMany.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbOneToMany, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
true,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <many-to-many/>
|
||||
attributes.getManyToManyAttributes().forEach( (jaxbManyToMany) -> {
|
||||
final DynamicFieldDetails member = new DynamicFieldDetails(
|
||||
jaxbManyToMany.getName(),
|
||||
determineDynamicAttributeJavaType( jaxbManyToMany, xmlDocumentContext ),
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
true,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
} );
|
||||
|
||||
// <many-to-any/>
|
||||
attributes.getPluralAnyMappingAttributes().forEach( (jaxbPluralAnyMapping) -> {
|
||||
final TypeDetails attributeType = determineDynamicAttributeJavaType(
|
||||
jaxbPluralAnyMapping,
|
||||
|
@ -355,6 +395,8 @@ public class ManagedTypeProcessor {
|
|||
attributeType,
|
||||
classDetails,
|
||||
MEMBER_MODIFIERS,
|
||||
false,
|
||||
true,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addField( member );
|
||||
|
|
|
@ -87,9 +87,9 @@ 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.HibernateAnnotations;
|
||||
import org.hibernate.boot.models.categorize.spi.JpaEventListener;
|
||||
import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle;
|
||||
import org.hibernate.boot.models.internal.AnnotationUsageHelper;
|
||||
import org.hibernate.boot.models.xml.internal.db.ColumnProcessing;
|
||||
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
|
||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||
|
@ -153,6 +153,7 @@ import jakarta.persistence.Temporal;
|
|||
import jakarta.persistence.TemporalType;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.hibernate.boot.models.xml.internal.XmlProcessingHelper.makeNestedAnnotation;
|
||||
|
||||
|
@ -1595,80 +1596,95 @@ public class XmlAnnotationHelper {
|
|||
}
|
||||
|
||||
static void applyDiscriminatorColumn(
|
||||
JaxbDiscriminatorColumnImpl discriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl jaxbDiscriminatorColumn,
|
||||
MutableClassDetails target,
|
||||
XmlDocumentContext xmlDocumentContext){
|
||||
if ( discriminatorColumn != null ) {
|
||||
final MutableAnnotationUsage<DiscriminatorColumn> discriminatorColumnAnn = XmlProcessingHelper
|
||||
.getOrMakeAnnotation( DiscriminatorColumn.class, target, xmlDocumentContext );
|
||||
final AnnotationDescriptor<DiscriminatorColumn> discriminatorColumnDescriptor = xmlDocumentContext
|
||||
.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( DiscriminatorColumn.class );
|
||||
applyOr(
|
||||
discriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getName,
|
||||
"name",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
|
||||
applyOr(
|
||||
discriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getDiscriminatorType,
|
||||
"discriminatorType",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
applyOr(
|
||||
discriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getColumnDefinition,
|
||||
"columnDefinition",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
applyOr(
|
||||
discriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getOptions,
|
||||
"options",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
applyOr(
|
||||
discriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getLength,
|
||||
"length",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
|
||||
// todo : add force-selection attribute to @DiscriminatorColumn
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbDiscriminatorColumn == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final MutableAnnotationUsage<DiscriminatorColumn> discriminatorColumnAnn = XmlProcessingHelper
|
||||
.getOrMakeAnnotation( DiscriminatorColumn.class, target, xmlDocumentContext );
|
||||
final AnnotationDescriptor<DiscriminatorColumn> discriminatorColumnDescriptor = xmlDocumentContext
|
||||
.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( DiscriminatorColumn.class );
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified(
|
||||
"name",
|
||||
jaxbDiscriminatorColumn.getName(),
|
||||
discriminatorColumnAnn
|
||||
);
|
||||
AnnotationUsageHelper.applyAttributeIfSpecified(
|
||||
"discriminatorType",
|
||||
jaxbDiscriminatorColumn.getDiscriminatorType(),
|
||||
discriminatorColumnAnn
|
||||
);
|
||||
|
||||
applyOr(
|
||||
jaxbDiscriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getColumnDefinition,
|
||||
"columnDefinition",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
applyOr(
|
||||
jaxbDiscriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getOptions,
|
||||
"options",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
applyOr(
|
||||
jaxbDiscriminatorColumn,
|
||||
JaxbDiscriminatorColumnImpl::getLength,
|
||||
"length",
|
||||
discriminatorColumnAnn,
|
||||
discriminatorColumnDescriptor
|
||||
);
|
||||
|
||||
if ( jaxbDiscriminatorColumn.isForceSelection() || jaxbDiscriminatorColumn.isInsertable() == FALSE ) {
|
||||
final MutableAnnotationUsage<DiscriminatorOptions> optionsAnn = XmlProcessingHelper.getOrMakeAnnotation(
|
||||
DiscriminatorOptions.class,
|
||||
target,
|
||||
xmlDocumentContext
|
||||
);
|
||||
|
||||
optionsAnn.setAttributeValue( "force", true );
|
||||
|
||||
AnnotationUsageHelper.applyAttributeIfSpecified(
|
||||
"insert",
|
||||
jaxbDiscriminatorColumn.isInsertable(),
|
||||
discriminatorColumnAnn
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyDiscriminatorFormula(
|
||||
JaxbDiscriminatorFormulaImpl jaxbDiscriminatorFormula,
|
||||
MutableClassDetails target,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbDiscriminatorFormula == null || StringHelper.isEmpty( jaxbDiscriminatorFormula.getFragment() ) ) {
|
||||
if ( jaxbDiscriminatorFormula == null ) {
|
||||
return;
|
||||
}
|
||||
if ( StringHelper.isEmpty( jaxbDiscriminatorFormula.getFragment() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final MutableAnnotationUsage<DiscriminatorFormula> discriminatorFormulaAnn = HibernateAnnotations.DISCRIMINATOR_FORMULA.createUsage(
|
||||
target,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
final MutableAnnotationUsage<DiscriminatorFormula> discriminatorFormulaAnn = XmlProcessingHelper.getOrMakeAnnotation( DiscriminatorFormula.class, target, xmlDocumentContext );
|
||||
|
||||
discriminatorFormulaAnn.setAttributeValue( "value", jaxbDiscriminatorFormula.getFragment() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "discriminatorType", jaxbDiscriminatorFormula.getDiscriminatorType(), discriminatorFormulaAnn );
|
||||
|
||||
|
||||
|
||||
if ( jaxbDiscriminatorFormula.isForceSelection() ) {
|
||||
final MutableAnnotationUsage<DiscriminatorOptions> existingOptionsAnnotation = (MutableAnnotationUsage<DiscriminatorOptions>) target.getAnnotationUsage( DiscriminatorOptions.class );
|
||||
final MutableAnnotationUsage<DiscriminatorOptions> optionsAnnotation = existingOptionsAnnotation != null
|
||||
? existingOptionsAnnotation
|
||||
: HibernateAnnotations.DISCRIMINATOR_OPTIONS.createUsage( target, xmlDocumentContext.getModelBuildingContext() );
|
||||
optionsAnnotation.setAttributeValue( "force", true );
|
||||
final MutableAnnotationUsage<DiscriminatorOptions> optionsAnn = XmlProcessingHelper.getOrMakeAnnotation(
|
||||
DiscriminatorOptions.class,
|
||||
target,
|
||||
xmlDocumentContext
|
||||
);
|
||||
|
||||
optionsAnn.setAttributeValue( "force", true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.lang.annotation.Annotation;
|
|||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbManagedType;
|
||||
import org.hibernate.boot.models.MemberResolutionException;
|
||||
import org.hibernate.boot.models.internal.AnnotationUsageHelper;
|
||||
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.models.internal.dynamic.DynamicAnnotationUsage;
|
||||
|
@ -152,13 +153,7 @@ public class XmlProcessingHelper {
|
|||
public static <A extends Annotation> MutableAnnotationUsage<A> makeNestedAnnotation(
|
||||
Class<A> annotationType,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
return new DynamicAnnotationUsage<>(
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( annotationType ),
|
||||
null,
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
return makeNestedAnnotation( annotationType, null, xmlDocumentContext );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,8 +173,7 @@ public class XmlProcessingHelper {
|
|||
public static <A extends Annotation> MutableAnnotationUsage<A> makeAnnotation(
|
||||
Class<A> annotationType,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
final MutableAnnotationUsage<A> created = makeNestedAnnotation( annotationType, xmlDocumentContext );
|
||||
return created;
|
||||
return makeNestedAnnotation( annotationType, xmlDocumentContext );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,36 +227,17 @@ public class XmlProcessingHelper {
|
|||
return created;
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void setIf(
|
||||
Object value,
|
||||
String attributeName,
|
||||
MutableAnnotationUsage<A> annotationUsage) {
|
||||
if ( value == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( value instanceof String && ( (String) value ).isBlank() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotationUsage.setAttributeValue( attributeName, value );
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyAttributeIfSpecified(
|
||||
String attributeName,
|
||||
String value,
|
||||
MutableAnnotationUsage<A> annotationUsage) {
|
||||
if ( StringHelper.isNotEmpty( value ) ) {
|
||||
annotationUsage.setAttributeValue( attributeName, value );
|
||||
}
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified( attributeName, value, annotationUsage );
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyAttributeIfSpecified(
|
||||
String attributeName,
|
||||
Object value,
|
||||
MutableAnnotationUsage<A> tableAnn) {
|
||||
if ( value != null ) {
|
||||
tableAnn.setAttributeValue( attributeName, value );
|
||||
}
|
||||
MutableAnnotationUsage<A> annotationUsage) {
|
||||
AnnotationUsageHelper.applyAttributeIfSpecified( attributeName, value, annotationUsage );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -928,7 +928,9 @@
|
|||
}
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="fragment" type="xsd:string"/>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="fragment" type="xsd:string"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="discriminator-type" type="orm:discriminator-type"/>
|
||||
<xsd:attribute name="force-selection" type="xsd:boolean" default="false"/>
|
||||
</xsd:complexType>
|
||||
|
|
|
@ -47,7 +47,7 @@ public class NamedEntityGraphTest {
|
|||
);
|
||||
|
||||
final Set<EntityHierarchy> entityHierarchies = categorizedDomainModel.getEntityHierarchies();
|
||||
assertThat( entityHierarchies ).hasSize( 1 );
|
||||
assertThat( entityHierarchies ).hasSize( 2 );
|
||||
|
||||
entityHierarchies.forEach(
|
||||
entityHierarchy -> {
|
||||
|
|
|
@ -35,7 +35,9 @@
|
|||
</entity>
|
||||
|
||||
<entity class="org.hibernate.orm.test.boot.models.xml.SimpleEntity" metadata-complete="true" access="FIELD">
|
||||
<discriminator-formula>CASE WHEN VALUE1 IS NOT NULL THEN 1 WHEN VALUE2 IS NOT NULL THEN 2 END</discriminator-formula>
|
||||
<discriminator-formula>
|
||||
<fragment>CASE WHEN VALUE1 IS NOT NULL THEN 1 WHEN VALUE2 IS NOT NULL THEN 2 END</fragment>
|
||||
</discriminator-formula>
|
||||
<attributes>
|
||||
<id name="id"/>
|
||||
</attributes>
|
||||
|
|
Loading…
Reference in New Issue