rename Generator subtypes to BeforeExecuteGenerator and OnExecuteGenerator

- and update javadocs
- add/improve doc of new Dialect methods
- add some missing @Override annotations
This commit is contained in:
Gavin 2022-12-20 02:40:49 +01:00 committed by Gavin King
parent f3e31fe427
commit 64d0cf804a
47 changed files with 247 additions and 202 deletions

View File

@ -23,7 +23,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* <p> * <p>
* For example, if we have a custom identifier generator: * For example, if we have a custom identifier generator:
* <pre>{@code * <pre>{@code
* public class CustomSequenceGenerator implements InMemoryGenerator { * public class CustomSequenceGenerator implements BeforeExecutionGenerator {
* public CustomSequenceGenerator(CustomSequence config, Member annotatedMember, * public CustomSequenceGenerator(CustomSequence config, Member annotatedMember,
* CustomIdGeneratorCreationContext context) { * CustomIdGeneratorCreationContext context) {
* ... * ...

View File

@ -12,8 +12,8 @@ import java.lang.annotation.Target;
import org.hibernate.generator.AnnotationBasedGenerator; import org.hibernate.generator.AnnotationBasedGenerator;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.internal.TenantIdGeneration; import org.hibernate.generator.internal.TenantIdGeneration;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
@ -50,9 +50,9 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* Every generator annotation type has an {@link Generator} implementation which * Every generator annotation type has an {@link Generator} implementation which
* is responsible for generating values. It must be either: * is responsible for generating values. It must be either:
* <ul> * <ul>
* <li>an {@link InMemoryGenerator}, for values that are generated in Java code, * <li>an {@link BeforeExecutionGenerator}, for values that are generated in Java code,
* using a {@link org.hibernate.tuple.ValueGenerator}, or * using a {@link org.hibernate.tuple.ValueGenerator}, or
* <li>an {@link InDatabaseGenerator}, for values which are generated by the * <li>an {@link OnExecutionGenerator}, for values which are generated by the
* database. * database.
* </ul> * </ul>
* A generator annotation may have members, which are used to configure the * A generator annotation may have members, which are used to configure the
@ -70,8 +70,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* {@link RetentionPolicy#RUNTIME}. * {@link RetentionPolicy#RUNTIME}.
* *
* @see Generator * @see Generator
* @see InMemoryGenerator * @see BeforeExecutionGenerator
* @see InDatabaseGenerator * @see OnExecutionGenerator
* @see AnnotationBasedGenerator * @see AnnotationBasedGenerator
* *
* @author Gunnar Morling * @author Gunnar Morling

View File

@ -49,8 +49,8 @@ import org.hibernate.generator.AnnotationBasedGenerator;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.binder.AttributeBinder; import org.hibernate.binder.AttributeBinder;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@ -452,10 +452,10 @@ public class PropertyBinder {
} }
private static void checkGeneratorClass(Class<? extends Generator> generatorClass) { private static void checkGeneratorClass(Class<? extends Generator> generatorClass) {
if ( !InMemoryGenerator.class.isAssignableFrom( generatorClass ) if ( !BeforeExecutionGenerator.class.isAssignableFrom( generatorClass )
&& !InDatabaseGenerator.class.isAssignableFrom( generatorClass ) ) { && !OnExecutionGenerator.class.isAssignableFrom( generatorClass ) ) {
throw new MappingException("Generator class '" + generatorClass.getName() throw new MappingException("Generator class '" + generatorClass.getName()
+ "' must implement either 'InMemoryGenerator' or 'InDatabaseGenerator'"); + "' must implement either 'BeforeExecutionGenerator' or 'OnExecutionGenerator'");
} }
} }

View File

@ -3436,17 +3436,47 @@ public abstract class Dialect implements ConversionContext {
} }
/** /**
* Does this dialect fully support {@code insert ... returning ...} in some form? * Does this dialect fully support returning arbitrary generated column values
* after execution of an {@code insert} statement, using native SQL syntax?
* <p>
* Support for identity columns is insufficient here, we require something like:
* <ol>
* <li>{@code insert ... returning ...}
* <li>{@code select from final table (insert ... )}
* </ol>
* *
* @return {@code true} if {@link org.hibernate.id.insert.InsertReturningDelegate} * @return {@code true} if {@link org.hibernate.id.insert.InsertReturningDelegate}
* works for any sort of primary key column (not just identity columns), or * works for any sort of primary key column (not just identity columns), or
* {@code false} if {@code InsertReturningDelegate} does not work, or only * {@code false} if {@code InsertReturningDelegate} does not work, or only
* works for specialized identity/"autoincrement" columns * works for specialized identity/"autoincrement" columns
*
* @see org.hibernate.generator.OnExecutionGenerator#getGeneratedIdentifierDelegate
* @see org.hibernate.id.insert.InsertReturningDelegate
*
* @since 6.2
*/ */
public boolean supportsInsertReturning() { public boolean supportsInsertReturning() {
return false; return false;
} }
/**
* Does this dialect fully support returning arbitrary generated column values
* after execution of an {@code insert} statement, using the JDBC method
* {@link Connection#prepareStatement(String, String[])}.
* <p>
* Support for returning the generated value of an identity column via the JDBC
* method {@link Connection#prepareStatement(String, int)} is insufficient here.
*
* @return {@code true} if {@link org.hibernate.id.insert.GetGeneratedKeysDelegate}
* works for any sort of primary key column (not just identity columns), or
* {@code false} if {@code GetGeneratedKeysDelegate} does not work, or only
* works for specialized identity/"autoincrement" columns
*
* @see org.hibernate.generator.OnExecutionGenerator#getGeneratedIdentifierDelegate
* @see org.hibernate.id.insert.GetGeneratedKeysDelegate
*
* @since 6.2
*/
public boolean supportsInsertReturningGeneratedKeys() { public boolean supportsInsertReturningGeneratedKeys() {
return false; return false;
} }

View File

@ -274,7 +274,7 @@ public class TemporaryTable implements Exportable, Contributable {
.getEntityBinding( entityDescriptor.getEntityName() ); .getEntityBinding( entityDescriptor.getEntityName() );
final Generator identifierGenerator = entityDescriptor.getEntityPersister().getGenerator(); final Generator identifierGenerator = entityDescriptor.getEntityPersister().getGenerator();
final boolean identityColumn = identifierGenerator.generatedByDatabase(); final boolean identityColumn = identifierGenerator.generatedOnExecute();
final boolean hasOptimizer; final boolean hasOptimizer;
if ( identityColumn ) { if ( identityColumn ) {
hasOptimizer = false; hasOptimizer = false;

View File

@ -33,7 +33,7 @@ import org.hibernate.jpa.event.spi.CallbackRegistryConsumer;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper; import org.hibernate.type.TypeHelper;
@ -116,8 +116,8 @@ public abstract class AbstractSaveEventListener<C>
final EntityPersister persister = source.getEntityPersister( entityName, entity ); final EntityPersister persister = source.getEntityPersister( entityName, entity );
Generator generator = persister.getGenerator(); Generator generator = persister.getGenerator();
if ( !generator.generatedByDatabase() ) { if ( !generator.generatedOnExecute() ) {
final Object generatedId = ( (InMemoryGenerator) generator ).generate( source, entity, null, INSERT ); final Object generatedId = ( (BeforeExecutionGenerator) generator ).generate( source, entity, null, INSERT );
if ( generatedId == null ) { if ( generatedId == null ) {
throw new IdentifierGenerationException( "null id generated for: " + entity.getClass() ); throw new IdentifierGenerationException( "null id generated for: " + entity.getClass() );
} }

View File

@ -29,8 +29,8 @@ import java.lang.reflect.Member;
* {@code AnnotationType} is the generator annotation type used to configure the * {@code AnnotationType} is the generator annotation type used to configure the
* generator. * generator.
* <p> * <p>
* Every instance of this class must implement either {@link InMemoryGenerator} or * Every instance of this class must implement either {@link BeforeExecutionGenerator} or
* {@link InDatabaseGenerator}. * {@link OnExecutionGenerator}.
* *
* @param <A> The generator annotation type supported by an implementation * @param <A> The generator annotation type supported by an implementation
* *

View File

@ -15,7 +15,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
* database via a parameter of a JDBC prepared statement, just like any other field or property * database via a parameter of a JDBC prepared statement, just like any other field or property
* value. * value.
* <p> * <p>
* Any {@link InMemoryGenerator} with {@linkplain #getEventTypes() generation event types} * Any {@link BeforeExecutionGenerator} with {@linkplain #getEventTypes() generation event types}
* {@link EventTypeSets#INSERT_ONLY} may be used to produce {@linkplain jakarta.persistence.Id * {@link EventTypeSets#INSERT_ONLY} may be used to produce {@linkplain jakarta.persistence.Id
* identifiers}. The built-in identifier generators all implement the older extension point * identifiers}. The built-in identifier generators all implement the older extension point
* {@link org.hibernate.id.IdentifierGenerator}, which is a subtype of this interface, but that * {@link org.hibernate.id.IdentifierGenerator}, which is a subtype of this interface, but that
@ -30,10 +30,11 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
* {@link org.hibernate.annotations.ValueGenerationType}, as for any {@link Generator}. * {@link org.hibernate.annotations.ValueGenerationType}, as for any {@link Generator}.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Gavin King
* *
* @since 6.2 * @since 6.2
*/ */
public interface InMemoryGenerator extends Generator { public interface BeforeExecutionGenerator extends Generator {
/** /**
* Generate a value. * Generate a value.
* *
@ -45,7 +46,8 @@ public interface InMemoryGenerator extends Generator {
*/ */
Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType); Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType);
default boolean generatedByDatabase() { @Override
default boolean generatedOnExecute() {
return false; return false;
} }
} }

View File

@ -7,7 +7,6 @@
package org.hibernate.generator; package org.hibernate.generator;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.tuple.ValueGenerator;
import java.io.Serializable; import java.io.Serializable;
import java.util.EnumSet; import java.util.EnumSet;
@ -18,18 +17,22 @@ import static org.hibernate.generator.EventType.UPDATE;
/** /**
* Describes the generation of values of a certain field or property of an entity. A generated * Describes the generation of values of a certain field or property of an entity. A generated
* value might be generated in Java, or by the database. Every instance must implement either * value might be generated in Java, or by the database. Every instance must implement either
* {@link InMemoryGenerator} or {@link InDatabaseGenerator} depending on whether values are * {@link BeforeExecutionGenerator} or {@link OnExecutionGenerator} depending on whether values
* generated in Java code, or by the database. * are generated in Java code before execution of a SQL statement, or by the database when the
* SQL statement is executed.
* <ul> * <ul>
* <li>Value generation via arbitrary code written in Java is the responsibility of the method * <li>Value generation via arbitrary code written in Java is the responsibility of the method
* {@link InMemoryGenerator#generate(SharedSessionContractImplementor, Object, Object, EventType)}. * {@link BeforeExecutionGenerator#generate(SharedSessionContractImplementor, Object, Object, EventType)}.
* In this case, the generated value is written to the database just like any other field * In this case, the generated value is written to the database just like any other field
* or property value. * or property value. The Java code may, of course, ask the database to actually generate
* the value. Examples include timestamp generation using the JVM system time, and id
* generation using a database sequence.
* <li>A value generated by the database might be generated implicitly, by a trigger, or using * <li>A value generated by the database might be generated implicitly, by a trigger, or using
* a {@code default} column value specified in DDL, for example, or it might be generated * a {@code default} column value specified in DDL, for example, or it might be generated
* by a SQL expression occurring explicitly in the SQL {@code insert} or {@code update} * by a SQL expression occurring explicitly in the SQL {@code insert} or {@code update}
* statement. In this case, the generated value is retrieved from the database using a SQL * statement. In this case, the generated value may be retrieved from the database using a
* {@code select}. * SQL {@code select}, though in certain cases this additional round trip may be avoided.
* An important example is id generation using an identity column.
* </ul> * </ul>
* Generically, a generator may be integrated with the program using the meta-annotation * Generically, a generator may be integrated with the program using the meta-annotation
* {@link org.hibernate.annotations.ValueGenerationType}, which associates the generator with * {@link org.hibernate.annotations.ValueGenerationType}, which associates the generator with
@ -71,12 +74,20 @@ import static org.hibernate.generator.EventType.UPDATE;
*/ */
public interface Generator extends Serializable { public interface Generator extends Serializable {
/** /**
* Determines if the property value is generated in Java, or by the database. * Determines if the property value is generated in Java code, or by the database.
* <ul>
* <li>Generators which only implement {@link BeforeExecutionGenerator} must result
* {@code false}.
* <li>Generators which only implement {@link OnExecutionGenerator} must result
* {@code true}.
* <li>Generators which implement both subinterfaces may decide at runtime what value
* to return.
* </ul>
* *
* @return {@code true} if the value is generated by the database, or false if it is * @return {@code true} if the value is generated by the database, or false if it is
* generated in Java using a {@link ValueGenerator}. * generated in Java code.
*/ */
boolean generatedByDatabase(); boolean generatedOnExecute();
/** /**
* The {@linkplain EventType event types} for which this generator should be called * The {@linkplain EventType event types} for which this generator should be called

View File

@ -18,11 +18,18 @@ import org.hibernate.persister.entity.EntityPersister;
import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPropertyNames; import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPropertyNames;
/** /**
* A generator which produces a new value by actually going ahead and writing a row to the
* database, then retrieving the value which was generated by the database itself as a side
* effect of the SQL {@code insert} or {@code update} statement which wrote the row.
* <p>
* A value generated by the database might be generated implicitly, by a trigger, or using * A value generated by the database might be generated implicitly, by a trigger, or using
* a {@code default} column value specified in DDL, for example, or it might be generated * a {@code default} column value specified in DDL, for example, or it might be generated
* by a SQL expression occurring explicitly in the SQL {@code insert} or {@code update} * by a SQL expression occurring explicitly in the SQL {@code insert} or {@code update}
* statement. In this case, the generated value is retrieved from the database using a SQL * statement.
* {@code select}. * <p>
* The generated value is usually retrieved from the database using a SQL {@code select},
* but in {@linkplain #getGeneratedIdentifierDelegate certain cases} this additional round
* trip may be avoided.
* <p> * <p>
* Implementations should override {@link #referenceColumnsInSql(Dialect)}, * Implementations should override {@link #referenceColumnsInSql(Dialect)},
* {@link #writePropertyValue()}, and {@link #getReferencedColumnValues(Dialect)} as needed * {@link #writePropertyValue()}, and {@link #getReferencedColumnValues(Dialect)} as needed
@ -34,10 +41,11 @@ import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPrope
* implementation of {@link org.hibernate.id.insert.InsertGeneratedIdentifierDelegate}. * implementation of {@link org.hibernate.id.insert.InsertGeneratedIdentifierDelegate}.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Gavin King
* *
* @since 6.2 * @since 6.2
*/ */
public interface InDatabaseGenerator extends Generator { public interface OnExecutionGenerator extends Generator {
/** /**
* Determines if the columns whose values are generated are included in the column list * Determines if the columns whose values are generated are included in the column list
@ -133,7 +141,8 @@ public interface InDatabaseGenerator extends Generator {
return getNaturalIdPropertyNames( persister ); return getNaturalIdPropertyNames( persister );
} }
default boolean generatedByDatabase() { @Override
default boolean generatedOnExecute() {
return true; return true;
} }
} }

View File

@ -14,8 +14,8 @@ import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.GenerationTiming;
@ -46,7 +46,7 @@ import static org.hibernate.generator.EventTypeSets.fromArray;
* @author Steve Ebersole * @author Steve Ebersole
* @author Gavin King * @author Gavin King
*/ */
public class CurrentTimestampGeneration implements InMemoryGenerator, InDatabaseGenerator { public class CurrentTimestampGeneration implements BeforeExecutionGenerator, OnExecutionGenerator {
private final EnumSet<EventType> eventTypes; private final EnumSet<EventType> eventTypes;
private final ValueGenerator<?> generator; private final ValueGenerator<?> generator;
@ -80,7 +80,7 @@ public class CurrentTimestampGeneration implements InMemoryGenerator, InDatabase
} }
@Override @Override
public boolean generatedByDatabase() { public boolean generatedOnExecute() {
return generator == null; return generator == null;
} }

View File

@ -9,7 +9,7 @@ package org.hibernate.generator.internal;
import org.hibernate.annotations.GeneratedColumn; import org.hibernate.annotations.GeneratedColumn;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import java.util.EnumSet; import java.util.EnumSet;
@ -20,7 +20,7 @@ import static org.hibernate.generator.EventTypeSets.ALL;
* *
* @author Gavin King * @author Gavin King
*/ */
public class GeneratedAlwaysGeneration implements InDatabaseGenerator { public class GeneratedAlwaysGeneration implements OnExecutionGenerator {
public GeneratedAlwaysGeneration() {} public GeneratedAlwaysGeneration() {}

View File

@ -10,7 +10,7 @@ import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime; import org.hibernate.annotations.GenerationTime;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import java.util.EnumSet; import java.util.EnumSet;
@ -18,7 +18,7 @@ import static org.hibernate.generator.EventTypeSets.fromArray;
import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.internal.util.StringHelper.isEmpty;
/** /**
* A fairly generic {@link InDatabaseGenerator} which marks a property as generated in the * A fairly generic {@link OnExecutionGenerator} which marks a property as generated in the
* database with semantics given explicitly by a {@link Generated @Generated} annotation. * database with semantics given explicitly by a {@link Generated @Generated} annotation.
* *
* @see Generated * @see Generated
@ -26,7 +26,7 @@ import static org.hibernate.internal.util.StringHelper.isEmpty;
* @author Steve Ebersole * @author Steve Ebersole
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class GeneratedGeneration implements InDatabaseGenerator { public class GeneratedGeneration implements OnExecutionGenerator {
private final EnumSet<EventType> eventTypes; private final EnumSet<EventType> eventTypes;
private final boolean writable; private final boolean writable;

View File

@ -17,7 +17,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.EventTypeSets;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.tuple.TimestampGenerators; import org.hibernate.tuple.TimestampGenerators;
import org.hibernate.tuple.ValueGenerator; import org.hibernate.tuple.ValueGenerator;
@ -52,7 +52,7 @@ import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
*/ */
@Deprecated(since = "6.2") @Deprecated(since = "6.2")
@Internal @Internal
public class SourceGeneration implements InMemoryGenerator { public class SourceGeneration implements BeforeExecutionGenerator {
private static final CoreMessageLogger log = Logger.getMessageLogger( private static final CoreMessageLogger log = Logger.getMessageLogger(
CoreMessageLogger.class, CoreMessageLogger.class,

View File

@ -14,7 +14,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.EventTypeSets;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.JavaType;
@ -30,7 +30,7 @@ import static org.hibernate.internal.util.ReflectHelper.getPropertyType;
* *
* @author Gavin King * @author Gavin King
*/ */
public class TenantIdGeneration implements InMemoryGenerator { public class TenantIdGeneration implements BeforeExecutionGenerator {
private final String entityName; private final String entityName;
private final String propertyName; private final String propertyName;

View File

@ -8,7 +8,7 @@ package org.hibernate.generator.internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.metamodel.mapping.EntityVersionMapping; import org.hibernate.metamodel.mapping.EntityVersionMapping;
import java.util.EnumSet; import java.util.EnumSet;
@ -31,7 +31,7 @@ import static org.hibernate.generator.EventTypeSets.INSERT_AND_UPDATE;
* *
* @author Gavin King * @author Gavin King
*/ */
public class VersionGeneration implements InMemoryGenerator { public class VersionGeneration implements BeforeExecutionGenerator {
private final EntityVersionMapping versionMapping; private final EntityVersionMapping versionMapping;
public VersionGeneration(EntityVersionMapping versionMapping) { public VersionGeneration(EntityVersionMapping versionMapping) {

View File

@ -18,7 +18,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.EventTypeSets;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import static org.hibernate.generator.EventTypeSets.INSERT_ONLY; import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
@ -26,15 +26,15 @@ import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
/** /**
* A classic extension point from the very earliest days of Hibernate, * A classic extension point from the very earliest days of Hibernate,
* this interface is no longer the only way to generate identifiers. Any * this interface is no longer the only way to generate identifiers. Any
* {@link InMemoryGenerator} with timing {@link EventTypeSets#INSERT_ONLY} * {@link BeforeExecutionGenerator} with timing {@link EventTypeSets#INSERT_ONLY}
* may now be used. * may now be used.
* <p> * <p>
* This interface extends {@code InMemoryGenerator} with some additional * This interface extends {@code BeforeExecutionGenerator} with some additional
* machinery for {@linkplain #configure configuration}, and for caching * machinery for {@linkplain #configure configuration}, and for caching
* {@linkplain #initialize(SqlStringGenerationContext) generated SQL}. * {@linkplain #initialize(SqlStringGenerationContext) generated SQL}.
* <p> * <p>
* Any identifier generator, including a generator which directly implements * Any identifier generator, including a generator which directly implements
* {@code InMemoryGenerator}, may also implement {@link ExportableProducer}. * {@code BeforeExecutionGenerator}, may also implement {@link ExportableProducer}.
* For the sake of convenience, {@code PersistentIdentifierGenerator} extends * For the sake of convenience, {@code PersistentIdentifierGenerator} extends
* {@code ExportableProducer}, in case the implementation needs to export * {@code ExportableProducer}, in case the implementation needs to export
* objects to the database as part of the process of schema export. * objects to the database as part of the process of schema export.
@ -60,7 +60,7 @@ import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
* @see PostInsertIdentifierGenerator * @see PostInsertIdentifierGenerator
* @see PersistentIdentifierGenerator * @see PersistentIdentifierGenerator
*/ */
public interface IdentifierGenerator extends InMemoryGenerator, ExportableProducer, Configurable { public interface IdentifierGenerator extends BeforeExecutionGenerator, ExportableProducer, Configurable {
/** /**
* The configuration parameter holding the entity name * The configuration parameter holding the entity name
*/ */

View File

@ -8,13 +8,13 @@ package org.hibernate.id;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.id.factory.spi.StandardGenerator; import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.id.insert.BasicSelectingDelegate; import org.hibernate.id.insert.BasicSelectingDelegate;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.id.insert.InsertReturningDelegate; import org.hibernate.id.insert.InsertReturningDelegate;
/** /**
* An {@link InDatabaseGenerator} that handles {@code IDENTITY}/"autoincrement" columns * An {@link OnExecutionGenerator} that handles {@code IDENTITY}/"autoincrement" columns
* on those databases which support them. * on those databases which support them.
* <p> * <p>
* Delegates to the {@link org.hibernate.dialect.identity.IdentityColumnSupport} provided * Delegates to the {@link org.hibernate.dialect.identity.IdentityColumnSupport} provided

View File

@ -9,7 +9,7 @@ package org.hibernate.id;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.EventTypeSets;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import java.util.EnumSet; import java.util.EnumSet;
@ -20,14 +20,14 @@ import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
/** /**
* The counterpart to {@link IdentifierGenerator} for values generated by the database. * The counterpart to {@link IdentifierGenerator} for values generated by the database.
* This interface is no longer the only way to handle database-generate identifiers. * This interface is no longer the only way to handle database-generate identifiers.
* Any {@link InDatabaseGenerator} with timing {@link EventTypeSets#INSERT_ONLY} may now * Any {@link OnExecutionGenerator} with timing {@link EventTypeSets#INSERT_ONLY} may now
* be used. * be used.
* *
* @see IdentifierGenerator * @see IdentifierGenerator
* *
* @author Gavin King * @author Gavin King
*/ */
public interface PostInsertIdentifierGenerator extends InDatabaseGenerator, Configurable { public interface PostInsertIdentifierGenerator extends OnExecutionGenerator, Configurable {
/** /**
* @return {@link EventTypeSets#INSERT_ONLY} * @return {@link EventTypeSets#INSERT_ONLY}

View File

@ -9,7 +9,7 @@ package org.hibernate.id;
import java.util.Properties; import java.util.Properties;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.id.factory.spi.StandardGenerator; import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
@ -64,7 +64,7 @@ import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPrope
* {@link org.hibernate.id.insert.UniqueKeySelectingDelegate}. * {@link org.hibernate.id.insert.UniqueKeySelectingDelegate}.
* <p> * <p>
* Arguably, this class breaks the natural separation of responsibility between the * Arguably, this class breaks the natural separation of responsibility between the
* {@linkplain InDatabaseGenerator generator} and the coordinating code, since its * {@linkplain OnExecutionGenerator generator} and the coordinating code, since its
* role is to specify how the generated value is <em>retrieved</em>. * role is to specify how the generated value is <em>retrieved</em>.
* *
* @see org.hibernate.annotations.NaturalId * @see org.hibernate.annotations.NaturalId

View File

@ -15,7 +15,7 @@ import org.hibernate.jdbc.Expectation;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder; import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard; import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
/** /**
* Delegate for dealing with {@code IDENTITY} columns where the dialect requires an * Delegate for dealing with {@code IDENTITY} columns where the dialect requires an
@ -34,7 +34,7 @@ public class BasicSelectingDelegate extends AbstractSelectingDelegate {
@Override @Deprecated @Override @Deprecated
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) { public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect ); IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect );
insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (InDatabaseGenerator) persister.getGenerator() ); insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (OnExecutionGenerator) persister.getGenerator() );
return insert; return insert;
} }
@ -46,7 +46,7 @@ public class BasicSelectingDelegate extends AbstractSelectingDelegate {
final TableInsertBuilder builder = final TableInsertBuilder builder =
new TableInsertBuilderStandard( persister, persister.getIdentifierTableMapping(), factory ); new TableInsertBuilderStandard( persister, persister.getIdentifierTableMapping(), factory );
final InDatabaseGenerator generator = (InDatabaseGenerator) persister.getGenerator(); final OnExecutionGenerator generator = (OnExecutionGenerator) persister.getGenerator();
if ( generator.referenceColumnsInSql( dialect ) ) { if ( generator.referenceColumnsInSql( dialect ) ) {
final String[] columnNames = persister.getRootTableKeyColumnNames(); final String[] columnNames = persister.getRootTableKeyColumnNames();
final String[] columnValues = generator.getReferencedColumnValues( dialect ); final String[] columnValues = generator.getReferencedColumnValues( dialect );

View File

@ -26,7 +26,7 @@ import org.hibernate.jdbc.Expectation;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder; import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard; import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import static java.sql.Statement.RETURN_GENERATED_KEYS; import static java.sql.Statement.RETURN_GENERATED_KEYS;
import static org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity; import static org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity;
@ -52,7 +52,7 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
@Override @Deprecated @Override @Deprecated
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) { public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect ); IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect );
insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (InDatabaseGenerator) persister.getGenerator() ); insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (OnExecutionGenerator) persister.getGenerator() );
return insert; return insert;
} }
@ -64,7 +64,7 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
final TableInsertBuilder builder = final TableInsertBuilder builder =
new TableInsertBuilderStandard( persister, persister.getIdentifierTableMapping(), factory ); new TableInsertBuilderStandard( persister, persister.getIdentifierTableMapping(), factory );
final InDatabaseGenerator generator = (InDatabaseGenerator) persister.getGenerator(); final OnExecutionGenerator generator = (OnExecutionGenerator) persister.getGenerator();
if ( generator.referenceColumnsInSql( dialect ) ) { if ( generator.referenceColumnsInSql( dialect ) ) {
final String[] columnNames = persister.getRootTableKeyColumnNames(); final String[] columnNames = persister.getRootTableKeyColumnNames();
final String[] columnValues = generator.getReferencedColumnValues( dialect ); final String[] columnValues = generator.getReferencedColumnValues( dialect );

View File

@ -19,7 +19,7 @@ import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
/** /**
* Each implementation defines a strategy for retrieving a primary key * Each implementation defines a strategy for retrieving a primary key
* {@linkplain org.hibernate.generator.InDatabaseGenerator generated by * {@linkplain org.hibernate.generator.OnExecutionGenerator generated by
* the database} from the database after execution of an {@code insert} * the database} from the database after execution of an {@code insert}
* statement. The generated primary key is usually an {@code IDENTITY} * statement. The generated primary key is usually an {@code IDENTITY}
* column, but in principle it might be something else, for example, * column, but in principle it might be something else, for example,
@ -31,9 +31,9 @@ import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
* <li>retrieving the generated identifier value using JDBC. * <li>retrieving the generated identifier value using JDBC.
* </ul> * </ul>
* The implementation should be written to handle any instance of * The implementation should be written to handle any instance of
* {@link org.hibernate.generator.InDatabaseGenerator}. * {@link org.hibernate.generator.OnExecutionGenerator}.
* *
* @see org.hibernate.generator.InDatabaseGenerator * @see org.hibernate.generator.OnExecutionGenerator
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */

View File

@ -21,7 +21,7 @@ import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.jdbc.Expectation; import org.hibernate.jdbc.Expectation;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder; import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import static java.sql.Statement.NO_GENERATED_KEYS; import static java.sql.Statement.NO_GENERATED_KEYS;
import static org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity; import static org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity;
@ -46,7 +46,7 @@ public class InsertReturningDelegate extends AbstractReturningDelegate {
@Override @Deprecated @Override @Deprecated
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) { public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
InsertSelectIdentityInsert insert = new InsertSelectIdentityInsert( dialect ); InsertSelectIdentityInsert insert = new InsertSelectIdentityInsert( dialect );
insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (InDatabaseGenerator) persister.getGenerator() ); insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (OnExecutionGenerator) persister.getGenerator() );
return insert; return insert;
} }

View File

@ -8,7 +8,7 @@ package org.hibernate.id.insert;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.sql.Insert; import org.hibernate.sql.Insert;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
/** /**
* Specialized {@link IdentifierGeneratingInsert} which appends the database * Specialized {@link IdentifierGeneratingInsert} which appends the database
@ -26,7 +26,7 @@ public class InsertSelectIdentityInsert extends IdentifierGeneratingInsert {
} }
@Override @Override
public Insert addGeneratedColumns(String[] columnNames, InDatabaseGenerator generator) { public Insert addGeneratedColumns(String[] columnNames, OnExecutionGenerator generator) {
if ( columnNames.length != 1 ) { if ( columnNames.length != 1 ) {
//TODO: Should this allow multiple columns? Would require changing //TODO: Should this allow multiple columns? Would require changing
// IdentityColumnSupport.appendIdentitySelectToInsert() // IdentityColumnSupport.appendIdentitySelectToInsert()

View File

@ -15,7 +15,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.EventTypeSets;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.type.descriptor.java.UUIDJavaType; import org.hibernate.type.descriptor.java.UUIDJavaType;
import org.hibernate.type.descriptor.java.UUIDJavaType.ValueTransformer; import org.hibernate.type.descriptor.java.UUIDJavaType.ValueTransformer;
@ -28,7 +28,7 @@ import static org.hibernate.internal.util.ReflectHelper.getPropertyType;
* *
* @see org.hibernate.annotations.UuidGenerator * @see org.hibernate.annotations.UuidGenerator
*/ */
public class UuidGenerator implements InMemoryGenerator { public class UuidGenerator implements BeforeExecutionGenerator {
interface ValueGenerator { interface ValueGenerator {
UUID generateUuid(SharedSessionContractImplementor session); UUID generateUuid(SharedSessionContractImplementor session);
} }

View File

@ -33,7 +33,7 @@ import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
import jakarta.transaction.SystemException; import jakarta.transaction.SystemException;
@ -101,8 +101,8 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen
final Object id; final Object id;
final Object[] state = persister.getValues( entity ); final Object[] state = persister.getValues( entity );
final Generator generator = persister.getGenerator(); final Generator generator = persister.getGenerator();
if ( !generator.generatedByDatabase() ) { if ( !generator.generatedOnExecute() ) {
id = ( (InMemoryGenerator) generator).generate( this, entity, null, INSERT ); id = ( (BeforeExecutionGenerator) generator).generate( this, entity, null, INSERT );
if ( persister.isVersioned() ) { if ( persister.isVersioned() ) {
if ( seedVersion( entity, state, persister, this ) ) { if ( seedVersion( entity, state, persister, this ) ) {
persister.setValues( entity, state ); persister.setValues( entity, state );

View File

@ -27,7 +27,6 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.CompositeNestedGeneratedValueGenerator; import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
@ -38,7 +37,7 @@ import org.hibernate.internal.util.collections.JoinedIterator;
import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.metamodel.spi.EmbeddableInstantiator;
import org.hibernate.property.access.spi.Setter; import org.hibernate.property.access.spi.Setter;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.type.ComponentType; import org.hibernate.type.ComponentType;
import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -640,8 +639,8 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
@Override @Override
public void execute(SharedSessionContractImplementor session, Object incomingObject, Object injectionContext) { public void execute(SharedSessionContractImplementor session, Object incomingObject, Object injectionContext) {
if ( !subgenerator.generatedByDatabase() ) { if ( !subgenerator.generatedOnExecute() ) {
Object generatedId = ( (InMemoryGenerator) subgenerator).generate( session, incomingObject, null, INSERT ); Object generatedId = ( (BeforeExecutionGenerator) subgenerator).generate( session, incomingObject, null, INSERT );
injector.set( injectionContext, generatedId ); injector.set( injectionContext, generatedId );
} }
else { else {

View File

@ -28,7 +28,7 @@ public interface GeneratedValueResolver {
// else { // else {
// return generator.generatedByDatabase() // return generator.generatedByDatabase()
// ? new InDatabaseGeneratedValueResolver( requestedTiming, dbSelectionPosition ) // in-db generation (column-default, function, etc) // ? new InDatabaseGeneratedValueResolver( requestedTiming, dbSelectionPosition ) // in-db generation (column-default, function, etc)
// : new InMemoryGeneratedValueResolver( (InMemoryGenerator) generator, requestedTiming ); // : new InMemoryGeneratedValueResolver( (BeforeExecutionGenerator) generator, requestedTiming );
// } // }
// } // }

View File

@ -9,7 +9,7 @@ package org.hibernate.metamodel.mapping;
import org.hibernate.Internal; import org.hibernate.Internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
/** /**
* GeneratedValueResolver impl for in-memory generation * GeneratedValueResolver impl for in-memory generation
@ -19,9 +19,9 @@ import org.hibernate.generator.InMemoryGenerator;
@Internal @Internal
public class InMemoryGeneratedValueResolver implements GeneratedValueResolver { public class InMemoryGeneratedValueResolver implements GeneratedValueResolver {
private final EventType eventType; private final EventType eventType;
private final InMemoryGenerator generator; private final BeforeExecutionGenerator generator;
public InMemoryGeneratedValueResolver(InMemoryGenerator generator, EventType eventType) { public InMemoryGeneratedValueResolver(BeforeExecutionGenerator generator, EventType eventType) {
this.generator = generator; this.generator = generator;
this.eventType = eventType; this.eventType = eventType;
} }

View File

@ -16,7 +16,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.loader.ast.internal.LoaderSelectBuilder; import org.hibernate.loader.ast.internal.LoaderSelectBuilder;
import org.hibernate.loader.ast.internal.NoCallbackExecutionContext; import org.hibernate.loader.ast.internal.NoCallbackExecutionContext;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
@ -35,14 +35,14 @@ import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.FILTER; import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.FILTER;
/** /**
* Responsible for retrieving {@linkplain InDatabaseGenerator * Responsible for retrieving {@linkplain OnExecutionGenerator
* database-generated} attribute values after an {@code insert} statement is executed. * database-generated} attribute values after an {@code insert} statement is executed.
* <p> * <p>
* Note that this class has responsibility for regular attributes of the entity. The * Note that this class has responsibility for regular attributes of the entity. The
* primary key / id attribute is handled separately, being the responsibility of an * primary key / id attribute is handled separately, being the responsibility of an
* instance of {@link org.hibernate.id.insert.InsertGeneratedIdentifierDelegate}. * instance of {@link org.hibernate.id.insert.InsertGeneratedIdentifierDelegate}.
* *
* @see InDatabaseGenerator * @see OnExecutionGenerator
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -82,7 +82,7 @@ public class GeneratedValuesProcessor {
} }
/** /**
* Find attributes generated by a {@link InDatabaseGenerator}, * Find attributes generated by a {@link OnExecutionGenerator},
* populate the list of {@link GeneratedValueDescriptor}s by side effect, and * populate the list of {@link GeneratedValueDescriptor}s by side effect, and
* return a list of {@link AttributeMapping}s. * return a list of {@link AttributeMapping}s.
*/ */
@ -94,7 +94,7 @@ public class GeneratedValuesProcessor {
entityDescriptor.forEachAttributeMapping( mapping -> { entityDescriptor.forEachAttributeMapping( mapping -> {
final Generator generator = generators[ mapping.getStateArrayPosition() ]; final Generator generator = generators[ mapping.getStateArrayPosition() ];
if ( generator != null if ( generator != null
&& generator.generatedByDatabase() && generator.generatedOnExecute()
&& generator.generatesSometimes() ) { && generator.generatesSometimes() ) {
// this attribute is generated for the timing we are processing... // this attribute is generated for the timing we are processing...
valueDescriptors.add( new GeneratedValueDescriptor( valueDescriptors.add( new GeneratedValueDescriptor(

View File

@ -52,7 +52,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.SubselectFetch; import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.FilterHelper; import org.hibernate.internal.FilterHelper;
@ -226,7 +226,7 @@ public abstract class AbstractCollectionPersister
protected final SqlExceptionHelper sqlExceptionHelper; protected final SqlExceptionHelper sqlExceptionHelper;
private final SessionFactoryImplementor factory; private final SessionFactoryImplementor factory;
private final EntityPersister ownerPersister; private final EntityPersister ownerPersister;
private final InMemoryGenerator identifierGenerator; private final BeforeExecutionGenerator identifierGenerator;
private final PropertyMapping elementPropertyMapping; private final PropertyMapping elementPropertyMapping;
private final EntityPersister elementPersister; private final EntityPersister elementPersister;
private final CollectionDataAccess cacheAccessStrategy; private final CollectionDataAccess cacheAccessStrategy;
@ -622,19 +622,19 @@ public abstract class AbstractCollectionPersister
tableMapping = buildCollectionTableMapping( collectionBootDescriptor, qualifiedTableName ); tableMapping = buildCollectionTableMapping( collectionBootDescriptor, qualifiedTableName );
} }
private InMemoryGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) { private BeforeExecutionGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) {
final Generator generator = collection.getIdentifier().createGenerator( final Generator generator = collection.getIdentifier().createGenerator(
context.getBootstrapContext().getIdentifierGeneratorFactory(), context.getBootstrapContext().getIdentifierGeneratorFactory(),
factory.getJdbcServices().getDialect(), factory.getJdbcServices().getDialect(),
null null
); );
if ( generator.generatedByDatabase() ) { if ( generator.generatedOnExecute() ) {
throw new MappingException("must be an InMemoryGenerator"); //TODO fix message throw new MappingException("must be an BeforeExecutionGenerator"); //TODO fix message
} }
if ( generator instanceof IdentifierGenerator ) { if ( generator instanceof IdentifierGenerator ) {
( (IdentifierGenerator) generator ).initialize( context.getSessionFactory().getSqlStringGenerationContext() ); ( (IdentifierGenerator) generator ).initialize( context.getSessionFactory().getSqlStringGenerationContext() );
} }
return (InMemoryGenerator) generator; return (BeforeExecutionGenerator) generator;
} }
@Override @Override
@ -1162,7 +1162,7 @@ public abstract class AbstractCollectionPersister
} }
@Override @Override
public InMemoryGenerator getGenerator() { public BeforeExecutionGenerator getGenerator() {
return identifierGenerator; return identifierGenerator;
} }

View File

@ -33,7 +33,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -241,7 +241,7 @@ public interface CollectionPersister extends Restrictable {
/** /**
* Get the surrogate key generation strategy (optional operation) * Get the surrogate key generation strategy (optional operation)
*/ */
default InMemoryGenerator getGenerator() { default BeforeExecutionGenerator getGenerator() {
return getIdentifierGenerator(); return getIdentifierGenerator();
} }

View File

@ -97,8 +97,8 @@ import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LoadEvent; import org.hibernate.event.spi.LoadEvent;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.internal.VersionGeneration; import org.hibernate.generator.internal.VersionGeneration;
import org.hibernate.id.Assigned; import org.hibernate.id.Assigned;
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator; import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
@ -432,7 +432,7 @@ public abstract class AbstractEntityPersister
protected AttributeMappingsMap declaredAttributeMappings = AttributeMappingsMap.builder().build(); protected AttributeMappingsMap declaredAttributeMappings = AttributeMappingsMap.builder().build();
protected AttributeMappingsList staticFetchableList; protected AttributeMappingsList staticFetchableList;
private InMemoryGenerator versionGenerator; private BeforeExecutionGenerator versionGenerator;
protected ReflectionOptimizer.AccessOptimizer accessOptimizer; protected ReflectionOptimizer.AccessOptimizer accessOptimizer;
@ -3066,7 +3066,7 @@ public abstract class AbstractEntityPersister
private void doLateInit() { private void doLateInit() {
if ( isIdentifierAssignedByInsert() ) { if ( isIdentifierAssignedByInsert() ) {
final InDatabaseGenerator generator = (InDatabaseGenerator) getGenerator(); final OnExecutionGenerator generator = (OnExecutionGenerator) getGenerator();
identityDelegate = generator.getGeneratedIdentifierDelegate( this ); identityDelegate = generator.getGeneratedIdentifierDelegate( this );
} }
@ -3840,7 +3840,7 @@ public abstract class AbstractEntityPersister
} }
@Override @Override
public InMemoryGenerator getVersionGenerator() { public BeforeExecutionGenerator getVersionGenerator() {
return versionGenerator; return versionGenerator;
} }
@ -4627,7 +4627,7 @@ public abstract class AbstractEntityPersister
final EntityMetamodel currentEntityMetamodel = getEntityMetamodel(); final EntityMetamodel currentEntityMetamodel = getEntityMetamodel();
if ( currentEntityMetamodel.isVersioned() ) { if ( currentEntityMetamodel.isVersioned() ) {
final InMemoryGenerator generator = currentEntityMetamodel.getVersionGenerator(); final BeforeExecutionGenerator generator = currentEntityMetamodel.getVersionGenerator();
// need to do this here because EntityMetamodel doesn't have the EntityVersionMapping :-( // need to do this here because EntityMetamodel doesn't have the EntityVersionMapping :-(
versionGenerator = generator == null ? new VersionGeneration( versionMapping ) : generator; versionGenerator = generator == null ? new VersionGeneration( versionMapping ) : generator;
} }

View File

@ -28,7 +28,7 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.internal.VersionGeneration; import org.hibernate.generator.internal.VersionGeneration;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
@ -472,7 +472,7 @@ public interface EntityPersister extends EntityMappingType, RootTableGroupProduc
return getIdentifierGenerator(); return getIdentifierGenerator();
} }
default InMemoryGenerator getVersionGenerator() { default BeforeExecutionGenerator getVersionGenerator() {
return new VersionGeneration( getVersionMapping() ); return new VersionGeneration( getVersionMapping() );
} }

View File

@ -24,7 +24,7 @@ import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
import org.hibernate.sql.model.internal.MutationOperationGroupNone; import org.hibernate.sql.model.internal.MutationOperationGroupNone;
import org.hibernate.sql.model.internal.MutationOperationGroupSingle; import org.hibernate.sql.model.internal.MutationOperationGroupSingle;
import org.hibernate.sql.model.internal.MutationOperationGroupStandard; import org.hibernate.sql.model.internal.MutationOperationGroupStandard;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
/** /**
* Base support for coordinating mutations against an entity * Base support for coordinating mutations against an entity
@ -97,7 +97,7 @@ public abstract class AbstractMutationCoordinator {
void handleValueGeneration( void handleValueGeneration(
AttributeMapping attributeMapping, AttributeMapping attributeMapping,
MutationGroupBuilder mutationGroupBuilder, MutationGroupBuilder mutationGroupBuilder,
InDatabaseGenerator generator) { OnExecutionGenerator generator) {
final Dialect dialect = factory.getJdbcServices().getDialect(); final Dialect dialect = factory.getJdbcServices().getDialect();
final boolean writePropertyValue = generator.writePropertyValue(); final boolean writePropertyValue = generator.writePropertyValue();
final String[] columnValues = writePropertyValue ? null : generator.getReferencedColumnValues( dialect ); final String[] columnValues = writePropertyValue ? null : generator.getReferencedColumnValues( dialect );

View File

@ -23,10 +23,7 @@ import org.hibernate.generator.EventType;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.AttributeMappingsList; import org.hibernate.persister.entity.AttributeMappingsList;
import org.hibernate.sql.model.MutationOperationGroup; import org.hibernate.sql.model.MutationOperationGroup;
@ -37,8 +34,8 @@ import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder; import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard; import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
/** /**
@ -114,9 +111,9 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
for ( int i = 0; i < generators.length; i++ ) { for ( int i = 0; i < generators.length; i++ ) {
final Generator generator = generators[i]; final Generator generator = generators[i];
if ( generator != null if ( generator != null
&& !generator.generatedByDatabase() && !generator.generatedOnExecute()
&& generator.generatesOnInsert() ) { && generator.generatesOnInsert() ) {
values[i] = ( (InMemoryGenerator) generator ).generate( session, entity, values[i], EventType.INSERT ); values[i] = ( (BeforeExecutionGenerator) generator ).generate( session, entity, values[i], EventType.INSERT );
entityPersister().setPropertyValue( entity, i, values[i] ); entityPersister().setPropertyValue( entity, i, values[i] );
} }
} }
@ -404,7 +401,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
if ( !attributeInclusions[ attributeIndex ] ) { if ( !attributeInclusions[ attributeIndex ] ) {
final Generator generator = attributeMapping.getGenerator(); final Generator generator = attributeMapping.getGenerator();
if ( isValueGenerationInSql( generator, factory().getJdbcServices().getDialect()) ) { if ( isValueGenerationInSql( generator, factory().getJdbcServices().getDialect()) ) {
handleValueGeneration( attributeMapping, insertGroupBuilder, (InDatabaseGenerator) generator ); handleValueGeneration( attributeMapping, insertGroupBuilder, (OnExecutionGenerator) generator );
} }
continue; continue;
} }
@ -434,7 +431,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) { private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) {
return generator != null return generator != null
&& generator.generatesOnInsert() && generator.generatesOnInsert()
&& generator.generatedByDatabase() && generator.generatedOnExecute()
&& ( (InDatabaseGenerator) generator ).referenceColumnsInSql(dialect); && ( (OnExecutionGenerator) generator ).referenceColumnsInSql(dialect);
} }
} }

View File

@ -32,11 +32,8 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EntityRowIdMapping; import org.hibernate.metamodel.mapping.EntityRowIdMapping;
import org.hibernate.metamodel.mapping.EntityVersionMapping; import org.hibernate.metamodel.mapping.EntityVersionMapping;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.AttributeMappingsList; import org.hibernate.persister.entity.AttributeMappingsList;
@ -49,15 +46,14 @@ import org.hibernate.sql.model.ast.MutatingTableReference;
import org.hibernate.sql.model.ast.RestrictedTableMutation; import org.hibernate.sql.model.ast.RestrictedTableMutation;
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder; import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
import org.hibernate.sql.model.ast.builder.RestrictedTableMutationBuilder; import org.hibernate.sql.model.ast.builder.RestrictedTableMutationBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.sql.model.ast.builder.TableUpdateBuilder; import org.hibernate.sql.model.ast.builder.TableUpdateBuilder;
import org.hibernate.sql.model.ast.builder.TableUpdateBuilderSkipped; import org.hibernate.sql.model.ast.builder.TableUpdateBuilderSkipped;
import org.hibernate.sql.model.ast.builder.TableUpdateBuilderStandard; import org.hibernate.sql.model.ast.builder.TableUpdateBuilderStandard;
import org.hibernate.sql.model.internal.MutationOperationGroupSingle; import org.hibernate.sql.model.internal.MutationOperationGroupSingle;
import org.hibernate.sql.model.jdbc.JdbcMutationOperation; import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
import static org.hibernate.engine.OptimisticLockStyle.ALL; import static org.hibernate.engine.OptimisticLockStyle.ALL;
@ -351,16 +347,16 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
private boolean isValueGenerationInSql(Generator generator, Dialect dialect) { private boolean isValueGenerationInSql(Generator generator, Dialect dialect) {
return generator != null return generator != null
&& generator.generatesOnUpdate() && generator.generatesOnUpdate()
&& generator.generatedByDatabase() && generator.generatedOnExecute()
&& ((InDatabaseGenerator) generator).referenceColumnsInSql(dialect); && ((OnExecutionGenerator) generator).referenceColumnsInSql(dialect);
} }
private boolean isValueGenerationInSqlNoWrite(Generator generator, Dialect dialect) { private boolean isValueGenerationInSqlNoWrite(Generator generator, Dialect dialect) {
return generator != null return generator != null
&& generator.generatesOnUpdate() && generator.generatesOnUpdate()
&& generator.generatedByDatabase() && generator.generatedOnExecute()
&& ((InDatabaseGenerator) generator).referenceColumnsInSql(dialect) && ((OnExecutionGenerator) generator).referenceColumnsInSql(dialect)
&& !((InDatabaseGenerator) generator).writePropertyValue(); && !((OnExecutionGenerator) generator).writePropertyValue();
} }
/** /**
@ -463,9 +459,9 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
for ( int i = 0; i < generators.length; i++ ) { for ( int i = 0; i < generators.length; i++ ) {
Generator generator = generators[i]; Generator generator = generators[i];
if ( generator != null if ( generator != null
&& !generator.generatedByDatabase() && !generator.generatedOnExecute()
&& generator.generatesOnUpdate() ) { && generator.generatesOnUpdate() ) {
newValues[i] = ( (InMemoryGenerator) generator ).generate( session, object, newValues[i], UPDATE ); newValues[i] = ( (BeforeExecutionGenerator) generator ).generate( session, object, newValues[i], UPDATE );
entityPersister().setPropertyValue( object, i, newValues[i] ); entityPersister().setPropertyValue( object, i, newValues[i] );
fieldsPreUpdateNeeded[count++] = i; fieldsPreUpdateNeeded[count++] = i;
} }
@ -947,7 +943,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
final Generator generator = attributeMapping.getGenerator(); final Generator generator = attributeMapping.getGenerator();
if ( isValueGenerationInSql( generator, dialect() ) ) { if ( isValueGenerationInSql( generator, dialect() ) ) {
handleValueGeneration( attributeMapping, updateGroupBuilder, (InDatabaseGenerator) generator ); handleValueGeneration( attributeMapping, updateGroupBuilder, (OnExecutionGenerator) generator );
} }
else if ( versionMapping != null else if ( versionMapping != null
&& versionMapping.getVersionAttribute() == attributeMapping ) { && versionMapping.getVersionAttribute() == attributeMapping ) {

View File

@ -272,7 +272,7 @@ public class CteInsertHandler implements InsertHandler {
rowNumberColumn rowNumberColumn
); );
} }
if ( !assignsId && entityDescriptor.getGenerator().generatedByDatabase() ) { if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecute() ) {
querySpec.getSelectClause().addSqlSelection( querySpec.getSelectClause().addSqlSelection(
new SqlSelectionImpl( new SqlSelectionImpl(
1, 1,
@ -336,7 +336,7 @@ public class CteInsertHandler implements InsertHandler {
processingStateStack.push( oldState ); processingStateStack.push( oldState );
sqmConverter.pruneTableGroupJoins(); sqmConverter.pruneTableGroupJoins();
if ( !assignsId && entityDescriptor.getGenerator().generatedByDatabase() ) { if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecute() ) {
// Add the row number to the assignments // Add the row number to the assignments
final CteColumn rowNumberColumn = cteTable.getCteColumns() final CteColumn rowNumberColumn = cteTable.getCteColumns()
.get( cteTable.getCteColumns().size() - 1 ); .get( cteTable.getCteColumns().size() - 1 );
@ -580,7 +580,7 @@ public class CteInsertHandler implements InsertHandler {
statement.addCteStatement( entityCte ); statement.addCteStatement( entityCte );
} }
} }
else if ( !assignsId && entityDescriptor.getGenerator().generatedByDatabase() ) { else if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecute() ) {
final String baseTableName = "base_" + entityCteTable.getTableExpression(); final String baseTableName = "base_" + entityCteTable.getTableExpression();
final CteStatement baseEntityCte = new CteStatement( final CteStatement baseEntityCte = new CteStatement(
entityCteTable.withName( baseTableName ), entityCteTable.withName( baseTableName ),
@ -777,7 +777,7 @@ public class CteInsertHandler implements InsertHandler {
final Generator identifierGenerator = entityDescriptor.getEntityPersister().getGenerator(); final Generator identifierGenerator = entityDescriptor.getEntityPersister().getGenerator();
final List<Map.Entry<List<CteColumn>, Assignment>> tableAssignments = assignmentsByTable.get( rootTableReference ); final List<Map.Entry<List<CteColumn>, Assignment>> tableAssignments = assignmentsByTable.get( rootTableReference );
if ( ( tableAssignments == null || tableAssignments.isEmpty() ) if ( ( tableAssignments == null || tableAssignments.isEmpty() )
&& !( identifierGenerator.generatedByDatabase() ) ) { && !identifierGenerator.generatedOnExecute() ) {
throw new IllegalStateException( "There must be at least a single root table assignment" ); throw new IllegalStateException( "There must be at least a single root table assignment" );
} }
@ -805,7 +805,7 @@ public class CteInsertHandler implements InsertHandler {
final QuerySpec insertSelectSpec = new QuerySpec( true ); final QuerySpec insertSelectSpec = new QuerySpec( true );
CteStatement finalCteStatement = null; CteStatement finalCteStatement = null;
final CteTable dmlResultCte; final CteTable dmlResultCte;
if ( i == 0 && !assignsId && identifierGenerator.generatedByDatabase() ) { if ( i == 0 && !assignsId && identifierGenerator.generatedOnExecute() ) {
// Special handling for identity generation // Special handling for identity generation
final String cteTableName = getCteTableName( tableExpression, "base_" ); final String cteTableName = getCteTableName( tableExpression, "base_" );
if ( statement.getCteStatement( cteTableName ) != null ) { if ( statement.getCteStatement( cteTableName ) != null ) {
@ -1074,7 +1074,7 @@ public class CteInsertHandler implements InsertHandler {
if ( finalCteStatement != null ) { if ( finalCteStatement != null ) {
statement.addCteStatement( finalCteStatement ); statement.addCteStatement( finalCteStatement );
} }
if ( i == 0 && !assignsId && identifierGenerator.generatedByDatabase() ) { if ( i == 0 && !assignsId && identifierGenerator.generatedOnExecute() ) {
// Special handling for identity generation // Special handling for identity generation
statement.addCteStatement( queryCte ); statement.addCteStatement( queryCte );
} }

View File

@ -75,8 +75,8 @@ import org.hibernate.sql.results.graph.basic.BasicFetch;
import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.sql.results.spi.ListResultsConsumer; import org.hibernate.sql.results.spi.ListResultsConsumer;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueBinder;
/** /**
@ -308,7 +308,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
final Generator generator = entityPersister.getGenerator(); final Generator generator = entityPersister.getGenerator();
final List<Assignment> assignments = assignmentsByTable.get( updatingTableReference ); final List<Assignment> assignments = assignmentsByTable.get( updatingTableReference );
if ( ( assignments == null || assignments.isEmpty() ) if ( ( assignments == null || assignments.isEmpty() )
&& !generator.generatedByDatabase() && !generator.generatedOnExecute()
&& ( !( generator instanceof BulkInsertionCapableIdentifierGenerator ) && ( !( generator instanceof BulkInsertionCapableIdentifierGenerator )
|| ( (BulkInsertionCapableIdentifierGenerator) generator ).supportsBulkInsertionIdentifierGeneration() ) ) { || ( (BulkInsertionCapableIdentifierGenerator) generator ).supportsBulkInsertionIdentifierGeneration() ) ) {
throw new IllegalStateException( "There must be at least a single root table assignment" ); throw new IllegalStateException( "There must be at least a single root table assignment" );
@ -356,7 +356,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
} }
final JdbcServices jdbcServices = sessionFactory.getJdbcServices(); final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
final Map<Object, Object> entityTableToRootIdentity; final Map<Object, Object> entityTableToRootIdentity;
if ( generator.generatedByDatabase() ) { if ( generator.generatedOnExecute() ) {
final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityDescriptor.getIdentifierMapping(); final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityDescriptor.getIdentifierMapping();
final QuerySpec idSelectQuerySpec = new QuerySpec( true ); final QuerySpec idSelectQuerySpec = new QuerySpec( true );
idSelectQuerySpec.getFromClause().addRoot( temporaryTableGroup ); idSelectQuerySpec.getFromClause().addRoot( temporaryTableGroup );
@ -510,7 +510,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
rootIdentity, rootIdentity,
new JdbcParameterBindingImpl( new JdbcParameterBindingImpl(
identifierMapping.getJdbcMapping(), identifierMapping.getJdbcMapping(),
( (InMemoryGenerator) generator ).generate( executionContext.getSession(), null, null, EventType.INSERT ) ( (BeforeExecutionGenerator) generator ).generate( executionContext.getSession(), null, null, EventType.INSERT )
) )
); );
jdbcServices.getJdbcMutationExecutor().execute( jdbcServices.getJdbcMutationExecutor().execute(
@ -558,8 +558,8 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
.buildInsertTranslator( sessionFactory, insertStatement ) .buildInsertTranslator( sessionFactory, insertStatement )
.translate( null, executionContext.getQueryOptions() ); .translate( null, executionContext.getQueryOptions() );
if ( generator.generatedByDatabase() ) { if ( generator.generatedOnExecute() ) {
final InDatabaseGenerator databaseGenerator = (InDatabaseGenerator) generator; final OnExecutionGenerator databaseGenerator = (OnExecutionGenerator) generator;
final InsertGeneratedIdentifierDelegate identifierDelegate = final InsertGeneratedIdentifierDelegate identifierDelegate =
databaseGenerator.getGeneratedIdentifierDelegate( (PostInsertIdentityPersister) entityPersister ); databaseGenerator.getGeneratedIdentifierDelegate( (PostInsertIdentityPersister) entityPersister );
final String finalSql = identifierDelegate.prepareIdentifierGeneratingInsert( jdbcInsert.getSqlString() ); final String finalSql = identifierDelegate.prepareIdentifierGeneratingInsert( jdbcInsert.getSqlString() );
@ -719,7 +719,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
final AbstractEntityPersister entityPersister = (AbstractEntityPersister) entityDescriptor.getEntityPersister(); final AbstractEntityPersister entityPersister = (AbstractEntityPersister) entityDescriptor.getEntityPersister();
final Generator identifierGenerator = entityPersister.getGenerator(); final Generator identifierGenerator = entityPersister.getGenerator();
final boolean needsKeyInsert; final boolean needsKeyInsert;
if ( identifierGenerator.generatedByDatabase() ) { if ( identifierGenerator.generatedOnExecute() ) {
needsKeyInsert = true; needsKeyInsert = true;
} }
else if ( identifierGenerator instanceof OptimizableGenerator ) { else if ( identifierGenerator instanceof OptimizableGenerator ) {

View File

@ -42,7 +42,7 @@ import org.hibernate.engine.profile.FetchProfile;
import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.graph.spi.AppliedGraph; import org.hibernate.graph.spi.AppliedGraph;
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator; import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
import org.hibernate.id.CompositeNestedGeneratedValueGenerator; import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
@ -1355,7 +1355,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
} }
// This uses identity generation, so we don't need to list the column // This uses identity generation, so we don't need to list the column
if ( identifierGenerator != null && identifierGenerator.generatedByDatabase() if ( identifierGenerator != null && identifierGenerator.generatedOnExecute()
|| identifierGenerator instanceof CompositeNestedGeneratedValueGenerator ) { || identifierGenerator instanceof CompositeNestedGeneratedValueGenerator ) {
identifierGenerator = null; identifierGenerator = null;
} }
@ -1440,10 +1440,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
if ( discriminatorExpression != null ) { if ( discriminatorExpression != null ) {
expressions.add( discriminatorExpression ); expressions.add( discriminatorExpression );
} }
if ( identifierGenerator != null && !identifierGenerator.generatedByDatabase() ) { if ( identifierGenerator != null && !identifierGenerator.generatedOnExecute() ) {
if ( identifierGeneratorParameter == null ) { if ( identifierGeneratorParameter == null ) {
identifierGeneratorParameter = identifierGeneratorParameter =
new IdGeneratorParameter( identifierMapping, (InMemoryGenerator) identifierGenerator ); new IdGeneratorParameter( identifierMapping, (BeforeExecutionGenerator) identifierGenerator );
} }
expressions.add( identifierGeneratorParameter ); expressions.add( identifierGeneratorParameter );
} }
@ -1517,9 +1517,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
private static class IdGeneratorParameter extends AbstractJdbcParameter { private static class IdGeneratorParameter extends AbstractJdbcParameter {
private final InMemoryGenerator generator; private final BeforeExecutionGenerator generator;
public IdGeneratorParameter(BasicEntityIdentifierMapping identifierMapping, InMemoryGenerator generator) { public IdGeneratorParameter(BasicEntityIdentifierMapping identifierMapping, BeforeExecutionGenerator generator) {
super( identifierMapping.getJdbcMapping() ); super( identifierMapping.getJdbcMapping() );
this.generator = generator; this.generator = generator;
} }

View File

@ -14,7 +14,7 @@ import org.hibernate.Internal;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
/** /**
* An SQL {@code INSERT} statement * An SQL {@code INSERT} statement
@ -98,7 +98,7 @@ public class Insert {
return this; return this;
} }
public Insert addGeneratedColumns(String[] columnNames, InDatabaseGenerator generator) { public Insert addGeneratedColumns(String[] columnNames, OnExecutionGenerator generator) {
if ( generator.referenceColumnsInSql( dialect ) ) { if ( generator.referenceColumnsInSql( dialect ) ) {
String[] columnValues = generator.getReferencedColumnValues( dialect ); String[] columnValues = generator.getReferencedColumnValues( dialect );
if ( columnNames.length != columnValues.length ) { if ( columnNames.length != columnValues.length ) {

View File

@ -42,7 +42,7 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
this.embedded = embedded; this.embedded = embedded;
this.hasIdentifierMapper = false; this.hasIdentifierMapper = false;
this.identifierGenerator = identifierGenerator; this.identifierGenerator = identifierGenerator;
this.identifierAssignedByInsert = identifierGenerator.generatedByDatabase(); this.identifierAssignedByInsert = identifierGenerator.generatedOnExecute();
} }
/** /**
@ -63,7 +63,7 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA
this.embedded = embedded; this.embedded = embedded;
this.hasIdentifierMapper = hasIdentifierMapper; this.hasIdentifierMapper = hasIdentifierMapper;
this.identifierGenerator = identifierGenerator; this.identifierGenerator = identifierGenerator;
this.identifierAssignedByInsert = identifierGenerator.generatedByDatabase(); this.identifierAssignedByInsert = identifierGenerator.generatedOnExecute();
} }
@Override @Override

View File

@ -8,19 +8,18 @@ package org.hibernate.tuple;
import java.util.EnumSet; import java.util.EnumSet;
import org.hibernate.Session;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
/** /**
* A value generator that can adapt to both Java value generation and database value generation. * A value generator that can adapt to both Java value generation and database value generation.
* <p> * <p>
* This is an older API that predates {@link Generator}. It's often cleaner to implement either * This is an older API that predates {@link Generator}. It's often cleaner to implement either
* {@link InMemoryGenerator} or {@link InDatabaseGenerator} directly. * {@link BeforeExecutionGenerator} or {@link OnExecutionGenerator} directly.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Gavin King * @author Gavin King
@ -30,7 +29,7 @@ import org.hibernate.generator.InMemoryGenerator;
* @deprecated Replaced by {@link Generator} * @deprecated Replaced by {@link Generator}
*/ */
@Deprecated(since = "6", forRemoval = true) @Deprecated(since = "6", forRemoval = true)
public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator { public interface ValueGeneration extends BeforeExecutionGenerator, OnExecutionGenerator {
/** /**
* Specifies that the property value is generated: * Specifies that the property value is generated:
* <ul> * <ul>
@ -84,7 +83,7 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator
/** /**
* A SQL expression indicating how to calculate the generated value when the property value * A SQL expression indicating how to calculate the generated value when the property value
* is {@linkplain #generatedByDatabase() generated in the database} and the mapped column is * is {@linkplain #generatedOnExecute() generated in the database} and the mapped column is
* {@linkplain #referenceColumnInSql() included in the SQL statement}. The SQL expression * {@linkplain #referenceColumnInSql() included in the SQL statement}. The SQL expression
* might be: * might be:
* <ul> * <ul>
@ -101,7 +100,7 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator
/** /**
* A SQL expression indicating how to calculate the generated value when the property value * A SQL expression indicating how to calculate the generated value when the property value
* is {@linkplain #generatedByDatabase() generated in the database} and the mapped column is * is {@linkplain #generatedOnExecute() generated in the database} and the mapped column is
* {@linkplain #referenceColumnInSql() included in the SQL statement}. The SQL expression * {@linkplain #referenceColumnInSql() included in the SQL statement}. The SQL expression
* might be: * might be:
* <ul> * <ul>
@ -140,7 +139,8 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator
* @return {@code true} if the value is generated by the database, or false if it is * @return {@code true} if the value is generated by the database, or false if it is
* generated in Java using a {@link ValueGenerator}. * generated in Java using a {@link ValueGenerator}.
*/ */
default boolean generatedByDatabase() { @Override
default boolean generatedOnExecute() {
return getValueGenerator() == null; return getValueGenerator() == null;
} }
@ -155,8 +155,9 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator
* *
* @see org.hibernate.annotations.Generated#writable() * @see org.hibernate.annotations.Generated#writable()
*/ */
@Override
default boolean writePropertyValue() { default boolean writePropertyValue() {
return !generatedByDatabase() // value generated in memory and then written as normal return !this.generatedOnExecute() // value generated in memory and then written as normal
// current value of property of entity instance written completely as normal // current value of property of entity instance written completely as normal
|| referenceColumnInSql() && getDatabaseGeneratedReferencedColumnValue()==null; || referenceColumnInSql() && getDatabaseGeneratedReferencedColumnValue()==null;
} }

View File

@ -11,16 +11,15 @@ import java.util.EnumSet;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Internal; import org.hibernate.Internal;
import org.hibernate.Session;
import org.hibernate.annotations.GeneratorType; import org.hibernate.annotations.GeneratorType;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import static org.hibernate.internal.util.ReflectHelper.getDefaultConstructor; import static org.hibernate.internal.util.ReflectHelper.getDefaultConstructor;
/** /**
* An {@link InMemoryGenerator} which delegates to a {@link ValueGenerator}. * A {@link BeforeExecutionGenerator} which delegates to a {@link ValueGenerator}.
* Underlies the {@link GeneratorType} annotation. * Underlies the {@link GeneratorType} annotation.
* *
* @author Gunnar Morling * @author Gunnar Morling
@ -29,7 +28,7 @@ import static org.hibernate.internal.util.ReflectHelper.getDefaultConstructor;
*/ */
@Internal @Internal
@Deprecated(since = "6.2") @Deprecated(since = "6.2")
public class VmValueGeneration implements InMemoryGenerator { public class VmValueGeneration implements BeforeExecutionGenerator {
private final EnumSet<EventType> eventTypes; private final EnumSet<EventType> eventTypes;
private final ValueGenerator<?> generator; private final ValueGenerator<?> generator;

View File

@ -34,8 +34,8 @@ import org.hibernate.engine.spi.CascadingActions;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.InDatabaseGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
@ -141,7 +141,7 @@ public class EntityMetamodel implements Serializable {
private final Set<String> subclassEntityNames; private final Set<String> subclassEntityNames;
private final Map<Class<?>,String> entityNameByInheritanceClassMap; private final Map<Class<?>,String> entityNameByInheritanceClassMap;
private final InMemoryGenerator versionGenerator; private final BeforeExecutionGenerator versionGenerator;
private final BytecodeEnhancementMetadata bytecodeEnhancementMetadata; private final BytecodeEnhancementMetadata bytecodeEnhancementMetadata;
@ -237,7 +237,7 @@ public class EntityMetamodel implements Serializable {
BitSet mutableIndexes = new BitSet(); BitSet mutableIndexes = new BitSet();
boolean foundNonIdentifierPropertyNamedId = false; boolean foundNonIdentifierPropertyNamedId = false;
boolean foundUpdateableNaturalIdProperty = false; boolean foundUpdateableNaturalIdProperty = false;
InMemoryGenerator tempVersionGenerator = null; BeforeExecutionGenerator tempVersionGenerator = null;
List<Property> props = persistentClass.getPropertyClosure(); List<Property> props = persistentClass.getPropertyClosure();
for ( int i=0; i<props.size(); i++ ) { for ( int i=0; i<props.size(); i++ ) {
@ -312,12 +312,12 @@ public class EntityMetamodel implements Serializable {
// generated value strategies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // generated value strategies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final Generator generator = buildGenerator( property, creationContext ); final Generator generator = buildGenerator( property, creationContext );
if ( generator != null ) { if ( generator != null ) {
if ( i == tempVersionProperty && !generator.generatedByDatabase() ) { if ( i == tempVersionProperty && !generator.generatedOnExecute() ) {
// when we have an in-memory generator for the version, we // when we have an in-memory generator for the version, we
// want to plug it in to the older infrastructure specific // want to plug it in to the older infrastructure specific
// to version generation, instead of treating it like a // to version generation, instead of treating it like a
// plain "value" generator for a regular attribute // plain "value" generator for a regular attribute
tempVersionGenerator = (InMemoryGenerator) generator; tempVersionGenerator = (BeforeExecutionGenerator) generator;
} }
else { else {
generators[i] = generator; generators[i] = generator;
@ -326,7 +326,7 @@ public class EntityMetamodel implements Serializable {
propertyUpdateability[i] = false; propertyUpdateability[i] = false;
} }
if ( generator.generatesOnInsert() ) { if ( generator.generatesOnInsert() ) {
if ( generator.generatedByDatabase() ) { if ( generator.generatedOnExecute() ) {
foundPostInsertGeneratedValues = true; foundPostInsertGeneratedValues = true;
} }
else { else {
@ -334,7 +334,7 @@ public class EntityMetamodel implements Serializable {
} }
} }
if ( generator.generatesOnUpdate() ) { if ( generator.generatesOnUpdate() ) {
if ( generator.generatedByDatabase() ) { if ( generator.generatedOnExecute() ) {
foundPostUpdateGeneratedValues = true; foundPostUpdateGeneratedValues = true;
} }
else { else {
@ -464,8 +464,8 @@ public class EntityMetamodel implements Serializable {
} }
private static boolean generatedWithNoParameter(Generator generator) { private static boolean generatedWithNoParameter(Generator generator) {
return generator.generatedByDatabase() return generator.generatedOnExecute()
&& !((InDatabaseGenerator) generator).writePropertyValue(); && !((OnExecutionGenerator) generator).writePropertyValue();
} }
private static Generator buildGenerator( private static Generator buildGenerator(
@ -494,7 +494,7 @@ public class EntityMetamodel implements Serializable {
return generators; return generators;
} }
public InMemoryGenerator getVersionGenerator() { public BeforeExecutionGenerator getVersionGenerator() {
return versionGenerator; return versionGenerator;
} }
@ -511,7 +511,7 @@ public class EntityMetamodel implements Serializable {
private boolean hadInMemoryGeneration; private boolean hadInMemoryGeneration;
private boolean hadInDatabaseGeneration; private boolean hadInDatabaseGeneration;
private List<InDatabaseGenerator> inDatabaseStrategies; private List<OnExecutionGenerator> inDatabaseStrategies;
public CompositeGeneratorBuilder(Property mappingProperty, Dialect dialect) { public CompositeGeneratorBuilder(Property mappingProperty, Dialect dialect) {
this.mappingProperty = mappingProperty; this.mappingProperty = mappingProperty;
@ -520,26 +520,26 @@ public class EntityMetamodel implements Serializable {
public void addPair(Generator generator) { public void addPair(Generator generator) {
if ( generator != null ) { if ( generator != null ) {
if ( generator.generatedByDatabase() ) { if ( generator.generatedOnExecute() ) {
if ( generator instanceof InDatabaseGenerator ) { if ( generator instanceof OnExecutionGenerator ) {
add( (InDatabaseGenerator) generator ); add( (OnExecutionGenerator) generator );
} }
} }
else { else {
if ( generator instanceof InMemoryGenerator ) { if ( generator instanceof BeforeExecutionGenerator ) {
add( (InMemoryGenerator) generator ); add( (BeforeExecutionGenerator) generator );
} }
} }
} }
} }
private void add(InMemoryGenerator inMemoryStrategy) { private void add(BeforeExecutionGenerator inMemoryStrategy) {
if ( inMemoryStrategy.generatesSometimes() ) { if ( inMemoryStrategy.generatesSometimes() ) {
hadInMemoryGeneration = true; hadInMemoryGeneration = true;
} }
} }
private void add(InDatabaseGenerator inDatabaseStrategy) { private void add(OnExecutionGenerator inDatabaseStrategy) {
if ( inDatabaseStrategies == null ) { if ( inDatabaseStrategies == null ) {
inDatabaseStrategies = new ArrayList<>(); inDatabaseStrategies = new ArrayList<>();
} }
@ -582,7 +582,7 @@ public class EntityMetamodel implements Serializable {
int columnIndex = 0; int columnIndex = 0;
for ( Property property : composite.getProperties() ) { for ( Property property : composite.getProperties() ) {
propertyIndex++; propertyIndex++;
final InDatabaseGenerator generator = inDatabaseStrategies.get( propertyIndex ); final OnExecutionGenerator generator = inDatabaseStrategies.get( propertyIndex );
eventTypes.addAll( generator.getEventTypes() ); eventTypes.addAll( generator.getEventTypes() );
if ( generator.referenceColumnsInSql(dialect) ) { if ( generator.referenceColumnsInSql(dialect) ) {
// override base-line value // override base-line value
@ -607,7 +607,7 @@ public class EntityMetamodel implements Serializable {
} }
// then use the aggregated values to build the InDatabaseValueGenerationStrategy // then use the aggregated values to build the InDatabaseValueGenerationStrategy
return new InDatabaseGeneratorImpl( eventTypes, referenceColumns, columnValues ); return new OnExecutionGeneratorImpl( eventTypes, referenceColumns, columnValues );
} }
else { else {
return new Generator() { return new Generator() {
@ -615,7 +615,8 @@ public class EntityMetamodel implements Serializable {
public EnumSet<EventType> getEventTypes() { public EnumSet<EventType> getEventTypes() {
return NONE; return NONE;
} }
public boolean generatedByDatabase() { @Override
public boolean generatedOnExecute() {
return false; return false;
} }
}; };
@ -623,12 +624,12 @@ public class EntityMetamodel implements Serializable {
} }
} }
private static class InDatabaseGeneratorImpl implements InDatabaseGenerator { private static class OnExecutionGeneratorImpl implements OnExecutionGenerator {
private final EnumSet<EventType> eventTypes; private final EnumSet<EventType> eventTypes;
private final boolean referenceColumnInSql; private final boolean referenceColumnInSql;
private final String[] referencedColumnValues; private final String[] referencedColumnValues;
private InDatabaseGeneratorImpl( private OnExecutionGeneratorImpl(
EnumSet<EventType> eventTypes, EnumSet<EventType> eventTypes,
boolean referenceColumnInSql, boolean referenceColumnInSql,
String[] referencedColumnValues) { String[] referencedColumnValues) {
@ -691,12 +692,12 @@ public class EntityMetamodel implements Serializable {
public boolean isVersionGeneratedByDatabase() { public boolean isVersionGeneratedByDatabase() {
final Generator strategy = generators[ versionPropertyIndex ]; final Generator strategy = generators[ versionPropertyIndex ];
return strategy != null && strategy.generatesSometimes() && strategy.generatedByDatabase(); return strategy != null && strategy.generatesSometimes() && strategy.generatedOnExecute();
} }
public boolean isVersionGeneratedInMemory() { public boolean isVersionGeneratedInMemory() {
final Generator strategy = generators[ versionPropertyIndex ]; final Generator strategy = generators[ versionPropertyIndex ];
return strategy != null && strategy.generatesSometimes() && !strategy.generatedByDatabase(); return strategy != null && strategy.generatesSometimes() && !strategy.generatedOnExecute();
} }
public int[] getNaturalIdentifierProperties() { public int[] getNaturalIdentifierProperties() {

View File

@ -22,7 +22,7 @@ import org.hibernate.annotations.ValueGenerationType;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.GenerationTiming;
import org.hibernate.generator.InMemoryGenerator; import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
@ -85,7 +85,7 @@ public class GeneratedUuidTests {
//end::mapping-generated-custom-ex2[] //end::mapping-generated-custom-ex2[]
//tag::mapping-generated-custom-ex3[] //tag::mapping-generated-custom-ex3[]
public static class UuidValueGeneration implements InMemoryGenerator { public static class UuidValueGeneration implements BeforeExecutionGenerator {
private final EnumSet<EventType> eventTypes; private final EnumSet<EventType> eventTypes;
public UuidValueGeneration(GeneratedUuidValue annotation) { public UuidValueGeneration(GeneratedUuidValue annotation) {