Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

import jakarta.persistence.GenerationType;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.Internal;
import org.hibernate.boot.models.annotations.internal.SequenceGeneratorJpaAnnotation;
import org.hibernate.boot.models.annotations.internal.TableGeneratorJpaAnnotation;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.models.spi.TypeDetails;

import java.io.Serializable;
Expand All @@ -27,6 +25,7 @@
import static org.hibernate.boot.model.internal.GeneratorStrategies.generatorStrategy;
import static org.hibernate.boot.models.JpaAnnotations.SEQUENCE_GENERATOR;
import static org.hibernate.boot.models.JpaAnnotations.TABLE_GENERATOR;
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;

/**
Expand All @@ -49,7 +48,9 @@ public IdentifierGeneratorDefinition(
final Map<String, String> parameters) {
this.name = name;
this.strategy = strategy;
this.parameters = isEmpty( parameters ) ? emptyMap() : unmodifiableMap( parameters );
this.parameters = isEmpty( parameters )
? emptyMap()
: unmodifiableMap( parameters );
}

public IdentifierGeneratorDefinition(
Expand Down Expand Up @@ -98,52 +99,37 @@ public static IdentifierGeneratorDefinition createImplicit(
// If we were unable to locate an actual matching named generator assume
// a sequence/table of the given name, make one based on GenerationType.

if ( generationType == null ) {
generationType = GenerationType.SEQUENCE;
}

switch ( generationType ) {
case SEQUENCE:
return buildSequenceGeneratorDefinition( name );
case TABLE:
return buildTableGeneratorDefinition( name );
case IDENTITY:
throw new AnnotationException(
"@GeneratedValue annotation specified 'strategy=IDENTITY' and 'generator'"
+ " but the generator name is unnecessary"
);
case UUID:
throw new AnnotationException(
"@GeneratedValue annotation specified 'strategy=UUID' and 'generator'"
+ " but the generator name is unnecessary"
);
case AUTO:
return new IdentifierGeneratorDefinition(
name,
generatorStrategy( generationType, generatorName, idType ),
singletonMap( IdentifierGenerator.GENERATOR_NAME, name )
);
default:
throw new AssertionFailure( "unknown generator type: " + generationType );
}
return switch ( generationType == null ? GenerationType.SEQUENCE : generationType ) {
case SEQUENCE -> buildSequenceGeneratorDefinition( name );
case TABLE -> buildTableGeneratorDefinition( name );
case AUTO -> new IdentifierGeneratorDefinition(
name,
generatorStrategy( generationType, generatorName, idType ),
singletonMap( IdentifierGenerator.GENERATOR_NAME, name )
);
case IDENTITY, UUID -> throw new AnnotationException(
"@GeneratedValue annotation specified 'strategy=" + generationType
+ "' and 'generator' but the generator name is unnecessary"
);
};
}

private static IdentifierGeneratorDefinition buildTableGeneratorDefinition(String name) {
final Builder builder = new Builder();
final TableGeneratorJpaAnnotation tableGeneratorUsage = TABLE_GENERATOR.createUsage( null );
if ( StringHelper.isNotEmpty( name ) ) {
if ( isNotEmpty( name ) ) {
tableGeneratorUsage.name( name );
}
final Builder builder = new Builder();
interpretTableGenerator( tableGeneratorUsage, builder );
return builder.build();
}

private static IdentifierGeneratorDefinition buildSequenceGeneratorDefinition(String name) {
final Builder builder = new Builder();
final SequenceGeneratorJpaAnnotation sequenceGeneratorUsage = SEQUENCE_GENERATOR.createUsage( null );
if ( StringHelper.isNotEmpty( name ) ) {
if ( isNotEmpty( name ) ) {
sequenceGeneratorUsage.name( name );
}
final Builder builder = new Builder();
interpretSequenceGenerator( sequenceGeneratorUsage, builder );
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import java.util.Locale;
import java.util.Map;

import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.descriptor.java.BasicJavaType;

import org.jboss.logging.Logger;

import static org.hibernate.internal.util.StringHelper.isEmpty;

/**
* Basic implementation of {@link TypeDefinitionRegistry}.
*
Expand All @@ -38,24 +39,20 @@ public TypeDefinition resolve(String typeName) {
if ( localDefinition != null ) {
return localDefinition;
}

if ( parent != null ) {
else if ( parent != null ) {
return parent.resolve( typeName );
}

return null;
else {
return null;
}
}

@Override
public TypeDefinition resolveAutoApplied(BasicJavaType<?> jtd) {
// For now, check the definition map for a entry keyed by the JTD name.
// Ultimately should maybe have TypeDefinition or the registry keep explicit track of
// auto-applied defs
if ( jtd.getJavaType() == null ) {
return null;
}

return typeDefinitionMap.get( jtd.getTypeName() );
// For now, check the definition map for an entry keyed by the JTD name.
// Ultimately should maybe have TypeDefinition or the registry keep explicit
// track of auto-applied definitions.
return jtd.getJavaType() == null ? null : typeDefinitionMap.get( jtd.getTypeName() );
}

@Override
Expand All @@ -73,7 +70,7 @@ public TypeDefinitionRegistry register(TypeDefinition typeDefinition, Duplicatio
throw new IllegalArgumentException( "TypeDefinition to register cannot define null #typeImplementorClass" );
}

if ( !StringHelper.isEmpty( typeDefinition.getName() ) ) {
if ( !isEmpty( typeDefinition.getName() ) ) {
register( typeDefinition.getName(), typeDefinition, duplicationStrategy );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@



import static java.lang.Boolean.parseBoolean;
import static java.lang.Integer.parseInt;
import static org.hibernate.engine.config.spi.ConfigurationService.Converter;

/**
Expand All @@ -17,9 +19,9 @@ public class StandardConverters {
public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean;

public static Boolean asBoolean(Object value) {
return value instanceof Boolean
? (Boolean) value
: Boolean.parseBoolean( value.toString() );
return value instanceof Boolean bool
? bool
: parseBoolean( value.toString() );
}

public static final Converter<String> STRING = StandardConverters::asString;
Expand All @@ -31,11 +33,9 @@ public static String asString(Object value) {
public static final Converter<Integer> INTEGER = StandardConverters::asInteger;

public static Integer asInteger(Object value) {
if ( value instanceof Number ) {
return ( (Number) value ).intValue();
}

return Integer.parseInt( value.toString() );
return value instanceof Number number
? number.intValue()
: parseInt( value.toString() );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions hibernate-core/src/main/java/org/hibernate/engine/jdbc/Size.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class Size implements Serializable {

@Deprecated( forRemoval = true )
@Deprecated(forRemoval = true, since = "6.5")
public enum LobMultiplier {
NONE( 1 ),
K( NONE.factor * 1024 ),
Expand Down Expand Up @@ -62,7 +62,7 @@ public Size() {
* @param lobMultiplier LOB length multiplier
* @deprecated in favor of {@link Size#Size(Integer, Integer, Long)}
*/
@Deprecated( forRemoval = true )
@Deprecated(forRemoval = true, since = "6.5")
public Size(Integer precision, Integer scale, Long length, LobMultiplier lobMultiplier) {
this.precision = precision;
this.scale = scale;
Expand All @@ -73,7 +73,7 @@ public Size(Integer precision, Integer scale, Long length, LobMultiplier lobMult
/**
* @deprecated in favor of {@link Size#Size(Integer, Integer, Long)}
*/
@Deprecated( forRemoval = true )
@Deprecated(forRemoval = true , since = "6.5")
public Size(Integer precision, Integer scale, Integer length, LobMultiplier lobMultiplier) {
this.precision = precision;
this.scale = scale;
Expand Down Expand Up @@ -121,7 +121,7 @@ public Integer getArrayLength() {
return arrayLength;
}

@Deprecated( forRemoval = true )
@Deprecated(forRemoval = true, since = "6.5")
public LobMultiplier getLobMultiplier() {
return lobMultiplier;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public Size setArrayLength(Integer arrayLength) {
return this;
}

@Deprecated( forRemoval = true )
@Deprecated(forRemoval = true, since = "6.5")
public Size setLobMultiplier(LobMultiplier lobMultiplier) {
this.lobMultiplier = lobMultiplier;
return this;
Expand Down