HHH-17504 - Ongoing JPA 32 work HHH-17350 - Work on hibernate-models, XSD and JAXB HHH-16114 - Improve boot metamodel binding HHH-15996 - Develop an abstraction for Annotation in annotation processing HHH-16012 - Develop an abstraction for domain model Class refs HHH-15997 - Support for dynamic models in orm.xml HHH-15698 - Support for entity-name in mapping.xsd
This commit is contained in:
parent
8609e461f5
commit
9d71b1c855
|
@ -219,6 +219,16 @@ public class XmlAnnotationHelper {
|
|||
return createJoinColumnAnnotation( jaxbJoinColumn, memberDetails, JoinColumn.class, xmlDocumentContext );
|
||||
}
|
||||
|
||||
public static MutableAnnotationUsage<JoinColumn> applyJoinColumn(
|
||||
JaxbJoinColumnImpl jaxbJoinColumn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbJoinColumn == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createJoinColumnAnnotation( jaxbJoinColumn, JoinColumn.class, xmlDocumentContext );
|
||||
}
|
||||
|
||||
public static <A extends Annotation> MutableAnnotationUsage<A> createJoinColumnAnnotation(
|
||||
JaxbColumnJoined jaxbJoinColumn,
|
||||
MutableMemberDetails memberDetails,
|
||||
|
@ -245,6 +255,31 @@ public class XmlAnnotationHelper {
|
|||
return joinColumnAnn;
|
||||
}
|
||||
|
||||
public static <A extends Annotation> MutableAnnotationUsage<A> createJoinColumnAnnotation(
|
||||
JaxbColumnJoined jaxbJoinColumn,
|
||||
Class<A> annotationType,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
final MutableAnnotationUsage<A> joinColumnAnn = XmlProcessingHelper.getOrMakeAnnotation( annotationType, xmlDocumentContext );
|
||||
final AnnotationDescriptor<A> joinColumnDescriptor = xmlDocumentContext
|
||||
.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( annotationType );
|
||||
|
||||
ColumnProcessing.applyColumnDetails( jaxbJoinColumn, joinColumnAnn, xmlDocumentContext );
|
||||
|
||||
applyOr( jaxbJoinColumn, JaxbColumnJoined::getReferencedColumnName, "referencedColumnName", joinColumnAnn, joinColumnDescriptor );
|
||||
|
||||
final JaxbForeignKeyImpl jaxbForeignKey = jaxbJoinColumn.getForeignKey();
|
||||
if ( jaxbForeignKey != null ) {
|
||||
joinColumnAnn.setAttributeValue(
|
||||
"foreignKey",
|
||||
createForeignKeyAnnotation( jaxbForeignKey, xmlDocumentContext )
|
||||
);
|
||||
}
|
||||
|
||||
return joinColumnAnn;
|
||||
}
|
||||
|
||||
public static void applyJoinColumns(
|
||||
List<JaxbJoinColumnImpl> jaxbJoinColumns,
|
||||
MutableMemberDetails memberDetails,
|
||||
|
@ -280,6 +315,19 @@ public class XmlAnnotationHelper {
|
|||
return joinColumns;
|
||||
}
|
||||
|
||||
public static List<AnnotationUsage<JoinColumn>> createJoinColumns(
|
||||
List<JaxbJoinColumnImpl> jaxbJoinColumns,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() );
|
||||
jaxbJoinColumns.forEach( jaxbJoinColumn -> {
|
||||
joinColumns.add( applyJoinColumn( jaxbJoinColumn, xmlDocumentContext ) );
|
||||
} );
|
||||
return joinColumns;
|
||||
}
|
||||
|
||||
public static <T,N> void applyOr(
|
||||
N jaxbNode,
|
||||
Function<N,T> jaxbValueAccess,
|
||||
|
@ -429,6 +477,23 @@ public class XmlAnnotationHelper {
|
|||
return foreignKeyAnn;
|
||||
}
|
||||
|
||||
public static MutableAnnotationUsage<ForeignKey> createForeignKeyAnnotation(
|
||||
JaxbForeignKeyImpl jaxbForeignKey,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
final MutableAnnotationUsage<ForeignKey> foreignKeyAnn = XmlProcessingHelper.getOrMakeAnnotation( ForeignKey.class, xmlDocumentContext );
|
||||
final AnnotationDescriptor<ForeignKey> foreignKeyDescriptor = xmlDocumentContext
|
||||
.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( ForeignKey.class );
|
||||
|
||||
applyOr( jaxbForeignKey, JaxbForeignKeyImpl::getName, "name", foreignKeyAnn, foreignKeyDescriptor );
|
||||
applyOr( jaxbForeignKey, JaxbForeignKeyImpl::getConstraintMode, "value", foreignKeyAnn, foreignKeyDescriptor );
|
||||
applyOr( jaxbForeignKey, JaxbForeignKeyImpl::getForeignKeyDefinition, "foreignKeyDefinition", foreignKeyAnn, foreignKeyDescriptor );
|
||||
applyOr( jaxbForeignKey, JaxbForeignKeyImpl::getOptions, "options", foreignKeyAnn, foreignKeyDescriptor );
|
||||
|
||||
return foreignKeyAnn;
|
||||
}
|
||||
|
||||
public static void applyMapKeyColumn(
|
||||
JaxbMapKeyColumnImpl jaxbMapKeyColumn,
|
||||
MutableMemberDetails memberDetails,
|
||||
|
@ -622,6 +687,26 @@ public class XmlAnnotationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyCheckConstraints(
|
||||
JaxbCheckable jaxbCheckable,
|
||||
MutableAnnotationUsage<A> annotationUsage,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( CollectionHelper.isNotEmpty( jaxbCheckable.getCheckConstraints() ) ) {
|
||||
final List<AnnotationUsage<CheckConstraint>> checks = new ArrayList<>( jaxbCheckable.getCheckConstraints().size() );
|
||||
final AnnotationDescriptor<CheckConstraint> checkConstraintDescriptor = xmlDocumentContext.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( CheckConstraint.class );
|
||||
for ( JaxbCheckConstraintImpl jaxbCheck : jaxbCheckable.getCheckConstraints() ) {
|
||||
final MutableAnnotationUsage<CheckConstraint> checkAnn = XmlProcessingHelper.getOrMakeAnnotation( CheckConstraint.class, xmlDocumentContext );
|
||||
applyOr( jaxbCheck, JaxbCheckConstraintImpl::getName, "name", checkAnn, checkConstraintDescriptor );
|
||||
applyOr( jaxbCheck, JaxbCheckConstraintImpl::getConstraint, "constraint", checkAnn, checkConstraintDescriptor );
|
||||
applyOr( jaxbCheck, JaxbCheckConstraintImpl::getOptions, "options", checkAnn, checkConstraintDescriptor );
|
||||
checks.add( checkAnn );
|
||||
}
|
||||
annotationUsage.setAttributeValue( "check", checks );
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyTargetClass(
|
||||
String name,
|
||||
MutableMemberDetails memberDetails,
|
||||
|
|
|
@ -125,6 +125,13 @@ public class XmlProcessingHelper {
|
|||
return makeAnnotation( annotationType, target, xmlDocumentContext );
|
||||
}
|
||||
|
||||
public static <A extends Annotation> MutableAnnotationUsage<A> getOrMakeAnnotation(
|
||||
Class<A> annotationType,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
|
||||
return makeAnnotation( annotationType, xmlDocumentContext );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a nested AnnotationUsage. The usage is created with the given target,
|
||||
* but it is not added to the target's annotations.
|
||||
|
@ -141,6 +148,16 @@ public class XmlProcessingHelper {
|
|||
);
|
||||
}
|
||||
|
||||
public static <A extends Annotation> MutableAnnotationUsage<A> makeNestedAnnotation(
|
||||
Class<A> annotationType,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
return new DynamicAnnotationUsage<>(
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( annotationType )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an AnnotationUsage.
|
||||
* Used when applying XML in complete mode or when {@linkplain #getOrMakeAnnotation}
|
||||
|
@ -155,6 +172,13 @@ public class XmlProcessingHelper {
|
|||
return created;
|
||||
}
|
||||
|
||||
public static <A extends Annotation> MutableAnnotationUsage<A> makeAnnotation(
|
||||
Class<A> annotationType,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
final MutableAnnotationUsage<A> created = makeNestedAnnotation( annotationType, xmlDocumentContext );
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an existing annotation by name, or create one.
|
||||
* Used when applying XML in override mode.
|
||||
|
|
|
@ -48,7 +48,6 @@ public class ElementCollectionAttributeProcessing {
|
|||
xmlDocumentContext
|
||||
);
|
||||
XmlProcessingHelper.setIf( jaxbElementCollection.getFetch(), "fetch", elementCollectionAnn );
|
||||
if ( StringHelper.isNotEmpty( jaxbElementCollection.getTargetClass() ) ) {
|
||||
elementCollectionAnn.setAttributeValue(
|
||||
"targetClass",
|
||||
XmlAnnotationHelper.resolveJavaType(
|
||||
|
@ -56,7 +55,6 @@ public class ElementCollectionAttributeProcessing {
|
|||
xmlDocumentContext.getModelBuildingContext()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
CommonAttributeProcessing.applyAttributeBasics( jaxbElementCollection, memberDetails, elementCollectionAnn, accessType, xmlDocumentContext );
|
||||
|
||||
|
@ -73,11 +71,6 @@ public class ElementCollectionAttributeProcessing {
|
|||
XmlAnnotationHelper.applyTemporal( jaxbElementCollection.getTemporal(), memberDetails, xmlDocumentContext );
|
||||
XmlAnnotationHelper.applyBasicTypeComposition( jaxbElementCollection, memberDetails, xmlDocumentContext );
|
||||
|
||||
if ( StringHelper.isNotEmpty( jaxbElementCollection.getTargetClass() ) ) {
|
||||
final MutableAnnotationUsage<Target> targetAnn = XmlProcessingHelper.getOrMakeAnnotation( Target.class, memberDetails, xmlDocumentContext );
|
||||
targetAnn.setAttributeValue( "value", jaxbElementCollection.getTargetClass() );
|
||||
}
|
||||
|
||||
jaxbElementCollection.getConverts().forEach( (jaxbConvert) -> {
|
||||
XmlAnnotationHelper.applyConvert( jaxbConvert, memberDetails, xmlDocumentContext );
|
||||
} );
|
||||
|
@ -110,12 +103,12 @@ public class ElementCollectionAttributeProcessing {
|
|||
XmlAnnotationHelper.applyOr( jaxbCollectionTable, JaxbCollectionTableImpl::getSchema, "schema", collectionTableAnn, collectionTableDescriptor );
|
||||
XmlAnnotationHelper.applyOr( jaxbCollectionTable, JaxbCollectionTableImpl::getOptions, "options", collectionTableAnn, collectionTableDescriptor );
|
||||
|
||||
collectionTableAnn.setAttributeValue( "joinColumns", XmlAnnotationHelper.createJoinColumns( jaxbCollectionTable.getJoinColumns(), memberDetails, xmlDocumentContext ) );
|
||||
collectionTableAnn.setAttributeValue( "joinColumns", XmlAnnotationHelper.createJoinColumns( jaxbCollectionTable.getJoinColumns(), xmlDocumentContext ) );
|
||||
|
||||
if ( jaxbCollectionTable.getForeignKeys() != null ) {
|
||||
collectionTableAnn.setAttributeValue(
|
||||
"foreignKey",
|
||||
XmlAnnotationHelper.createForeignKeyAnnotation( jaxbCollectionTable.getForeignKeys(), memberDetails, xmlDocumentContext )
|
||||
XmlAnnotationHelper.createForeignKeyAnnotation( jaxbCollectionTable.getForeignKeys(), xmlDocumentContext )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,37 +38,57 @@ public class ColumnProcessing {
|
|||
return;
|
||||
}
|
||||
|
||||
applyColumnBasics( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnNullness( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnMutability( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnDefinition( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnUniqueness( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnComment( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnNullness( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnMutability( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnSizable sizable ) {
|
||||
applyColumnSizing( sizable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnSizing( sizable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyColumnDetails(
|
||||
JaxbColumnStandard jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
JaxbColumnCommon jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
applyColumnBasics( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnNullness( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnMutability( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnDefinition( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnSizing( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnUniqueness( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnComment( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnNullness( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnMutability( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnSizable sizable ) {
|
||||
applyColumnSizing( sizable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyColumnDetails(
|
||||
JaxbColumnStandard jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnNullness( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnMutability( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnSizing( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyColumnDetails(
|
||||
|
@ -80,30 +100,30 @@ public class ColumnProcessing {
|
|||
return;
|
||||
}
|
||||
|
||||
applyColumnBasics( jaxbColumn, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext );
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnNullable nullable ) {
|
||||
applyColumnNullness( nullable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnNullness( nullable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnMutable mutable ) {
|
||||
applyColumnMutability( mutable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnMutability( mutable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnDefinable definable ) {
|
||||
applyColumnDefinition( definable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnDefinition( definable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnSizable sizable ) {
|
||||
applyColumnSizing( sizable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnSizing( sizable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
if ( jaxbColumn instanceof JaxbColumnUniqueable uniqueable ) {
|
||||
applyColumnUniqueness( uniqueable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnUniqueness( uniqueable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
if ( jaxbColumn instanceof JaxbCommentable commentable ) {
|
||||
applyColumnComment( commentable, target, columnAnn, xmlDocumentContext );
|
||||
applyColumnComment( commentable, columnAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
if ( jaxbColumn instanceof JaxbCheckable checkable ) {
|
||||
|
@ -113,7 +133,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnBasics(
|
||||
JaxbColumn jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) {
|
||||
|
@ -127,7 +146,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnNullness(
|
||||
JaxbColumnNullable jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn.isNullable() != null ) {
|
||||
|
@ -137,7 +155,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnMutability(
|
||||
JaxbColumnMutable jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn.isInsertable() != null ) {
|
||||
|
@ -151,7 +168,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnSizing(
|
||||
JaxbColumnSizable jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
|
||||
|
@ -170,7 +186,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnUniqueness(
|
||||
JaxbColumnUniqueable jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn.isUnique() != null ) {
|
||||
|
@ -180,7 +195,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnDefinition(
|
||||
JaxbColumnDefinable jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) {
|
||||
|
@ -194,7 +208,6 @@ public class ColumnProcessing {
|
|||
|
||||
private static <A extends Annotation> void applyColumnComment(
|
||||
JaxbCommentable jaxbColumn,
|
||||
MutableAnnotationTarget target,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getComment() ) ) {
|
||||
|
|
Loading…
Reference in New Issue