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 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).
@ -804,15 +805,13 @@ public class ModelBinder {
if ( StringHelper.isNotEmpty( unsavedValue ) ) {
identifierValue.setNullValue( unsavedValue );
}
else {
if ( "assigned".equals( identifierValue.getIdentifierGeneratorStrategy() ) ) {
else if ( DEFAULT_ID_GEN_STRATEGY.equals( identifierValue.getIdentifierGeneratorStrategy() ) ) {
identifierValue.setNullValue( "undefined" );
}
else {
identifierValue.setNullValue( null );
}
}
}
private void bindAggregatedCompositeEntityIdentifier(
MappingDocument mappingDocument,

View File

@ -75,7 +75,6 @@ import org.hibernate.cfg.annotations.PropertyBinder;
import org.hibernate.cfg.annotations.QueryBinder;
import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.GenericsHelper;
import org.hibernate.mapping.Any;
@ -1872,10 +1871,10 @@ public final class AnnotationBinder {
GeneratedValue generatedValue) {
if ( isComponent ) {
//a component must not have any generator
return "assigned";
return DEFAULT_ID_GEN_STRATEGY;
}
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.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.NOOP;
import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.interpret;
@ -362,8 +363,8 @@ public class BinderHelper {
final Component copy = new Component( context, component );
copy.setComponentClassName( component.getComponentClassName() );
copy.setEmbedded( component.isEmbedded() );
for ( Property property1 : component.getProperties()) {
copy.addProperty( cloneProperty(ownerEntity, context, property1) );
for ( Property subproperty : component.getProperties() ) {
copy.addProperty( cloneProperty( ownerEntity, context, subproperty ) );
}
copy.sortProperties();
final Property result = new SyntheticProperty();
@ -372,9 +373,8 @@ public class BinderHelper {
result.setUpdateable( false );
result.setInsertable( false );
result.setValue(copy);
final Property clone = result;
clone.setPropertyAccessorName( property.getPropertyAccessorName() );
return clone;
result.setPropertyAccessorName( property.getPropertyAccessorName() );
return result;
}
else {
final Property clone = shallowCopy( property );
@ -792,7 +792,7 @@ public class BinderHelper {
//checkIfMatchingGenerator(definition, generatorType, generatorName);
parameters.putAll( definition.getParameters() );
}
if ( "assigned".equals( generatorType ) ) {
if ( DEFAULT_ID_GEN_STRATEGY.equals( generatorType ) ) {
id.setNullValue( "undefined" );
}
id.setIdentifierGeneratorParameters( parameters );
@ -839,7 +839,7 @@ public class BinderHelper {
final GeneratedValue generatedValue = idXProperty.getAnnotation( GeneratedValue.class );
if ( generatedValue == null ) {
// 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(

View File

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

View File

@ -23,15 +23,6 @@ import jakarta.persistence.GenerationType;
* @author Steve Ebersole
*/
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
*/
@ -68,5 +59,14 @@ public interface IdentifierGeneratorFactory extends Service {
* {@link #createIdentifierGenerator(GenerationType, String, String, JavaType, Properties, GeneratorDefinitionResolver)}
*/
@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
* {@link GenerationType} possibilities.
*
* @apiNote no GenerationType indicates `hbm.xml` mapping
* @apiNote no GenerationType indicates {@code hbm.xml} mapping
*/
public interface GenerationTypeStrategy {
IdentifierGenerator createIdentifierGenerator(

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.jpa.spi;
import org.hibernate.Remove;
import java.util.Map;
/**
@ -16,7 +18,7 @@ import java.util.Map;
*
* @deprecated supply a {@link org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration} instead
*/
@Deprecated(since = "6.0")
@Deprecated(since = "6.0") @Remove
public interface IdentifierGeneratorStrategyProvider {
/**
* 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 {
boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect);
ForeignKey createForeignKeyOfEntity(String entityName);
boolean isCascadeDeleteEnabled();
@ -39,7 +37,7 @@ public interface KeyValue extends Value {
/**
* @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead.
*/
@Deprecated
@Deprecated(since="6.2")
default IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
@ -52,7 +50,7 @@ public interface KeyValue extends Value {
/**
* @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead.
*/
@Deprecated
@Deprecated(since="6.2")
default IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
@ -60,4 +58,10 @@ public interface KeyValue extends Value {
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;
}
@Deprecated
public boolean isIdentityColumn(IdentifierGeneratorFactory identifierGeneratorFactory, Dialect dialect) {
return IdentityGenerator.class.isAssignableFrom(
identifierGeneratorFactory.getIdentifierGeneratorClass( identifierGeneratorStrategy )

View File

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