HHH-17504 Fixed IllegalArgumentException caused by setting AnnotationUsage attributes values to null (#219)
HHH-17504 - Ongoing JPA 32 work
This commit is contained in:
parent
0a86254c2f
commit
9df49675ee
|
@ -27,6 +27,7 @@ import jakarta.persistence.TableGenerator;
|
|||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.hibernate.boot.models.JpaAnnotations.TABLE_GENERATOR;
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified;
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
|
||||
|
||||
/**
|
||||
|
@ -161,7 +162,7 @@ public class IdentifierGeneratorDefinition implements Serializable {
|
|||
null,
|
||||
null
|
||||
);
|
||||
sequenceGeneratorUsage.setAttributeValue( "name", name );
|
||||
applyStringAttributeIfSpecified( "name", name, sequenceGeneratorUsage );
|
||||
GenerationStrategyInterpreter.STRATEGY_INTERPRETER.interpretSequenceGenerator( sequenceGeneratorUsage, builder );
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.hibernate.boot.model.naming.Identifier;
|
|||
import org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource;
|
||||
import org.hibernate.boot.model.source.spi.AttributePath;
|
||||
import org.hibernate.boot.models.JpaAnnotations;
|
||||
import org.hibernate.boot.models.internal.AnnotationUsageHelper;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -490,18 +491,27 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
|
|||
final String columnName = timeZoneColumn != null
|
||||
? timeZoneColumn.getString( "name" )
|
||||
: column.getString( "name" ) + "_tz";
|
||||
created.setAttributeValue( "name", columnName );
|
||||
created.setAttributeValue( "nullable", column.getBoolean( "nullable" ) );
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", columnName, created );
|
||||
AnnotationUsageHelper.applyAttributeIfSpecified(
|
||||
"nullable",
|
||||
column.getBoolean( "nullable" ),
|
||||
created
|
||||
);
|
||||
|
||||
final AnnotationUsage<?> source = timeZoneColumn != null
|
||||
? timeZoneColumn
|
||||
: column;
|
||||
created.setAttributeValue( "table", source.getAttributeValue( "table" ) );
|
||||
created.setAttributeValue( "insertable", source.getAttributeValue( "insertable" ) );
|
||||
created.setAttributeValue( "updatable", source.getAttributeValue( "updatable" ) );
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified( "table", source.getAttributeValue( "table" ), created );
|
||||
AnnotationUsageHelper.applyAttributeIfSpecified( "insertable", source.getAttributeValue( "insertable" ), created );
|
||||
AnnotationUsageHelper.applyAttributeIfSpecified( "updatable", source.getAttributeValue( "updatable" ), created );
|
||||
|
||||
if ( timeZoneColumn != null ) {
|
||||
created.setAttributeValue( "columnDefinition", timeZoneColumn.getAttributeValue( "columnDefinition" ) );
|
||||
AnnotationUsageHelper
|
||||
.applyStringAttributeIfSpecified(
|
||||
"columnDefinition",
|
||||
timeZoneColumn.getAttributeValue( "columnDefinition" ),
|
||||
created
|
||||
);
|
||||
}
|
||||
},
|
||||
context.getMetadataCollector().getSourceModelBuildingContext()
|
||||
|
@ -551,7 +561,7 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
|
|||
return JpaAnnotations.COLUMN.createUsage(
|
||||
element,
|
||||
(created) -> {
|
||||
created.setAttributeValue( "name", implicitName.getText() );
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", implicitName.getText(), created );
|
||||
created.setAttributeValue( "precision", precision );
|
||||
},
|
||||
context.getMetadataCollector().getSourceModelBuildingContext()
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.hibernate.models.spi.AnnotationDescriptor;
|
|||
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
|
||||
import org.hibernate.models.spi.AnnotationUsage;
|
||||
import org.hibernate.models.spi.MemberDetails;
|
||||
import org.hibernate.models.spi.MutableAnnotationUsage;
|
||||
import org.hibernate.models.spi.SourceModelBuildingContext;
|
||||
|
||||
import jakarta.persistence.CheckConstraint;
|
||||
|
@ -48,6 +47,7 @@ import static org.hibernate.boot.model.internal.AnnotatedColumn.buildFormulaFrom
|
|||
import static org.hibernate.boot.model.internal.BinderHelper.getOverridableAnnotation;
|
||||
import static org.hibernate.boot.model.internal.BinderHelper.getPath;
|
||||
import static org.hibernate.boot.model.internal.BinderHelper.getPropertyOverriddenByMapperOrMapsId;
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified;
|
||||
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
||||
|
||||
/**
|
||||
|
@ -320,24 +320,36 @@ class ColumnsBuilder {
|
|||
return joinColumnDescriptor.createUsage(
|
||||
property,
|
||||
(usage) -> {
|
||||
transferAttribute( "name", pkJoinColumnAnn, usage );
|
||||
transferAttribute( "referencedColumnName", pkJoinColumnAnn, usage );
|
||||
transferAttribute( "columnDefinition", pkJoinColumnAnn, usage );
|
||||
transferAttribute( "options", pkJoinColumnAnn, usage );
|
||||
transferAttribute( "foreignKey", pkJoinColumnAnn, usage );
|
||||
applyAttributeIfSpecified(
|
||||
"name",
|
||||
pkJoinColumnAnn.getAttributeValue( "name" ),
|
||||
usage
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"referencedColumnName",
|
||||
pkJoinColumnAnn.getAttributeValue( "referencedColumnName" ),
|
||||
usage
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"columnDefinition",
|
||||
pkJoinColumnAnn.getAttributeValue( "columnDefinition" ),
|
||||
usage
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"options",
|
||||
pkJoinColumnAnn.getAttributeValue( "options" ),
|
||||
usage
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"foreignKey",
|
||||
pkJoinColumnAnn.getAttributeValue( "foreignKey" ),
|
||||
usage
|
||||
);
|
||||
},
|
||||
hibernateModelsContext
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private void transferAttribute(
|
||||
String attributeName,
|
||||
AnnotationUsage source,
|
||||
MutableAnnotationUsage target) {
|
||||
target.setAttributeValue( attributeName, source.getAttributeValue( attributeName ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful to override a column either by {@code @MapsId} or by {@code @IdClass}
|
||||
*/
|
||||
|
|
|
@ -159,6 +159,7 @@ import static org.hibernate.boot.model.internal.PropertyBinder.processElementAnn
|
|||
import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder;
|
||||
import static org.hibernate.boot.model.internal.TableBinder.bindForeignKey;
|
||||
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified;
|
||||
import static org.hibernate.engine.OptimisticLockStyle.fromLockType;
|
||||
import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle;
|
||||
import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier;
|
||||
|
@ -1770,8 +1771,12 @@ public class EntityBinder {
|
|||
classDetails,
|
||||
context.getMetadataCollector().getSourceModelBuildingContext()
|
||||
);
|
||||
cacheUsage.setAttributeValue( "region", classDetails.getName() );
|
||||
cacheUsage.setAttributeValue( "usage", determineCacheConcurrencyStrategy( context ) );
|
||||
applyAttributeIfSpecified( "region", classDetails.getName(), cacheUsage );
|
||||
applyAttributeIfSpecified(
|
||||
"usage",
|
||||
determineCacheConcurrencyStrategy( context ),
|
||||
cacheUsage
|
||||
);
|
||||
return cacheUsage;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@ import jakarta.persistence.ForeignKey;
|
|||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.MapKeyJoinColumn;
|
||||
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified;
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
|
@ -44,16 +48,52 @@ public class MapKeyJoinColumnDelegator implements JoinColumn {
|
|||
context.getMetadataCollector().getSourceModelBuildingContext()
|
||||
);
|
||||
|
||||
joinColumn.setAttributeValue( "name", mapKeyJoinColumn.getAttributeValue( "name" ) );
|
||||
joinColumn.setAttributeValue( "table", mapKeyJoinColumn.getAttributeValue( "table" ) );
|
||||
joinColumn.setAttributeValue( "unique", mapKeyJoinColumn.getAttributeValue( "unique" ) );
|
||||
joinColumn.setAttributeValue( "nullable", mapKeyJoinColumn.getAttributeValue( "nullable" ) );
|
||||
joinColumn.setAttributeValue( "insertable", mapKeyJoinColumn.getAttributeValue( "insertable" ) );
|
||||
joinColumn.setAttributeValue( "referencedColumnName", mapKeyJoinColumn.getAttributeValue( "referencedColumnName" ) );
|
||||
joinColumn.setAttributeValue( "columnDefinition", mapKeyJoinColumn.getAttributeValue( "columnDefinition" ) );
|
||||
joinColumn.setAttributeValue( "options", mapKeyJoinColumn.getAttributeValue( "options" ) );
|
||||
applyStringAttributeIfSpecified(
|
||||
"name",
|
||||
mapKeyJoinColumn.getAttributeValue( "name" ),
|
||||
joinColumn
|
||||
);
|
||||
applyStringAttributeIfSpecified(
|
||||
"table",
|
||||
mapKeyJoinColumn.getAttributeValue( "table" ),
|
||||
joinColumn
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"unique",
|
||||
mapKeyJoinColumn.getAttributeValue( "unique" ),
|
||||
joinColumn
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"nullable",
|
||||
mapKeyJoinColumn.getAttributeValue( "nullable" ),
|
||||
joinColumn
|
||||
);
|
||||
applyAttributeIfSpecified(
|
||||
"insertable",
|
||||
mapKeyJoinColumn.getAttributeValue( "insertable" ),
|
||||
joinColumn
|
||||
);
|
||||
applyStringAttributeIfSpecified(
|
||||
"referencedColumnName",
|
||||
mapKeyJoinColumn.getAttributeValue( "referencedColumnName" ),
|
||||
joinColumn
|
||||
);
|
||||
applyStringAttributeIfSpecified(
|
||||
"columnDefinition",
|
||||
mapKeyJoinColumn.getAttributeValue( "columnDefinition" ),
|
||||
joinColumn
|
||||
);
|
||||
applyStringAttributeIfSpecified(
|
||||
"options",
|
||||
mapKeyJoinColumn.getAttributeValue( "options" ),
|
||||
joinColumn
|
||||
);
|
||||
// joinColumn.setAttributeValue( "comment", mapKeyJoinColumn.getAttributeValue( "comment" ) );
|
||||
joinColumn.setAttributeValue( "foreignKey", mapKeyJoinColumn.getAttributeValue( "foreignKey" ) );
|
||||
applyAttributeIfSpecified(
|
||||
"foreignKey",
|
||||
mapKeyJoinColumn.getAttributeValue( "foreignKey" ),
|
||||
joinColumn
|
||||
);
|
||||
|
||||
return joinColumn;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,8 @@ import static org.hibernate.boot.models.HibernateAnnotations.FILTER_DEF;
|
|||
import static org.hibernate.boot.models.HibernateAnnotations.JAVA_TYPE_REG;
|
||||
import static org.hibernate.boot.models.HibernateAnnotations.JDBC_TYPE_REG;
|
||||
import static org.hibernate.boot.models.HibernateAnnotations.TYPE_REG;
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified;
|
||||
import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified;
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
|
||||
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
|
||||
|
||||
|
@ -638,12 +640,13 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
|
||||
sequenceGenerators.forEach( (generator) -> {
|
||||
final MutableAnnotationUsage<SequenceGenerator> annotationUsage = makeAnnotation( JpaAnnotations.SEQUENCE_GENERATOR );
|
||||
annotationUsage.setAttributeValue( "name", generator.getName() );
|
||||
annotationUsage.setAttributeValue( "sequenceName", generator.getSequenceName() );
|
||||
annotationUsage.setAttributeValue( "catalog", generator.getCatalog() );
|
||||
annotationUsage.setAttributeValue( "schema", generator.getSchema() );
|
||||
annotationUsage.setAttributeValue( "initialValue", generator.getInitialValue() );
|
||||
annotationUsage.setAttributeValue( "allocationSize", generator.getAllocationSize() );
|
||||
applyStringAttributeIfSpecified( "name", generator.getName(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "sequenceName", generator.getSequenceName(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "catalog", generator.getCatalog(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "schema", generator.getSchema(), annotationUsage );
|
||||
applyAttributeIfSpecified( "initialValue", generator.getInitialValue(), annotationUsage );
|
||||
applyAttributeIfSpecified( "allocationSize", generator.getAllocationSize(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "options", generator.getOptions(), annotationUsage );
|
||||
|
||||
collectSequenceGenerator( new SequenceGeneratorRegistration( generator.getName(), annotationUsage ) );
|
||||
} );
|
||||
|
@ -676,15 +679,18 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
|
||||
tableGenerators.forEach( (generator) -> {
|
||||
final MutableAnnotationUsage<TableGenerator> annotationUsage = makeAnnotation( JpaAnnotations.TABLE_GENERATOR );
|
||||
annotationUsage.setAttributeValue( "name", generator.getName() );
|
||||
annotationUsage.setAttributeValue( "table", generator.getTable() );
|
||||
annotationUsage.setAttributeValue( "catalog", generator.getCatalog() );
|
||||
annotationUsage.setAttributeValue( "schema", generator.getSchema() );
|
||||
annotationUsage.setAttributeValue( "pkColumnName", generator.getPkColumnName() );
|
||||
annotationUsage.setAttributeValue( "valueColumnName", generator.getValueColumnName() );
|
||||
annotationUsage.setAttributeValue( "pkColumnValue", generator.getPkColumnValue() );
|
||||
annotationUsage.setAttributeValue( "initialValue", generator.getInitialValue() );
|
||||
annotationUsage.setAttributeValue( "allocationSize", generator.getAllocationSize() );
|
||||
applyStringAttributeIfSpecified( "name", generator.getName(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "table", generator.getTable(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "catalog", generator.getCatalog(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "schema", generator.getSchema(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "pkColumnName", generator.getPkColumnName(), annotationUsage );
|
||||
applyStringAttributeIfSpecified( "valueColumnName", generator.getValueColumnName(), annotationUsage );
|
||||
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 );
|
||||
applyStringAttributeIfSpecified( "options", generator.getOptions(), annotationUsage );
|
||||
|
||||
collectTableGenerator( new TableGeneratorRegistration( generator.getName(), annotationUsage ) );
|
||||
} );
|
||||
|
@ -713,11 +719,13 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
|
||||
genericGenerators.forEach( (generator) -> {
|
||||
final MutableAnnotationUsage<GenericGenerator> annotationUsage = makeAnnotation( HibernateAnnotations.GENERIC_GENERATOR );
|
||||
annotationUsage.setAttributeValue( "name", generator.getName() );
|
||||
annotationUsage.setAttributeValue( "strategy", generator.getClazz() );
|
||||
applyStringAttributeIfSpecified( "name", generator.getName(), annotationUsage );
|
||||
|
||||
applyStringAttributeIfSpecified( "strategy", generator.getClazz(), annotationUsage );
|
||||
|
||||
// todo : update the mapping.xsd to account for new @GenericGenerator definition
|
||||
|
||||
applyAttributeIfSpecified( "parameters", generator.getParameters(), annotationUsage );
|
||||
// setValueIfNotNull( "type", generator.getType(), annotationUsage );
|
||||
collectGenericGenerator( new GenericGeneratorRegistration( generator.getName(), annotationUsage ) );
|
||||
} );
|
||||
}
|
||||
|
@ -783,7 +791,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
|
||||
jaxbSqlResultSetMappings.forEach( (jaxbMapping) -> {
|
||||
final MutableAnnotationUsage<SqlResultSetMapping> mappingAnnotation = JpaAnnotations.SQL_RESULT_SET_MAPPING.createUsage( null, null );
|
||||
mappingAnnotation.setAttributeValue( "name", jaxbMapping.getName() );
|
||||
applyStringAttributeIfSpecified( "name", jaxbMapping.getName(), mappingAnnotation );
|
||||
|
||||
sqlResultSetMappingRegistrations.put(
|
||||
jaxbMapping.getName(),
|
||||
|
@ -792,17 +800,17 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
|
||||
applyEntityResults(
|
||||
jaxbMapping.getEntityResult(),
|
||||
(results) -> mappingAnnotation.setAttributeValue( "entities", results )
|
||||
(results) -> applyAttributeIfSpecified( "entities", results, mappingAnnotation )
|
||||
);
|
||||
|
||||
applyConstructorResults(
|
||||
jaxbMapping.getConstructorResult(),
|
||||
(results) -> mappingAnnotation.setAttributeValue( "classes", results )
|
||||
(results) -> applyAttributeIfSpecified( "classes", results, mappingAnnotation )
|
||||
);
|
||||
|
||||
applyColumnResults(
|
||||
jaxbMapping.getColumnResult(),
|
||||
(columnResults) -> mappingAnnotation.setAttributeValue( "columns", columnResults )
|
||||
(columnResults) -> applyAttributeIfSpecified( "columns", columnResults, mappingAnnotation )
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
@ -820,18 +828,18 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
final MutableAnnotationUsage<EntityResult> entityResultAnnotation = makeAnnotation( JpaAnnotations.ENTITY_RESULT );
|
||||
entityResults.add( entityResultAnnotation );
|
||||
|
||||
entityResultAnnotation.setAttributeValue( "entityClass", classDetailsRegistry.resolveClassDetails( jaxbEntityResult.getEntityClass() ) );
|
||||
entityResultAnnotation.setAttributeValue( "lockMode", jaxbEntityResult.getLockMode() );
|
||||
entityResultAnnotation.setAttributeValue( "discriminatorColumn", jaxbEntityResult.getDiscriminatorColumn() );
|
||||
applyAttributeIfSpecified( "entityClass", classDetailsRegistry.resolveClassDetails( jaxbEntityResult.getEntityClass() ), entityResultAnnotation );
|
||||
applyAttributeIfSpecified( "lockMode", jaxbEntityResult.getLockMode(), entityResultAnnotation );
|
||||
applyStringAttributeIfSpecified( "discriminatorColumn", jaxbEntityResult.getDiscriminatorColumn(), entityResultAnnotation );
|
||||
|
||||
if ( !jaxbEntityResult.getFieldResult().isEmpty() ) {
|
||||
final List<AnnotationUsage<FieldResult>> fieldResults = arrayList( jaxbEntityResult.getFieldResult().size() );
|
||||
entityResultAnnotation.setAttributeValue( "fields", fieldResults );
|
||||
applyAttributeIfSpecified( "fields", fieldResults, entityResultAnnotation );
|
||||
|
||||
for ( JaxbFieldResultImpl jaxbFieldResult : jaxbEntityResult.getFieldResult() ) {
|
||||
final MutableAnnotationUsage<FieldResult> fieldResultAnnotation = makeAnnotation( JpaAnnotations.FIELD_RESULT );
|
||||
fieldResultAnnotation.setAttributeValue( "name", jaxbFieldResult.getName() );
|
||||
fieldResultAnnotation.setAttributeValue( "column", jaxbFieldResult.getColumn() );
|
||||
applyStringAttributeIfSpecified( "name", jaxbFieldResult.getName(), fieldResultAnnotation );
|
||||
applyStringAttributeIfSpecified( "column", jaxbFieldResult.getColumn(), fieldResultAnnotation );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -877,7 +885,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
columnResults.add( columnResultAnnotation );
|
||||
|
||||
columnResultAnnotation.setAttributeValue( "name", jaxbColumn.getName() );
|
||||
columnResultAnnotation.setAttributeValue( "type", classDetailsRegistry.resolveClassDetails( jaxbColumn.getClazz() ) );
|
||||
applyAttributeIfSpecified( "type", classDetailsRegistry.resolveClassDetails( jaxbColumn.getClazz() ), columnResultAnnotation );
|
||||
}
|
||||
annotationListConsumer.accept( columnResults );
|
||||
}
|
||||
|
@ -898,12 +906,12 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
new NamedQueryRegistration( jaxbNamedQuery.getName(), queryAnnotation )
|
||||
);
|
||||
|
||||
queryAnnotation.setAttributeValue( "name", jaxbNamedQuery.getName() );
|
||||
queryAnnotation.setAttributeValue( "query", jaxbNamedQuery.getQuery() );
|
||||
queryAnnotation.setAttributeValue( "lockMode", jaxbNamedQuery.getLockMode() );
|
||||
applyStringAttributeIfSpecified( "name", jaxbNamedQuery.getName(), queryAnnotation );
|
||||
applyStringAttributeIfSpecified( "query", jaxbNamedQuery.getQuery(), queryAnnotation );
|
||||
applyAttributeIfSpecified( "lockMode", jaxbNamedQuery.getLockMode(), queryAnnotation );
|
||||
|
||||
final List<AnnotationUsage<QueryHint>> hints = extractQueryHints( jaxbNamedQuery );
|
||||
queryAnnotation.setAttributeValue( "hints", hints );
|
||||
applyAttributeIfSpecified( "hints", hints, queryAnnotation );
|
||||
|
||||
if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) {
|
||||
final MutableAnnotationUsage<QueryHint> cacheableHint = makeAnnotation( JpaAnnotations.QUERY_HINT );
|
||||
|
@ -972,9 +980,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
queryAnnotation.setAttributeValue( "resultClass", classDetailsRegistry.resolveClassDetails( jaxbNamedQuery.getResultClass() ) );
|
||||
}
|
||||
|
||||
if ( StringHelper.isNotEmpty( jaxbNamedQuery.getResultSetMapping() ) ) {
|
||||
queryAnnotation.setAttributeValue( "resultSetMapping", jaxbNamedQuery.getResultSetMapping() );
|
||||
}
|
||||
applyStringAttributeIfSpecified( "resultSetMapping", jaxbNamedQuery.getResultSetMapping(), queryAnnotation );
|
||||
|
||||
applyEntityResults(
|
||||
jaxbNamedQuery.getEntityResult(),
|
||||
|
@ -1046,24 +1052,24 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
queryAnnotation.setAttributeValue( "procedureName", jaxbQuery.getProcedureName() );
|
||||
|
||||
final ArrayList<ClassDetails> resultClasses = arrayList( jaxbQuery.getResultClasses().size() );
|
||||
queryAnnotation.setAttributeValue( "resultClasses", resultClasses );
|
||||
applyAttributeIfSpecified( "resultClasses", resultClasses, queryAnnotation );
|
||||
for ( String resultClassName : jaxbQuery.getResultClasses() ) {
|
||||
resultClasses.add( classDetailsRegistry.resolveClassDetails( resultClassName ) );
|
||||
}
|
||||
|
||||
queryAnnotation.setAttributeValue( "resultSetMappings", jaxbQuery.getResultSetMappings() );
|
||||
applyAttributeIfSpecified( "resultSetMappings", jaxbQuery.getResultSetMappings(), queryAnnotation );
|
||||
|
||||
queryAnnotation.setAttributeValue( "hints", extractQueryHints( jaxbQuery ) );
|
||||
applyAttributeIfSpecified( "hints", extractQueryHints( jaxbQuery ), queryAnnotation );
|
||||
|
||||
final ArrayList<AnnotationUsage<StoredProcedureParameter>> parameters = arrayList( jaxbQuery.getProcedureParameters().size() );
|
||||
queryAnnotation.setAttributeValue( "parameters", parameters );
|
||||
applyAttributeIfSpecified( "parameters", parameters, queryAnnotation );
|
||||
for ( JaxbStoredProcedureParameterImpl jaxbProcedureParameter : jaxbQuery.getProcedureParameters() ) {
|
||||
final MutableAnnotationUsage<StoredProcedureParameter> parameterAnnotation = makeAnnotation( JpaAnnotations.STORED_PROCEDURE_PARAMETER );
|
||||
parameters.add( parameterAnnotation );
|
||||
|
||||
parameterAnnotation.setAttributeValue( "name", jaxbProcedureParameter.getName() );
|
||||
parameterAnnotation.setAttributeValue( "mode", jaxbProcedureParameter.getMode() );
|
||||
parameterAnnotation.setAttributeValue( "type", classDetailsRegistry.resolveClassDetails( jaxbProcedureParameter.getClazz() ) );
|
||||
applyStringAttributeIfSpecified( "name", jaxbProcedureParameter.getName(), parameterAnnotation );
|
||||
applyAttributeIfSpecified( "mode", jaxbProcedureParameter.getMode(), parameterAnnotation );
|
||||
applyAttributeIfSpecified( "type", classDetailsRegistry.resolveClassDetails( jaxbProcedureParameter.getClazz() ), parameterAnnotation );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.hibernate.boot.models.internal;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.models.spi.MutableAnnotationUsage;
|
||||
|
||||
public class AnnotationUsageHelper {
|
||||
|
||||
public static <A extends Annotation> void applyAttributeIfSpecified(
|
||||
String attributeName,
|
||||
Object value,
|
||||
MutableAnnotationUsage<A> annotationUsage) {
|
||||
if ( value != null ) {
|
||||
annotationUsage.setAttributeValue( attributeName, value );
|
||||
}
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyStringAttributeIfSpecified(
|
||||
String attributeName,
|
||||
String value,
|
||||
MutableAnnotationUsage<A> annotationUsage) {
|
||||
if ( StringHelper.isNotEmpty( value ) ) {
|
||||
annotationUsage.setAttributeValue( attributeName, value );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,10 +7,7 @@
|
|||
package org.hibernate.boot.models.xml.internal;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
|
@ -21,15 +18,11 @@ import org.hibernate.annotations.SQLUpdate;
|
|||
import org.hibernate.annotations.TenantId;
|
||||
import org.hibernate.boot.internal.Abstract;
|
||||
import org.hibernate.boot.internal.Extends;
|
||||
import org.hibernate.boot.internal.LimitedCollectionClassification;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainer;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainerImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbCachingImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddableImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedIdImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityOrMappedSuperclass;
|
||||
|
@ -37,9 +30,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbIdImpl;
|
|||
import org.hibernate.boot.jaxb.mapping.spi.JaxbManagedType;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclassImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraphImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToOneImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistentAttribute;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralAttribute;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbTenantIdImpl;
|
||||
import org.hibernate.boot.models.HibernateAnnotations;
|
||||
import org.hibernate.boot.models.JpaAnnotations;
|
||||
|
@ -78,7 +69,6 @@ import jakarta.persistence.MappedSuperclass;
|
|||
|
||||
import static org.hibernate.internal.util.NullnessHelper.coalesce;
|
||||
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
|
||||
import static org.hibernate.internal.util.NullnessHelper.nullif;
|
||||
|
||||
/**
|
||||
* Helper for handling managed types defined in mapping XML, in either
|
||||
|
@ -500,8 +490,12 @@ public class ManagedTypeProcessor {
|
|||
xmlDocumentContext.getModelBuildingContext()
|
||||
);
|
||||
classDetails.addAnnotationUsage( cacheableUsage );
|
||||
XmlProcessingHelper.setIf( jaxbCaching.getRegion(), "region", cacheableUsage );
|
||||
XmlProcessingHelper.setIf( convertCacheAccessType( jaxbCaching.getAccess() ), "access", cacheableUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "region", jaxbCaching.getRegion(), cacheableUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified(
|
||||
"access",
|
||||
convertCacheAccessType( jaxbCaching.getAccess() ),
|
||||
cacheableUsage
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -155,7 +155,6 @@ import jakarta.persistence.UniqueConstraint;
|
|||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.hibernate.boot.models.xml.internal.XmlProcessingHelper.makeNestedAnnotation;
|
||||
import static org.hibernate.internal.util.NullnessHelper.coalesce;
|
||||
|
||||
/**
|
||||
* Helper for creating annotation from equivalent JAXB
|
||||
|
@ -173,9 +172,7 @@ public class XmlAnnotationHelper {
|
|||
MutableClassDetails classDetails,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
final MutableAnnotationUsage<Entity> entityUsage = XmlProcessingHelper.getOrMakeAnnotation( Entity.class, classDetails, xmlDocumentContext );
|
||||
if ( StringHelper.isNotEmpty( jaxbEntity.getName() ) ) {
|
||||
entityUsage.setAttributeValue( "name", jaxbEntity.getName() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbEntity.getName(), entityUsage );
|
||||
}
|
||||
|
||||
public static MutableAnnotationUsage<Access> createAccessAnnotation(
|
||||
|
@ -194,7 +191,7 @@ public class XmlAnnotationHelper {
|
|||
final MutableAnnotationUsage<AttributeAccessor> accessorAnn = XmlProcessingHelper.makeAnnotation( AttributeAccessor.class, memberDetails, xmlDocumentContext );
|
||||
memberDetails.addAnnotationUsage( accessorAnn );
|
||||
// todo : this is the old, deprecated form
|
||||
accessorAnn.setAttributeValue( "value", attributeAccessor );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "value", attributeAccessor, accessorAnn );
|
||||
}
|
||||
|
||||
public static void applyColumn(
|
||||
|
@ -580,7 +577,8 @@ public class XmlAnnotationHelper {
|
|||
final AnnotationDescriptor<UniqueConstraint> uniqueConstraintDescriptor = xmlDocumentContext.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
.getDescriptor( UniqueConstraint.class );
|
||||
applyOr( jaxbUniqueConstraint, JaxbUniqueConstraintImpl::getName, "name", uniqueConstraintAnn, uniqueConstraintDescriptor );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbUniqueConstraint.getName(), uniqueConstraintAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "options", jaxbUniqueConstraint.getOptions(), uniqueConstraintAnn );
|
||||
uniqueConstraintAnn.setAttributeValue( "columnNames", jaxbUniqueConstraint.getColumnName() );
|
||||
uniqueConstraints.add( uniqueConstraintAnn );
|
||||
} );
|
||||
|
@ -771,8 +769,8 @@ public class XmlAnnotationHelper {
|
|||
|
||||
final MutableAnnotationUsage<GeneratedValue> generatedValueAnn = XmlProcessingHelper.makeAnnotation( GeneratedValue.class, memberDetails, xmlDocumentContext );
|
||||
memberDetails.addAnnotationUsage( generatedValueAnn );
|
||||
generatedValueAnn.setAttributeValue( "strategy", jaxbGeneratedValue.getStrategy() );
|
||||
generatedValueAnn.setAttributeValue( "generator", jaxbGeneratedValue.getGenerator() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "strategy", jaxbGeneratedValue.getStrategy(), generatedValueAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "generator", jaxbGeneratedValue.getGenerator(), generatedValueAnn );
|
||||
}
|
||||
|
||||
public static void applySequenceGenerator(
|
||||
|
@ -790,14 +788,13 @@ public class XmlAnnotationHelper {
|
|||
xmlDocumentContext
|
||||
);
|
||||
|
||||
if ( StringHelper.isNotEmpty( jaxbGenerator.getSequenceName() ) ) {
|
||||
sequenceAnn.setAttributeValue( "sequenceName", jaxbGenerator.getSequenceName() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "sequenceName", jaxbGenerator.getSequenceName(), sequenceAnn );
|
||||
|
||||
sequenceAnn.setAttributeValue( "catalog", jaxbGenerator.getCatalog() );
|
||||
sequenceAnn.setAttributeValue( "schema", jaxbGenerator.getSchema() );
|
||||
sequenceAnn.setAttributeValue( "initialValue", jaxbGenerator.getInitialValue() );
|
||||
sequenceAnn.setAttributeValue( "allocationSize", jaxbGenerator.getInitialValue() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "catalog", jaxbGenerator.getCatalog(), sequenceAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "schema", jaxbGenerator.getSchema(), sequenceAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "initialValue", jaxbGenerator.getInitialValue(), sequenceAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "allocationSize", jaxbGenerator.getInitialValue(), sequenceAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "options", jaxbGenerator.getOptions(), sequenceAnn );
|
||||
}
|
||||
|
||||
public static void applyTableGenerator(
|
||||
|
@ -810,15 +807,15 @@ public class XmlAnnotationHelper {
|
|||
|
||||
final MutableAnnotationUsage<TableGenerator> annotationUsage = XmlProcessingHelper.makeAnnotation( TableGenerator.class, memberDetails, xmlDocumentContext );
|
||||
memberDetails.addAnnotationUsage( annotationUsage );
|
||||
annotationUsage.setAttributeValue( "name", jaxbGenerator.getName() );
|
||||
annotationUsage.setAttributeValue( "table", jaxbGenerator.getTable() );
|
||||
annotationUsage.setAttributeValue( "catalog", jaxbGenerator.getCatalog() );
|
||||
annotationUsage.setAttributeValue( "schema", jaxbGenerator.getSchema() );
|
||||
annotationUsage.setAttributeValue( "pkColumnName", jaxbGenerator.getPkColumnName() );
|
||||
annotationUsage.setAttributeValue( "valueColumnName", jaxbGenerator.getValueColumnName() );
|
||||
annotationUsage.setAttributeValue( "pkColumnValue", jaxbGenerator.getPkColumnValue() );
|
||||
annotationUsage.setAttributeValue( "initialValue", jaxbGenerator.getInitialValue() );
|
||||
annotationUsage.setAttributeValue( "allocationSize", jaxbGenerator.getInitialValue() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbGenerator.getName(), annotationUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "table", jaxbGenerator.getTable(), annotationUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "catalog", jaxbGenerator.getCatalog(), annotationUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "schema", jaxbGenerator.getSchema(), annotationUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "pkColumnName", jaxbGenerator.getPkColumnName(), annotationUsage );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "valueColumnName", jaxbGenerator.getValueColumnName(), annotationUsage );
|
||||
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 );
|
||||
}
|
||||
|
@ -897,9 +894,9 @@ public class XmlAnnotationHelper {
|
|||
xmlDocumentContext
|
||||
);
|
||||
memberDetails.addAnnotationUsage( annotationUsage );
|
||||
annotationUsage.setAttributeValue( "name", jaxbOverride.getName() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbOverride.getName(), annotationUsage );
|
||||
final List<JaxbJoinColumnImpl> joinColumns = jaxbOverride.getJoinColumns();
|
||||
if ( CollectionHelper.isNotEmpty( joinColumns)) {
|
||||
if ( CollectionHelper.isNotEmpty( joinColumns ) ) {
|
||||
annotationUsage.setAttributeValue( "joinColumns", createJoinColumns( joinColumns, memberDetails, xmlDocumentContext ) );
|
||||
}
|
||||
if ( jaxbOverride.getJoinTable() != null ) {
|
||||
|
@ -957,14 +954,15 @@ public class XmlAnnotationHelper {
|
|||
final ClassDetails converter;
|
||||
if ( StringHelper.isNotEmpty( jaxbConvert.getConverter() ) ) {
|
||||
converter = classDetailsRegistry.resolveClassDetails( jaxbConvert.getConverter() );
|
||||
annotationUsage.setAttributeValue( "converter", converter );
|
||||
}
|
||||
else {
|
||||
// allowable for disable-conversion
|
||||
converter = null;
|
||||
}
|
||||
annotationUsage.setAttributeValue( "converter", converter );
|
||||
annotationUsage.setAttributeValue( "attributeName", prefixIfNotAlready( jaxbConvert.getAttributeName(), namePrefix ) );
|
||||
annotationUsage.setAttributeValue( "disableConversion", jaxbConvert.isDisableConversion() );
|
||||
|
||||
XmlProcessingHelper.applyAttributeIfSpecified(
|
||||
"attributeName",
|
||||
prefixIfNotAlready( jaxbConvert.getAttributeName(), namePrefix ),
|
||||
annotationUsage
|
||||
);
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "disableConversion", jaxbConvert.isDisableConversion(), annotationUsage );
|
||||
}
|
||||
|
||||
public static void applyTable(
|
||||
|
@ -1010,34 +1008,6 @@ public class XmlAnnotationHelper {
|
|||
applyCheckConstraints( jaxbTable, target, tableAnn, xmlDocumentContext );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyAttributeIfSpecified(
|
||||
MutableAnnotationUsage<A> annotationUsage,
|
||||
String attributeName,
|
||||
String value) {
|
||||
if ( StringHelper.isNotEmpty( value ) ) {
|
||||
annotationUsage.setAttributeValue( attributeName, value );
|
||||
}
|
||||
}
|
||||
|
||||
private static <A extends Annotation, V> void applyAttributeIfSpecified(
|
||||
MutableAnnotationUsage<A> annotationUsage,
|
||||
String attributeName,
|
||||
V... values) {
|
||||
final V coalesced = coalesce( values );
|
||||
if ( coalesced != null ) {
|
||||
annotationUsage.setAttributeValue( attributeName, coalesced );
|
||||
}
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyAttributeIfSpecified(
|
||||
MutableAnnotationUsage<A> tableAnn,
|
||||
String attributeName,
|
||||
Object value) {
|
||||
if ( value != null ) {
|
||||
tableAnn.setAttributeValue( attributeName, value );
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyNaturalId(
|
||||
JaxbNaturalId jaxbNaturalId,
|
||||
MutableMemberDetails backingMember,
|
||||
|
@ -1070,7 +1040,7 @@ public class XmlAnnotationHelper {
|
|||
classDetails.addAnnotationUsage( annotationUsage );
|
||||
|
||||
final JaxbCachingImpl jaxbCaching = jaxbNaturalId.getCaching();
|
||||
annotationUsage.setAttributeValue( "region", jaxbCaching.getRegion() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "region", jaxbCaching.getRegion(), annotationUsage );
|
||||
}
|
||||
|
||||
public static void applyId(
|
||||
|
@ -1116,7 +1086,7 @@ public class XmlAnnotationHelper {
|
|||
classDetails,
|
||||
xmlDocumentContext
|
||||
);
|
||||
inheritanceAnn.setAttributeValue( "strategy", jaxbEntity.getInheritance().getStrategy() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "strategy", jaxbEntity.getInheritance().getStrategy(), inheritanceAnn );
|
||||
}
|
||||
|
||||
public static ClassDetails resolveJavaType(String value, XmlDocumentContext xmlDocumentContext) {
|
||||
|
@ -1299,8 +1269,8 @@ public class XmlAnnotationHelper {
|
|||
xmlDocumentContext
|
||||
);
|
||||
|
||||
applyAttributeIfSpecified( filterAnn, "condition", jaxbFilter.getCondition() );
|
||||
applyAttributeIfSpecified( filterAnn, "deduceAliasInjectionPoints", jaxbFilter.isAutoAliasInjection() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "condition", jaxbFilter.getCondition(), filterAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "deduceAliasInjectionPoints", jaxbFilter.isAutoAliasInjection(), filterAnn );
|
||||
|
||||
final List<JaxbHbmFilterImpl.JaxbAliasesImpl> aliases = jaxbFilter.getAliases();
|
||||
if ( !CollectionHelper.isEmpty( aliases ) ) {
|
||||
|
@ -1316,7 +1286,7 @@ public class XmlAnnotationHelper {
|
|||
for ( JaxbHbmFilterImpl.JaxbAliasesImpl alias : aliases ) {
|
||||
final MutableAnnotationUsage<SqlFragmentAlias> aliasAnn = makeNestedAnnotation( SqlFragmentAlias.class, target, xmlDocumentContext );
|
||||
aliasAnn.setAttributeValue( "alias", alias.getAlias() );
|
||||
applyAttributeIfSpecified( aliasAnn, "table", alias.getTable() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "table", alias.getTable(), aliasAnn );
|
||||
if ( StringHelper.isNotEmpty( alias.getEntity() ) ) {
|
||||
aliasAnn.setAttributeValue(
|
||||
"entity",
|
||||
|
@ -1362,7 +1332,7 @@ public class XmlAnnotationHelper {
|
|||
final MutableAnnotationUsage<A> annotation = XmlProcessingHelper.getOrMakeAnnotation( annotationType, target, xmlDocumentContext );
|
||||
annotation.setAttributeValue( "sql", jaxbCustomSql.getValue() );
|
||||
annotation.setAttributeValue( "callable", jaxbCustomSql.isCallable() );
|
||||
applyAttributeIfSpecified( annotation, "table", jaxbCustomSql.getTable() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "table", jaxbCustomSql.getTable(), annotation );
|
||||
if ( jaxbCustomSql.getResultCheck() != null ) {
|
||||
annotation.setAttributeValue( "check", getResultCheckStyle( jaxbCustomSql.getResultCheck() ) );
|
||||
}
|
||||
|
@ -1474,7 +1444,7 @@ public class XmlAnnotationHelper {
|
|||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( rowId != null ) {
|
||||
final MutableAnnotationUsage<RowId> rowIdAnn = XmlProcessingHelper.getOrMakeAnnotation( RowId.class, target, xmlDocumentContext );
|
||||
applyAttributeIfSpecified( rowIdAnn, "value", rowId );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "value", rowId, rowIdAnn );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1500,21 +1470,8 @@ public class XmlAnnotationHelper {
|
|||
);
|
||||
|
||||
final AnnotationDescriptor<NamedEntityGraph> namedEntityGraphAnnotationDescriptor = namedEntityGraphAnn.getAnnotationDescriptor();
|
||||
applyOr(
|
||||
namedEntityGraph,
|
||||
JaxbNamedEntityGraphImpl::getName,
|
||||
"name",
|
||||
namedEntityGraphAnn,
|
||||
namedEntityGraphAnnotationDescriptor
|
||||
);
|
||||
|
||||
applyOr(
|
||||
namedEntityGraph,
|
||||
JaxbNamedEntityGraphImpl::isIncludeAllAttributes,
|
||||
"includeAllAttributes",
|
||||
namedEntityGraphAnn,
|
||||
namedEntityGraphAnnotationDescriptor
|
||||
);
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "name", namedEntityGraph.getName(), namedEntityGraphAnn );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "includeAllAttributes", namedEntityGraph.isIncludeAllAttributes(), namedEntityGraphAnn );
|
||||
|
||||
namedEntityGraphAnn.setAttributeValue(
|
||||
"attributeNodes",
|
||||
|
@ -1557,7 +1514,7 @@ public class XmlAnnotationHelper {
|
|||
target,
|
||||
xmlDocumentContext
|
||||
);
|
||||
applyAttributeIfSpecified( namedSubgraphNodeAnn, "name", subGraphsNodeName );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "name", subGraphsNodeName, namedSubgraphNodeAnn );
|
||||
|
||||
final String clazz = subclassSubgraphNode.getClazz();
|
||||
if ( clazz == null ) {
|
||||
|
@ -1601,7 +1558,7 @@ public class XmlAnnotationHelper {
|
|||
target,
|
||||
xmlDocumentContext
|
||||
);
|
||||
applyAttributeIfSpecified( namedAttributeNodeAnn, "value", namedAttributeNode.getName() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "value", namedAttributeNode.getName(), namedAttributeNodeAnn );
|
||||
final AnnotationDescriptor<NamedAttributeNode> namedAttributeNodeDescriptor = xmlDocumentContext
|
||||
.getModelBuildingContext()
|
||||
.getAnnotationDescriptorRegistry()
|
||||
|
@ -1633,7 +1590,7 @@ public class XmlAnnotationHelper {
|
|||
if ( discriminatorValue != null ) {
|
||||
final MutableAnnotationUsage<DiscriminatorValue> rowIdAnn = XmlProcessingHelper
|
||||
.getOrMakeAnnotation( DiscriminatorValue.class, target, xmlDocumentContext );
|
||||
applyAttributeIfSpecified( rowIdAnn, "value", discriminatorValue );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "value", discriminatorValue, rowIdAnn );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1704,7 +1661,7 @@ public class XmlAnnotationHelper {
|
|||
);
|
||||
|
||||
discriminatorFormulaAnn.setAttributeValue( "value", jaxbDiscriminatorFormula.getFragment() );
|
||||
discriminatorFormulaAnn.setAttributeValue( "discriminatorType", jaxbDiscriminatorFormula.getDiscriminatorType() );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "discriminatorType", jaxbDiscriminatorFormula.getDiscriminatorType(), discriminatorFormulaAnn );
|
||||
|
||||
if ( jaxbDiscriminatorFormula.isForceSelection() ) {
|
||||
final MutableAnnotationUsage<DiscriminatorOptions> existingOptionsAnnotation = (MutableAnnotationUsage<DiscriminatorOptions>) target.getAnnotationUsage( DiscriminatorOptions.class );
|
||||
|
|
|
@ -247,4 +247,22 @@ public class XmlProcessingHelper {
|
|||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyAttributeIfSpecified(
|
||||
String attributeName,
|
||||
Object value,
|
||||
MutableAnnotationUsage<A> tableAnn) {
|
||||
if ( value != null ) {
|
||||
tableAnn.setAttributeValue( attributeName, value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class AnyMappingAttributeProcessing {
|
|||
}
|
||||
|
||||
final DiscriminatorType discriminatorType = jaxbDiscriminator.getType();
|
||||
anyDiscriminatorAnn.setAttributeValue( "value", discriminatorType );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "value", discriminatorType, anyDiscriminatorAnn );
|
||||
|
||||
final JaxbColumnImpl jaxbColumn = jaxbDiscriminator.getColumn();
|
||||
final MutableAnnotationUsage<Column> columnAnn = XmlProcessingHelper.makeAnnotation( Column.class, memberDetails, xmlDocumentContext );
|
||||
|
|
|
@ -74,7 +74,7 @@ public class CommonAttributeProcessing {
|
|||
.getClassDetailsRegistry()
|
||||
.getClassDetails( attributeAccessor );
|
||||
final MutableAnnotationUsage<AttributeAccessor> accessAnn = XmlProcessingHelper.makeAnnotation( AttributeAccessor.class, memberDetails, xmlDocumentContext );
|
||||
accessAnn.setAttributeValue( "strategy", strategyClassDetails );
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "strategy", strategyClassDetails, accessAnn );
|
||||
}
|
||||
|
||||
public static <A extends Annotation> void applyOptionality(
|
||||
|
@ -105,9 +105,7 @@ public class CommonAttributeProcessing {
|
|||
MutableAnnotationUsage<A> attributeAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
final FetchType fetchType = jaxbAttribute.getFetch();
|
||||
if ( fetchType != null ) {
|
||||
attributeAnn.setAttributeValue( "fetch", fetchType );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "fetch", fetchType, attributeAnn );
|
||||
|
||||
if ( jaxbAttribute instanceof JaxbSingularAssociationAttribute jaxbSingularAttribute ) {
|
||||
final JaxbSingularFetchModeImpl jaxbFetchMode = jaxbSingularAttribute.getFetchMode();
|
||||
|
|
|
@ -6,13 +6,11 @@
|
|||
*/
|
||||
package org.hibernate.boot.models.xml.internal.attr;
|
||||
|
||||
import org.hibernate.boot.internal.Target;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionTableImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollectionImpl;
|
||||
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.StringHelper;
|
||||
import org.hibernate.models.spi.AnnotationDescriptor;
|
||||
import org.hibernate.models.spi.MutableAnnotationUsage;
|
||||
import org.hibernate.models.spi.MutableClassDetails;
|
||||
|
@ -47,13 +45,18 @@ public class ElementCollectionAttributeProcessing {
|
|||
memberDetails,
|
||||
xmlDocumentContext
|
||||
);
|
||||
XmlProcessingHelper.setIf( jaxbElementCollection.getFetch(), "fetch", elementCollectionAnn );
|
||||
elementCollectionAnn.setAttributeValue(
|
||||
XmlProcessingHelper.applyAttributeIfSpecified(
|
||||
"fetch",
|
||||
jaxbElementCollection.getFetch(),
|
||||
elementCollectionAnn
|
||||
);
|
||||
XmlProcessingHelper.applyAttributeIfSpecified(
|
||||
"targetClass",
|
||||
XmlAnnotationHelper.resolveJavaType(
|
||||
jaxbElementCollection.getTargetClass(),
|
||||
xmlDocumentContext.getModelBuildingContext()
|
||||
)
|
||||
).determineRawClass(),
|
||||
elementCollectionAnn
|
||||
);
|
||||
|
||||
CommonAttributeProcessing.applyAttributeBasics( jaxbElementCollection, memberDetails, elementCollectionAnn, accessType, xmlDocumentContext );
|
||||
|
|
|
@ -18,9 +18,10 @@ import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnSizable;
|
|||
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnStandard;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnUniqueable;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCommentable;
|
||||
import org.hibernate.boot.models.internal.AnnotationUsageHelper;
|
||||
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.StringHelper;
|
||||
import org.hibernate.models.spi.MutableAnnotationTarget;
|
||||
import org.hibernate.models.spi.MutableAnnotationUsage;
|
||||
|
||||
|
@ -135,83 +136,62 @@ public class ColumnProcessing {
|
|||
JaxbColumn jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) {
|
||||
columnAnn.setAttributeValue( "name", jaxbColumn.getName() );
|
||||
}
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", jaxbColumn.getName(), columnAnn );
|
||||
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) {
|
||||
columnAnn.setAttributeValue( "table", jaxbColumn.getTable() );
|
||||
}
|
||||
AnnotationUsageHelper.applyStringAttributeIfSpecified( "table", jaxbColumn.getTable(), columnAnn );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyColumnNullness(
|
||||
JaxbColumnNullable jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn.isNullable() != null ) {
|
||||
columnAnn.setAttributeValue( "unique", jaxbColumn.isNullable() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "unique", jaxbColumn.isNullable(), columnAnn );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyColumnMutability(
|
||||
JaxbColumnMutable jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn.isInsertable() != null ) {
|
||||
columnAnn.setAttributeValue( "insertable", jaxbColumn.isInsertable() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "insertable", jaxbColumn.isInsertable(), columnAnn );
|
||||
|
||||
if ( jaxbColumn.isUpdatable() != null ) {
|
||||
columnAnn.setAttributeValue( "updatable", jaxbColumn.isUpdatable() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "updatable", jaxbColumn.isUpdatable(), columnAnn );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyColumnSizing(
|
||||
JaxbColumnSizable jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "length", jaxbColumn.getLength(), columnAnn );
|
||||
|
||||
if ( jaxbColumn.getLength() != null ) {
|
||||
columnAnn.setAttributeValue( "length", jaxbColumn.getLength() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "precision", jaxbColumn.getPrecision(), columnAnn );
|
||||
|
||||
if ( jaxbColumn.getPrecision() != null ) {
|
||||
columnAnn.setAttributeValue( "precision", jaxbColumn.getPrecision() );
|
||||
}
|
||||
|
||||
if ( jaxbColumn.getScale() != null ) {
|
||||
columnAnn.setAttributeValue( "scale", jaxbColumn.getScale() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "scale", jaxbColumn.getScale(), columnAnn );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyColumnUniqueness(
|
||||
JaxbColumnUniqueable jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( jaxbColumn.isUnique() != null ) {
|
||||
columnAnn.setAttributeValue( "unique", jaxbColumn.isUnique() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "unique", jaxbColumn.isUnique(), columnAnn );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyColumnDefinition(
|
||||
JaxbColumnDefinable jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) {
|
||||
columnAnn.setAttributeValue( "columnDefinition", jaxbColumn.getColumnDefinition() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified(
|
||||
"columnDefinition",
|
||||
jaxbColumn.getColumnDefinition(),
|
||||
columnAnn
|
||||
);
|
||||
|
||||
if ( jaxbColumn.getOptions() != null ) {
|
||||
columnAnn.setAttributeValue( "options", jaxbColumn.getOptions() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "options", jaxbColumn.getOptions(), columnAnn );
|
||||
}
|
||||
|
||||
private static <A extends Annotation> void applyColumnComment(
|
||||
JaxbCommentable jaxbColumn,
|
||||
MutableAnnotationUsage<A> columnAnn,
|
||||
XmlDocumentContext xmlDocumentContext) {
|
||||
if ( StringHelper.isNotEmpty( jaxbColumn.getComment() ) ) {
|
||||
columnAnn.setAttributeValue( "comment", jaxbColumn.getComment() );
|
||||
}
|
||||
XmlProcessingHelper.applyAttributeIfSpecified( "comment", jaxbColumn.getComment(), columnAnn );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue