models-0.7.9

This commit is contained in:
Steve Ebersole 2024-04-23 16:29:51 -05:00
parent 1f5d2fb417
commit f8311935ee
10 changed files with 41 additions and 73 deletions

View File

@ -882,7 +882,7 @@ public class AnnotatedColumn {
final List<AnnotationUsage<Check>> checkAnns = checksAnn.getList( "value" );
for ( AnnotationUsage<Check> checkAnn : checkAnns ) {
addCheckConstraint(
checkAnn.getString( "name", (String) null ),
checkAnn.getString( "name" ),
checkAnn.getString( "constraints" )
);
}

View File

@ -50,9 +50,7 @@ import jakarta.persistence.Lob;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import static jakarta.persistence.EnumType.ORDINAL;
import static java.util.Collections.singletonMap;
import static org.hibernate.annotations.TimeZoneStorageType.AUTO;
import static org.hibernate.annotations.TimeZoneStorageType.COLUMN;
/**
@ -167,7 +165,7 @@ public class BasicValueHelper {
return;
}
basicValue.setEnumerationStyle( enumerated.getEnum( "value", ORDINAL ) );
basicValue.setEnumerationStyle( enumerated.getEnum( "value" ) );
}
public static void bindTemporalPrecision(
@ -196,7 +194,7 @@ public class BasicValueHelper {
final AnnotationUsage<TimeZoneStorage> storageAnn = member.getAnnotationUsage( TimeZoneStorage.class );
final AnnotationUsage<TimeZoneColumn> columnAnn = member.getAnnotationUsage( TimeZoneColumn.class );
if ( storageAnn != null ) {
final TimeZoneStorageType strategy = storageAnn.getEnum( "value", AUTO );
final TimeZoneStorageType strategy = storageAnn.getEnum( "value" );
if ( strategy != COLUMN && columnAnn != null ) {
throw new AnnotationPlacementException(
"Illegal combination of @TimeZoneStorage(" + strategy.name() + ") and @TimeZoneColumn"
@ -207,10 +205,16 @@ public class BasicValueHelper {
if ( columnAnn != null ) {
final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) basicValue.getColumn();
column.setName( columnAnn.getString( "name", property.getName() + "_tz" ) );
column.setSqlType( columnAnn.getString( "columnDefinition", (String) null ) );
final String name = columnAnn.getString( "name" );
if ( StringHelper.isEmpty( name ) ) {
column.setName( property.getName() + "_tz" );
}
else {
column.setName( name );
}
column.setSqlType( columnAnn.getString( "columnDefinition" ) );
final var tableName = columnAnn.getString( "table", (String) null );
final var tableName = columnAnn.getString( "table" );
TableReference tableByName = null;
if ( tableName != null ) {
final Identifier identifier = Identifier.toIdentifier( tableName );
@ -218,8 +222,8 @@ public class BasicValueHelper {
basicValue.setTable( tableByName.table() );
}
property.setInsertable( columnAnn.getBoolean( "insertable", true ) );
property.setUpdateable( columnAnn.getBoolean( "updatable", true ) );
property.setInsertable( columnAnn.getBoolean( "insertable" ) );
property.setUpdateable( columnAnn.getBoolean( "updatable" ) );
}
}
@ -283,7 +287,7 @@ public class BasicValueHelper {
final var columnAnn = member.getAnnotationUsage( annotationType );
final var column = ColumnHelper.bindColumn( columnAnn, defaultNameSupplier );
var tableName = BindingHelper.getValue( columnAnn, "table", "" );
var tableName = columnAnn.getString( "table" );
if ( StringHelper.isEmpty( tableName ) ) {
basicValue.setTable( primaryTable );
}

View File

@ -7,8 +7,6 @@
package org.hibernate.boot.models.bind.internal;
import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;
import org.hibernate.boot.model.naming.Identifier;
@ -17,18 +15,17 @@ import org.hibernate.boot.models.bind.spi.BindingOptions;
import org.hibernate.boot.models.bind.spi.BindingState;
import org.hibernate.boot.models.bind.spi.QuotedIdentifierTarget;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.models.ModelsException;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationUsage;
import static org.hibernate.boot.models.bind.ModelBindingLogging.MODEL_BINDING_LOGGER;
/**
* @author Steve Ebersole
*/
public class BindingHelper {
public static <A extends Annotation> Identifier toIdentifier(
/**
* Applies global quoting to the passed name, returning the {@linkplain Identifier} form
*/
public static Identifier toIdentifier(
String name,
QuotedIdentifierTarget target,
BindingOptions options,
@ -37,14 +34,22 @@ public class BindingHelper {
return jdbcEnvironment.getIdentifierHelper().toIdentifier( name, globallyQuoted );
}
/**
* Get a named attribute value from the annotation usage.
* The default value is used if the passed annotation usage is null.
*/
public static <T,A extends Annotation> T getValue(AnnotationUsage<A> ann, String attributeName, T defaultValue) {
if ( ann == null ) {
return defaultValue;
}
return ann.getAttributeValue( attributeName, defaultValue );
return ann.getAttributeValue( attributeName );
}
/**
* Get a named attribute value from the annotation usage.
* The attribute's default value is used if the passed annotation usage is null.
*/
public static <T,A extends Annotation> T getValue(AnnotationUsage<A> ann, String attributeName, AnnotationDescriptor<A> descriptor) {
if ( ann == null ) {
//noinspection unchecked
@ -54,12 +59,16 @@ public class BindingHelper {
return ann.getAttributeValue( attributeName );
}
/**
* Get a named attribute value from the annotation usage.
* The value from the supplier is used if the passed annotation usage is null.
*/
public static <T,A extends Annotation> T getValue(AnnotationUsage<A> ann, String attributeName, Supplier<T> defaultValueSupplier) {
if ( ann == null ) {
return defaultValueSupplier.get();
}
return ann.getAttributeValue( attributeName, defaultValueSupplier );
return ann.getAttributeValue( attributeName );
}
public static <A extends Annotation> String getGloballyQuotedValue(
@ -87,36 +96,4 @@ public class BindingHelper {
return objectNameNormalizer.applyGlobalQuoting( text );
}
public static void processSecondPassQueue(List<? extends SecondPass> secondPasses) {
if ( secondPasses == null ) {
return;
}
int processedCount = 0;
final Iterator<? extends SecondPass> secondPassItr = secondPasses.iterator();
while ( secondPassItr.hasNext() ) {
final SecondPass secondPass = secondPassItr.next();
try {
final boolean success = secondPass.process();
if ( success ) {
processedCount++;
secondPassItr.remove();
}
}
catch (Exception e) {
MODEL_BINDING_LOGGER.debug( "Error processing second pass", e );
}
}
if ( !secondPasses.isEmpty() ) {
if ( processedCount == 0 ) {
// there are second-passes in the queue, but we were not able to
// successfully process any of them. this is a non-changing
// error condition - just throw an exception
throw new ModelsException( "Unable to process second-pass list" );
}
processSecondPassQueue( secondPasses );
}
}
}

View File

@ -108,7 +108,7 @@ public class ColumnHelper {
final Formula formula = new Formula( formulaAnn.getString( "value" ) );
value.addFormula( formula );
discriminatorType = formulaAnn.getEnum( "discriminatorType", DiscriminatorType.STRING );
discriminatorType = formulaAnn.getEnum( "discriminatorType" );
}
else {
final Column column = new Column();

View File

@ -29,7 +29,6 @@ import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.bind.spi.BindingContext;
import org.hibernate.boot.models.bind.spi.BindingOptions;
import org.hibernate.boot.models.bind.spi.BindingState;
import org.hibernate.boot.models.bind.spi.TableReference;
import org.hibernate.boot.models.categorize.spi.AttributeMetadata;
import org.hibernate.boot.models.categorize.spi.EntityHierarchy;
import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata;
@ -46,7 +45,6 @@ import org.hibernate.jpa.event.spi.CallbackType;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
import org.hibernate.models.ModelsException;
import org.hibernate.models.spi.AnnotationUsage;
@ -186,8 +184,8 @@ public abstract class EntityBinding extends IdentifiableTypeBinding {
filters.forEach( (filter) -> {
persistentClass.addFilter(
filter.getString( "name" ),
filter.getString( "condition", (String) null ),
filter.getAttributeValue( "deduceAliasInjectionPoints", true ),
filter.getString( "condition" ),
filter.getAttributeValue( "deduceAliasInjectionPoints" ),
extractFilterAliasTableMap( filter ),
extractFilterAliasEntityMap( filter )
);

View File

@ -8,7 +8,6 @@ package org.hibernate.boot.models.bind.internal;
import org.hibernate.MappingException;
import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.OptimisticLocking;
import org.hibernate.annotations.SoftDelete;
import org.hibernate.annotations.SoftDeleteType;
@ -194,7 +193,7 @@ public class RootEntityBinding extends EntityBinding {
final var optimisticLocking = classDetails.getAnnotationUsage( OptimisticLocking.class );
if ( optimisticLocking != null ) {
final var optimisticLockingType = optimisticLocking.getEnum( "type", OptimisticLockType.VERSION );
final var optimisticLockingType = optimisticLocking.getEnum( "type" );
rootClass.setOptimisticLockStyle( OptimisticLockStyle.valueOf( optimisticLockingType.name() ) );
}
}

View File

@ -10,6 +10,7 @@ import java.util.Locale;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.NaturalIdCache;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.OptimisticLocking;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.categorize.ModelCategorizationLogging;
@ -266,7 +267,8 @@ public class EntityHierarchyImpl implements EntityHierarchy {
private OptimisticLockStyle determineOptimisticLockStyle(HierarchyMetadataCollector metadataCollector) {
final AnnotationUsage<OptimisticLocking> optimisticLockingAnnotation = metadataCollector.getOptimisticLockingAnnotation();
if ( optimisticLockingAnnotation != null ) {
optimisticLockingAnnotation.getEnum( "type", DEFAULT_LOCKING_STRATEGY );
final OptimisticLockType lockingType = optimisticLockingAnnotation.getEnum( "type" );
return OptimisticLockStyle.fromLockType( lockingType );
}
return DEFAULT_LOCKING_STRATEGY;
}

View File

@ -33,8 +33,6 @@ import jakarta.persistence.IdClass;
import jakarta.persistence.Inheritance;
import jakarta.persistence.Version;
import static org.hibernate.boot.models.categorize.ModelCategorizationLogging.MODEL_CATEGORIZATION_LOGGER;
/**
* Used to collect useful details about a hierarchy as we build its metadata
*
@ -257,15 +255,6 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer {
private <A extends Annotation> AnnotationUsage<A> applyLocalAnnotation(Class<A> annotationType, ClassDetails classDetails, AnnotationUsage<A> currentValue) {
final AnnotationUsage<A> localInheritanceAnnotation = classDetails.getAnnotationUsage( annotationType );
if ( localInheritanceAnnotation != null ) {
if ( currentValue != null ) {
MODEL_CATEGORIZATION_LOGGER.debugf(
"Ignoring @%s from %s in favor of usage from %s",
annotationType.getSimpleName(),
classDetails.getName(),
currentValue.getAnnotationTarget().getName()
);
}
// the one "closest" to the root-entity should win
return localInheritanceAnnotation;
}

View File

@ -146,7 +146,6 @@ public class XmlProcessingHelper {
xmlDocumentContext.getModelBuildingContext()
.getAnnotationDescriptorRegistry()
.getDescriptor( annotationType ),
target,
xmlDocumentContext.getModelBuildingContext()
);
}

View File

@ -70,7 +70,7 @@ dependencyResolutionManagement {
def byteBuddyVersion = version "byteBuddy", "1.14.18"
def classmateVersion = version "classmate", "1.5.1"
def geolatteVersion = version "geolatte", "1.9.1"
def hibernateModelsVersion = version "hibernateModels", "0.7.8"
def hibernateModelsVersion = version "hibernateModels", "0.7.9"
def jandexVersion = version "jandex", "3.2.0"
def hcannVersion = version "hcann", "7.0.1.Final"
def jacksonVersion = version "jackson", "2.17.0"