HHH-18000 : Remove XmlProcessingHelper methods for creating AnnotationUsage instances

This commit is contained in:
Steve Ebersole 2024-04-23 20:45:20 -05:00
parent 62178086a6
commit f3624c712e
7 changed files with 32 additions and 88 deletions

View File

@ -117,7 +117,6 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.IdClass;
import jakarta.persistence.Index;
import jakarta.persistence.Inheritance;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.persistence.TableGenerator;
@ -149,40 +148,6 @@ public class XmlAnnotationHelper {
}
}
public static <S> void applyOptionalAttribute(
MutableAnnotationUsage<? extends Annotation> annotationUsage,
String attributeName,
S valueSource,
Function<S,Object> valueExtractor) {
if ( valueSource == null ) {
return;
}
final Object value = valueExtractor.apply( valueSource );
if ( value == null ) {
return;
}
annotationUsage.setAttributeValue( attributeName, value );
}
public static <S> void applyOptionalStringAttribute(
MutableAnnotationUsage<? extends Annotation> annotationUsage,
String attributeName,
S valueSource,
Function<S,String> valueExtractor) {
if ( valueSource == null ) {
return;
}
final String value = valueExtractor.apply( valueSource );
if ( StringHelper.isEmpty( value ) ) {
return;
}
annotationUsage.setAttributeValue( attributeName, value );
}
/**
* Handle creating {@linkplain Entity @Entity} from an {@code <entity/>} element.
* Used in both complete and override modes.
@ -223,16 +188,6 @@ public class XmlAnnotationHelper {
return columnAnnotationUsage;
}
public static MutableAnnotationUsage<JoinColumn> applyJoinColumn(
JaxbJoinColumnImpl jaxbJoinColumn,
MutableMemberDetails memberDetails,
XmlDocumentContext xmlDocumentContext) {
if ( jaxbJoinColumn == null ) {
return null;
}
return JoinColumnProcessing.createJoinColumnAnnotation( jaxbJoinColumn, memberDetails, JoinColumn.class, xmlDocumentContext );
}
public static <T,N> void applyOr(
N jaxbNode,
@ -267,6 +222,12 @@ public class XmlAnnotationHelper {
);
}
public static void applyUserType(
JaxbUserTypeImpl jaxbType,
MutableMemberDetails memberDetails,

View File

@ -15,6 +15,7 @@ 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.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.FieldDetails;
import org.hibernate.models.spi.MethodDetails;
@ -115,11 +116,11 @@ public class XmlProcessingHelper {
* Used when applying XML in override mode.
*/
public static <A extends Annotation> MutableAnnotationUsage<A> getOrMakeNamedAnnotation(
Class<A> annotationType,
AnnotationDescriptor<A> annotationDescriptor,
String name,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
return getOrMakeNamedAnnotation( annotationType, name, "name", target, xmlDocumentContext );
return getOrMakeNamedAnnotation( annotationDescriptor, name, "name", target, xmlDocumentContext );
}
/**
@ -127,43 +128,30 @@ public class XmlProcessingHelper {
* Used when applying XML in override mode.
*/
public static <A extends Annotation> MutableAnnotationUsage<A> getOrMakeNamedAnnotation(
Class<A> annotationType,
AnnotationDescriptor<A> annotationDescriptor,
String name,
String attributeToMatch,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
if ( name == null ) {
return xmlDocumentContext
.getModelBuildingContext()
.getAnnotationDescriptorRegistry()
.getDescriptor( annotationType )
.createUsage( null, xmlDocumentContext.getModelBuildingContext() );
return annotationDescriptor.createUsage( null, xmlDocumentContext.getModelBuildingContext() );
}
final AnnotationUsage<A> existing = target.getNamedAnnotationUsage( annotationType, name, attributeToMatch );
final AnnotationUsage<A> existing = target.getNamedAnnotationUsage( annotationDescriptor, name, attributeToMatch );
if ( existing != null ) {
return (MutableAnnotationUsage<A>) existing;
}
return makeNamedAnnotation( annotationType, name, attributeToMatch, target, xmlDocumentContext );
return makeNamedAnnotation( annotationDescriptor, name, attributeToMatch, target, xmlDocumentContext );
}
/**
* Make a named AnnotationUsage.
* Used when applying XML in complete mode or when {@linkplain #getOrMakeNamedAnnotation}
* needs to make.
*/
public static <A extends Annotation> MutableAnnotationUsage<A> makeNamedAnnotation(
Class<A> annotationType,
private static <A extends Annotation> MutableAnnotationUsage<A> makeNamedAnnotation(
AnnotationDescriptor<A> annotationDescriptor,
String name,
String nameAttributeName,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<A> created = xmlDocumentContext
.getModelBuildingContext()
.getAnnotationDescriptorRegistry()
.getDescriptor( annotationType )
.createUsage( null, xmlDocumentContext.getModelBuildingContext() );
final MutableAnnotationUsage<A> created = annotationDescriptor.createUsage( null, xmlDocumentContext.getModelBuildingContext() );
target.addAnnotationUsage( created );
created.setAttributeValue( nameAttributeName, name );
return created;

View File

@ -14,6 +14,7 @@ import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing;
import org.hibernate.boot.models.xml.internal.db.TableProcessing;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.StringHelper;
@ -73,9 +74,7 @@ public class OneToManyAttributeProcessing {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// other properties
jaxbOneToMany.getJoinColumn().forEach( jaxbJoinColumn -> {
XmlAnnotationHelper.applyJoinColumn( jaxbJoinColumn, memberDetails, xmlDocumentContext );
} );
JoinColumnProcessing.applyJoinColumns( jaxbOneToMany.getJoinColumn(), memberDetails, xmlDocumentContext );
if ( jaxbOneToMany.getOnDelete() != null ) {
final MutableAnnotationUsage<OnDelete> onDeleteAnn = memberDetails.applyAnnotationUsage(

View File

@ -21,6 +21,7 @@ import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.MutableAnnotationUsage;
@ -164,10 +165,10 @@ public class JoinColumnProcessing {
public static <A extends Annotation> MutableAnnotationUsage<A> createJoinColumnAnnotation(
JaxbColumnJoined jaxbJoinColumn,
MutableMemberDetails memberDetails,
Class<A> annotationType,
AnnotationDescriptor<A> annotationDescriptor,
XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<A> joinColumnAnn = XmlProcessingHelper.getOrMakeNamedAnnotation(
annotationType,
annotationDescriptor,
jaxbJoinColumn.getName(),
memberDetails,
xmlDocumentContext
@ -208,15 +209,10 @@ public class JoinColumnProcessing {
return;
}
if ( jaxbJoinColumns.size() == 1 ) {
XmlAnnotationHelper.applyJoinColumn( jaxbJoinColumns.get( 0 ), memberDetails, xmlDocumentContext );
}
else {
final MutableAnnotationUsage<JoinColumns> columnsAnn = memberDetails.applyAnnotationUsage(
JpaAnnotations.JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext()
);
columnsAnn.setAttributeValue( "value", createJoinColumns( jaxbJoinColumns, memberDetails, xmlDocumentContext ) );
}
final MutableAnnotationUsage<JoinColumns> columnsAnn = memberDetails.applyAnnotationUsage(
JpaAnnotations.JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext()
);
columnsAnn.setAttributeValue( "value", createJoinColumns( jaxbJoinColumns, memberDetails, xmlDocumentContext ) );
}
}

View File

@ -22,12 +22,12 @@ public class CompositeKeyDeleteTest extends BaseCoreFunctionalTestCase {
@Override
protected String getBaseForMappings() {
return "org/hibernate/orm/test/";
return "";
}
@Override
public String[] getMappings() {
return new String[] { "annotations/derivedidentities/e1/b/specjmapid/lazy/order_orm.xml" };
return new String[] { "org/hibernate/orm/test/annotations/derivedidentities/e1/b/specjmapid/lazy/order_orm.xml" };
}
public CompositeKeyDeleteTest() {

View File

@ -60,8 +60,8 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase {
final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm2.xml" );
assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse();

View File

@ -119,8 +119,8 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase {
public void testSingleJoinColumn() {
final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm4.xml" );
assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse();