minor cleanups + add a couple of @Deprecated annotations

This commit is contained in:
Gavin 2022-12-01 10:26:49 +01:00 committed by Gavin King
parent 3396c18178
commit 101bee7647
10 changed files with 52 additions and 46 deletions

View File

@ -161,6 +161,7 @@ import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType; import org.hibernate.usertype.UserType;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.mapping.SimpleValue.DEFAULT_ID_GEN_STRATEGY;
/** /**
* Responsible for coordinating the binding of all information inside entity tags ({@code <class/>}, etc). * Responsible for coordinating the binding of all information inside entity tags ({@code <class/>}, etc).
@ -804,15 +805,13 @@ public class ModelBinder {
if ( StringHelper.isNotEmpty( unsavedValue ) ) { if ( StringHelper.isNotEmpty( unsavedValue ) ) {
identifierValue.setNullValue( unsavedValue ); identifierValue.setNullValue( unsavedValue );
} }
else { else if ( DEFAULT_ID_GEN_STRATEGY.equals( identifierValue.getIdentifierGeneratorStrategy() ) ) {
if ( "assigned".equals( identifierValue.getIdentifierGeneratorStrategy() ) ) {
identifierValue.setNullValue( "undefined" ); identifierValue.setNullValue( "undefined" );
} }
else { else {
identifierValue.setNullValue( null ); identifierValue.setNullValue( null );
} }
} }
}
private void bindAggregatedCompositeEntityIdentifier( private void bindAggregatedCompositeEntityIdentifier(
MappingDocument mappingDocument, MappingDocument mappingDocument,

View File

@ -75,7 +75,6 @@ import org.hibernate.cfg.annotations.PropertyBinder;
import org.hibernate.cfg.annotations.QueryBinder; import org.hibernate.cfg.annotations.QueryBinder;
import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.GenericsHelper; import org.hibernate.internal.util.GenericsHelper;
import org.hibernate.mapping.Any; import org.hibernate.mapping.Any;
@ -1872,10 +1871,10 @@ public final class AnnotationBinder {
GeneratedValue generatedValue) { GeneratedValue generatedValue) {
if ( isComponent ) { if ( isComponent ) {
//a component must not have any generator //a component must not have any generator
return "assigned"; return DEFAULT_ID_GEN_STRATEGY;
} }
else { else {
return generatedValue == null ? "assigned" : generatorType( generatedValue, entityXClass, context ); return generatedValue == null ? DEFAULT_ID_GEN_STRATEGY : generatorType( generatedValue, entityXClass, context );
} }
} }

View File

@ -76,6 +76,7 @@ import static org.hibernate.cfg.AnnotatedColumn.buildColumnOrFormulaFromAnnotati
import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.isNotEmpty;
import static org.hibernate.internal.util.StringHelper.qualify; import static org.hibernate.internal.util.StringHelper.qualify;
import static org.hibernate.mapping.SimpleValue.DEFAULT_ID_GEN_STRATEGY;
import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED;
import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.NOOP; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.NOOP;
import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.interpret; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.interpret;
@ -362,19 +363,18 @@ public class BinderHelper {
final Component copy = new Component( context, component ); final Component copy = new Component( context, component );
copy.setComponentClassName( component.getComponentClassName() ); copy.setComponentClassName( component.getComponentClassName() );
copy.setEmbedded( component.isEmbedded() ); copy.setEmbedded( component.isEmbedded() );
for ( Property property1 : component.getProperties()) { for ( Property subproperty : component.getProperties() ) {
copy.addProperty( cloneProperty(ownerEntity, context, property1) ); copy.addProperty( cloneProperty( ownerEntity, context, subproperty ) );
} }
copy.sortProperties(); copy.sortProperties();
final Property result = new SyntheticProperty(); final Property result = new SyntheticProperty();
result.setName(property.getName()); result.setName( property.getName() );
result.setPersistentClass(ownerEntity); result.setPersistentClass( ownerEntity );
result.setUpdateable( false ); result.setUpdateable( false );
result.setInsertable( false ); result.setInsertable( false );
result.setValue(copy); result.setValue(copy);
final Property clone = result; result.setPropertyAccessorName( property.getPropertyAccessorName() );
clone.setPropertyAccessorName( property.getPropertyAccessorName() ); return result;
return clone;
} }
else { else {
final Property clone = shallowCopy( property ); final Property clone = shallowCopy( property );
@ -792,7 +792,7 @@ public class BinderHelper {
//checkIfMatchingGenerator(definition, generatorType, generatorName); //checkIfMatchingGenerator(definition, generatorType, generatorName);
parameters.putAll( definition.getParameters() ); parameters.putAll( definition.getParameters() );
} }
if ( "assigned".equals( generatorType ) ) { if ( DEFAULT_ID_GEN_STRATEGY.equals( generatorType ) ) {
id.setNullValue( "undefined" ); id.setNullValue( "undefined" );
} }
id.setIdentifierGeneratorParameters( parameters ); id.setIdentifierGeneratorParameters( parameters );
@ -839,7 +839,7 @@ public class BinderHelper {
final GeneratedValue generatedValue = idXProperty.getAnnotation( GeneratedValue.class ); final GeneratedValue generatedValue = idXProperty.getAnnotation( GeneratedValue.class );
if ( generatedValue == null ) { if ( generatedValue == null ) {
// this should really never happen, but it's easy to protect against it... // this should really never happen, but it's easy to protect against it...
return new IdentifierGeneratorDefinition( "assigned", "assigned" ); return new IdentifierGeneratorDefinition( DEFAULT_ID_GEN_STRATEGY, DEFAULT_ID_GEN_STRATEGY );
} }
return IdentifierGeneratorDefinition.createImplicit( return IdentifierGeneratorDefinition.createImplicit(

View File

@ -106,16 +106,13 @@ public class IdBagBinder extends BagBinder {
final String namedGenerator = collectionIdAnn.generator(); final String namedGenerator = collectionIdAnn.generator();
if ( "identity".equals( namedGenerator ) ) { switch (namedGenerator) {
throw new MappingException( "IDENTITY generation not supported for CollectionId" ); case "identity":
} throw new MappingException("IDENTITY generation not supported for CollectionId");
case "assigned":
if ( "assigned".equals( namedGenerator ) ) { throw new MappingException("Assigned generation not supported for CollectionId");
throw new MappingException( "Assigned generation not supported for CollectionId" ); case "native":
} throw new MappingException("Native generation not supported for CollectionId");
if ( "native".equals( namedGenerator ) ) {
throw new MappingException( "Native generation not supported for CollectionId" );
} }
final String generatorName; final String generatorName;

View File

@ -23,15 +23,6 @@ import jakarta.persistence.GenerationType;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface IdentifierGeneratorFactory extends Service { public interface IdentifierGeneratorFactory extends Service {
/**
* Get the dialect.
* @deprecated should be removed
*
* @return the dialect
*/
@Deprecated(since = "6.2", forRemoval = true)
Dialect getDialect();
/** /**
* Create an IdentifierGenerator based on the given details * Create an IdentifierGenerator based on the given details
*/ */
@ -68,5 +59,14 @@ public interface IdentifierGeneratorFactory extends Service {
* {@link #createIdentifierGenerator(GenerationType, String, String, JavaType, Properties, GeneratorDefinitionResolver)} * {@link #createIdentifierGenerator(GenerationType, String, String, JavaType, Properties, GeneratorDefinitionResolver)}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
Class getIdentifierGeneratorClass(String strategy); Class<?> getIdentifierGeneratorClass(String strategy);
/**
* Get the dialect.
* @deprecated should be removed
*
* @return the dialect
*/
@Deprecated(since = "6.2", forRemoval = true)
Dialect getDialect();
} }

View File

@ -17,7 +17,7 @@ import org.hibernate.type.descriptor.java.JavaType;
* Delegate for defining how to handle the various types of * Delegate for defining how to handle the various types of
* {@link GenerationType} possibilities. * {@link GenerationType} possibilities.
* *
* @apiNote no GenerationType indicates `hbm.xml` mapping * @apiNote no GenerationType indicates {@code hbm.xml} mapping
*/ */
public interface GenerationTypeStrategy { public interface GenerationTypeStrategy {
IdentifierGenerator createIdentifierGenerator( IdentifierGenerator createIdentifierGenerator(

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.jpa.spi; package org.hibernate.jpa.spi;
import org.hibernate.Remove;
import java.util.Map; import java.util.Map;
/** /**
@ -16,7 +18,7 @@ import java.util.Map;
* *
* @deprecated supply a {@link org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration} instead * @deprecated supply a {@link org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration} instead
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0") @Remove
public interface IdentifierGeneratorStrategyProvider { public interface IdentifierGeneratorStrategyProvider {
/** /**
* set of strategy / generator class pairs to register as accepted strategies * set of strategy / generator class pairs to register as accepted strategies

View File

@ -21,8 +21,6 @@ import org.hibernate.tuple.InMemoryGenerator;
*/ */
public interface KeyValue extends Value { public interface KeyValue extends Value {
boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect);
ForeignKey createForeignKeyOfEntity(String entityName); ForeignKey createForeignKeyOfEntity(String entityName);
boolean isCascadeDeleteEnabled(); boolean isCascadeDeleteEnabled();
@ -39,7 +37,7 @@ public interface KeyValue extends Value {
/** /**
* @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead. * @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead.
*/ */
@Deprecated @Deprecated(since="6.2")
default IdentifierGenerator createIdentifierGenerator( default IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory, IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect, Dialect dialect,
@ -52,7 +50,7 @@ public interface KeyValue extends Value {
/** /**
* @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead. * @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead.
*/ */
@Deprecated @Deprecated(since="6.2")
default IdentifierGenerator createIdentifierGenerator( default IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory, IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect, Dialect dialect,
@ -60,4 +58,10 @@ public interface KeyValue extends Value {
return (IdentifierGenerator) createGenerator( identifierGeneratorFactory, dialect, rootClass ); return (IdentifierGenerator) createGenerator( identifierGeneratorFactory, dialect, rootClass );
} }
/**
* We need to add {@code Column.isIdentity()}.
*/
@Deprecated(since="6.2")
boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect);
} }

View File

@ -445,6 +445,7 @@ public abstract class SimpleValue implements KeyValue {
this.identifierGeneratorStrategy = identifierGeneratorStrategy; this.identifierGeneratorStrategy = identifierGeneratorStrategy;
} }
@Deprecated
public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect) { public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect) {
return IdentityGenerator.class.isAssignableFrom( return IdentityGenerator.class.isAssignableFrom(
identifierGeneratorFactory.getIdentifierGeneratorClass( identifierGeneratorStrategy ) identifierGeneratorFactory.getIdentifierGeneratorClass( identifierGeneratorStrategy )

View File

@ -61,8 +61,12 @@ public class StandardTableExporter implements Exporter<Table> {
boolean isPrimaryKeyIdentity = table.hasPrimaryKey() boolean isPrimaryKeyIdentity = table.hasPrimaryKey()
&& table.getIdentifierValue() != null && table.getIdentifierValue() != null
&& table.getIdentifierValue().isIdentityColumn( ( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getIdentifierGeneratorFactory(), dialect ); && table.getIdentifierValue().isIdentityColumn(
// this is the much better form moving forward as we move to metamodel ( (MetadataImplementor) metadata ).getMetadataBuildingOptions()
.getIdentifierGeneratorFactory(),
dialect
);
// TODO: this is the much better form moving forward as we move to metamodel
//boolean isPrimaryKeyIdentity = hasPrimaryKey //boolean isPrimaryKeyIdentity = hasPrimaryKey
// && table.getPrimaryKey().getColumnSpan() == 1 // && table.getPrimaryKey().getColumnSpan() == 1
// && table.getPrimaryKey().getColumn( 0 ).isIdentity(); // && table.getPrimaryKey().getColumn( 0 ).isIdentity();