diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/IdGeneratorType.java b/hibernate-core/src/main/java/org/hibernate/annotations/IdGeneratorType.java index d07c621d45..72ea7be298 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/IdGeneratorType.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/IdGeneratorType.java @@ -23,7 +23,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; *

* For example, if we have a custom identifier generator: *

{@code
- * public class CustomSequenceGenerator implements InMemoryGenerator {
+ * public class CustomSequenceGenerator implements BeforeExecutionGenerator {
  *     public CustomSequenceGenerator(CustomSequence config, Member annotatedMember,
  *                                    CustomIdGeneratorCreationContext context) {
  *         ...
diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/ValueGenerationType.java b/hibernate-core/src/main/java/org/hibernate/annotations/ValueGenerationType.java
index e5b3cc2715..5c4f368a53 100644
--- a/hibernate-core/src/main/java/org/hibernate/annotations/ValueGenerationType.java
+++ b/hibernate-core/src/main/java/org/hibernate/annotations/ValueGenerationType.java
@@ -12,8 +12,8 @@ import java.lang.annotation.Target;
 
 import org.hibernate.generator.AnnotationBasedGenerator;
 import org.hibernate.generator.Generator;
-import org.hibernate.generator.InDatabaseGenerator;
-import org.hibernate.generator.InMemoryGenerator;
+import org.hibernate.generator.OnExecutionGenerator;
+import org.hibernate.generator.BeforeExecutionGenerator;
 import org.hibernate.generator.internal.TenantIdGeneration;
 
 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
  * is responsible for generating values. It must be either:
  * 
  * 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}.
  *
  * @see Generator
- * @see InMemoryGenerator
- * @see InDatabaseGenerator
+ * @see BeforeExecutionGenerator
+ * @see OnExecutionGenerator
  * @see AnnotationBasedGenerator
  *
  * @author Gunnar Morling
diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java
index 99e5a0134f..49a5f97489 100644
--- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java
+++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java
@@ -49,8 +49,8 @@ import org.hibernate.generator.AnnotationBasedGenerator;
 import org.hibernate.generator.Generator;
 import org.hibernate.binder.AttributeBinder;
 import org.hibernate.generator.GeneratorCreationContext;
-import org.hibernate.generator.InDatabaseGenerator;
-import org.hibernate.generator.InMemoryGenerator;
+import org.hibernate.generator.OnExecutionGenerator;
+import org.hibernate.generator.BeforeExecutionGenerator;
 import org.jboss.logging.Logger;
 
 import java.lang.annotation.Annotation;
@@ -452,10 +452,10 @@ public class PropertyBinder {
 	}
 
 	private static void checkGeneratorClass(Class generatorClass) {
-		if ( !InMemoryGenerator.class.isAssignableFrom( generatorClass )
-				&& !InDatabaseGenerator.class.isAssignableFrom( generatorClass ) ) {
+		if ( !BeforeExecutionGenerator.class.isAssignableFrom( generatorClass )
+				&& !OnExecutionGenerator.class.isAssignableFrom( generatorClass ) ) {
 			throw new MappingException("Generator class '" + generatorClass.getName()
-					+ "' must implement either 'InMemoryGenerator' or 'InDatabaseGenerator'");
+					+ "' must implement either 'BeforeExecutionGenerator' or 'OnExecutionGenerator'");
 		}
 	}
 
diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
index 7e5172865c..f9f740ec8f 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
@@ -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?
+	 * 

+ * Support for identity columns is insufficient here, we require something like: + *

    + *
  1. {@code insert ... returning ...} + *
  2. {@code select from final table (insert ... )} + *
* * @return {@code true} if {@link org.hibernate.id.insert.InsertReturningDelegate} * works for any sort of primary key column (not just identity columns), or * {@code false} if {@code InsertReturningDelegate} does not work, or only * works for specialized identity/"autoincrement" columns + * + * @see org.hibernate.generator.OnExecutionGenerator#getGeneratedIdentifierDelegate + * @see org.hibernate.id.insert.InsertReturningDelegate + * + * @since 6.2 */ public boolean supportsInsertReturning() { 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[])}. + *

+ * 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() { return false; } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java index 3149d6db57..7d2630a797 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java @@ -274,7 +274,7 @@ public class TemporaryTable implements Exportable, Contributable { .getEntityBinding( entityDescriptor.getEntityName() ); final Generator identifierGenerator = entityDescriptor.getEntityPersister().getGenerator(); - final boolean identityColumn = identifierGenerator.generatedByDatabase(); + final boolean identityColumn = identifierGenerator.generatedOnExecute(); final boolean hasOptimizer; if ( identityColumn ) { hasOptimizer = false; diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java index 6411f688b8..2beee3c94f 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java @@ -33,7 +33,7 @@ import org.hibernate.jpa.event.spi.CallbackRegistryConsumer; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.type.Type; import org.hibernate.type.TypeHelper; @@ -116,8 +116,8 @@ public abstract class AbstractSaveEventListener final EntityPersister persister = source.getEntityPersister( entityName, entity ); Generator generator = persister.getGenerator(); - if ( !generator.generatedByDatabase() ) { - final Object generatedId = ( (InMemoryGenerator) generator ).generate( source, entity, null, INSERT ); + if ( !generator.generatedOnExecute() ) { + final Object generatedId = ( (BeforeExecutionGenerator) generator ).generate( source, entity, null, INSERT ); if ( generatedId == null ) { throw new IdentifierGenerationException( "null id generated for: " + entity.getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/generator/AnnotationBasedGenerator.java b/hibernate-core/src/main/java/org/hibernate/generator/AnnotationBasedGenerator.java index 55a322170d..bd7d6a75f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/AnnotationBasedGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/AnnotationBasedGenerator.java @@ -29,8 +29,8 @@ import java.lang.reflect.Member; * {@code AnnotationType} is the generator annotation type used to configure the * generator. *

- * Every instance of this class must implement either {@link InMemoryGenerator} or - * {@link InDatabaseGenerator}. + * Every instance of this class must implement either {@link BeforeExecutionGenerator} or + * {@link OnExecutionGenerator}. * * @param The generator annotation type supported by an implementation * diff --git a/hibernate-core/src/main/java/org/hibernate/generator/InMemoryGenerator.java b/hibernate-core/src/main/java/org/hibernate/generator/BeforeExecutionGenerator.java similarity index 90% rename from hibernate-core/src/main/java/org/hibernate/generator/InMemoryGenerator.java rename to hibernate-core/src/main/java/org/hibernate/generator/BeforeExecutionGenerator.java index 797bff0778..ab120ef24b 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/InMemoryGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/BeforeExecutionGenerator.java @@ -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 * value. *

- * 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 * 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 @@ -30,10 +30,11 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; * {@link org.hibernate.annotations.ValueGenerationType}, as for any {@link Generator}. * * @author Steve Ebersole + * @author Gavin King * * @since 6.2 */ -public interface InMemoryGenerator extends Generator { +public interface BeforeExecutionGenerator extends Generator { /** * Generate a value. * @@ -45,7 +46,8 @@ public interface InMemoryGenerator extends Generator { */ Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType); - default boolean generatedByDatabase() { + @Override + default boolean generatedOnExecute() { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/generator/Generator.java b/hibernate-core/src/main/java/org/hibernate/generator/Generator.java index 7d6f64f775..459d2f9f3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/Generator.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/Generator.java @@ -7,7 +7,6 @@ package org.hibernate.generator; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.tuple.ValueGenerator; import java.io.Serializable; 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 * 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 - * generated in Java code, or by the database. + * {@link BeforeExecutionGenerator} or {@link OnExecutionGenerator} depending on whether values + * are generated in Java code before execution of a SQL statement, or by the database when the + * SQL statement is executed. *

* Generically, a generator may be integrated with the program using the meta-annotation * {@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 { /** - * 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. + * * * @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 diff --git a/hibernate-core/src/main/java/org/hibernate/generator/InDatabaseGenerator.java b/hibernate-core/src/main/java/org/hibernate/generator/OnExecutionGenerator.java similarity index 90% rename from hibernate-core/src/main/java/org/hibernate/generator/InDatabaseGenerator.java rename to hibernate-core/src/main/java/org/hibernate/generator/OnExecutionGenerator.java index 060f930e57..f353c2cdb7 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/InDatabaseGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/OnExecutionGenerator.java @@ -18,11 +18,18 @@ import org.hibernate.persister.entity.EntityPersister; 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. + *

* 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 * 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 - * {@code select}. + * statement. + *

+ * 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. *

* Implementations should override {@link #referenceColumnsInSql(Dialect)}, * {@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}. * * @author Steve Ebersole + * @author Gavin King * * @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 @@ -133,7 +141,8 @@ public interface InDatabaseGenerator extends Generator { return getNaturalIdPropertyNames( persister ); } - default boolean generatedByDatabase() { + @Override + default boolean generatedOnExecute() { return true; } } diff --git a/hibernate-core/src/main/java/org/hibernate/generator/internal/CurrentTimestampGeneration.java b/hibernate-core/src/main/java/org/hibernate/generator/internal/CurrentTimestampGeneration.java index 3bc31d64e1..9e810bc729 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/internal/CurrentTimestampGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/internal/CurrentTimestampGeneration.java @@ -14,8 +14,8 @@ import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.tuple.GenerationTiming; @@ -46,7 +46,7 @@ import static org.hibernate.generator.EventTypeSets.fromArray; * @author Steve Ebersole * @author Gavin King */ -public class CurrentTimestampGeneration implements InMemoryGenerator, InDatabaseGenerator { +public class CurrentTimestampGeneration implements BeforeExecutionGenerator, OnExecutionGenerator { private final EnumSet eventTypes; private final ValueGenerator generator; @@ -80,7 +80,7 @@ public class CurrentTimestampGeneration implements InMemoryGenerator, InDatabase } @Override - public boolean generatedByDatabase() { + public boolean generatedOnExecute() { return generator == null; } diff --git a/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedAlwaysGeneration.java b/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedAlwaysGeneration.java index 004d06065d..b1e6411ce5 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedAlwaysGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedAlwaysGeneration.java @@ -9,7 +9,7 @@ package org.hibernate.generator.internal; import org.hibernate.annotations.GeneratedColumn; import org.hibernate.dialect.Dialect; import org.hibernate.generator.EventType; -import org.hibernate.generator.InDatabaseGenerator; +import org.hibernate.generator.OnExecutionGenerator; import java.util.EnumSet; @@ -20,7 +20,7 @@ import static org.hibernate.generator.EventTypeSets.ALL; * * @author Gavin King */ -public class GeneratedAlwaysGeneration implements InDatabaseGenerator { +public class GeneratedAlwaysGeneration implements OnExecutionGenerator { public GeneratedAlwaysGeneration() {} diff --git a/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedGeneration.java b/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedGeneration.java index ce551a6d76..9692574eb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/internal/GeneratedGeneration.java @@ -10,7 +10,7 @@ import org.hibernate.annotations.Generated; import org.hibernate.annotations.GenerationTime; import org.hibernate.dialect.Dialect; import org.hibernate.generator.EventType; -import org.hibernate.generator.InDatabaseGenerator; +import org.hibernate.generator.OnExecutionGenerator; import java.util.EnumSet; @@ -18,7 +18,7 @@ import static org.hibernate.generator.EventTypeSets.fromArray; 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. * * @see Generated @@ -26,7 +26,7 @@ import static org.hibernate.internal.util.StringHelper.isEmpty; * @author Steve Ebersole * @author Gunnar Morling */ -public class GeneratedGeneration implements InDatabaseGenerator { +public class GeneratedGeneration implements OnExecutionGenerator { private final EnumSet eventTypes; private final boolean writable; diff --git a/hibernate-core/src/main/java/org/hibernate/generator/internal/SourceGeneration.java b/hibernate-core/src/main/java/org/hibernate/generator/internal/SourceGeneration.java index 9f8358415a..60c9d2a744 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/internal/SourceGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/internal/SourceGeneration.java @@ -17,7 +17,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.GeneratorCreationContext; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.tuple.TimestampGenerators; import org.hibernate.tuple.ValueGenerator; @@ -52,7 +52,7 @@ import static org.hibernate.generator.EventTypeSets.INSERT_ONLY; */ @Deprecated(since = "6.2") @Internal -public class SourceGeneration implements InMemoryGenerator { +public class SourceGeneration implements BeforeExecutionGenerator { private static final CoreMessageLogger log = Logger.getMessageLogger( CoreMessageLogger.class, diff --git a/hibernate-core/src/main/java/org/hibernate/generator/internal/TenantIdGeneration.java b/hibernate-core/src/main/java/org/hibernate/generator/internal/TenantIdGeneration.java index 0f8fb50c35..3112e11a32 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/internal/TenantIdGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/internal/TenantIdGeneration.java @@ -14,7 +14,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.type.descriptor.java.JavaType; @@ -30,7 +30,7 @@ import static org.hibernate.internal.util.ReflectHelper.getPropertyType; * * @author Gavin King */ -public class TenantIdGeneration implements InMemoryGenerator { +public class TenantIdGeneration implements BeforeExecutionGenerator { private final String entityName; private final String propertyName; diff --git a/hibernate-core/src/main/java/org/hibernate/generator/internal/VersionGeneration.java b/hibernate-core/src/main/java/org/hibernate/generator/internal/VersionGeneration.java index 9d582ce553..c8f8674081 100644 --- a/hibernate-core/src/main/java/org/hibernate/generator/internal/VersionGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/generator/internal/VersionGeneration.java @@ -8,7 +8,7 @@ package org.hibernate.generator.internal; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.metamodel.mapping.EntityVersionMapping; import java.util.EnumSet; @@ -31,7 +31,7 @@ import static org.hibernate.generator.EventTypeSets.INSERT_AND_UPDATE; * * @author Gavin King */ -public class VersionGeneration implements InMemoryGenerator { +public class VersionGeneration implements BeforeExecutionGenerator { private final EntityVersionMapping versionMapping; public VersionGeneration(EntityVersionMapping versionMapping) { diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGenerator.java index 08adc1521d..e5696cb49c 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGenerator.java @@ -18,7 +18,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; import org.hibernate.service.ServiceRegistry; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.type.Type; 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, * 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. *

- * This interface extends {@code InMemoryGenerator} with some additional + * This interface extends {@code BeforeExecutionGenerator} with some additional * machinery for {@linkplain #configure configuration}, and for caching * {@linkplain #initialize(SqlStringGenerationContext) generated SQL}. *

* 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 * {@code ExportableProducer}, in case the implementation needs to 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 PersistentIdentifierGenerator */ -public interface IdentifierGenerator extends InMemoryGenerator, ExportableProducer, Configurable { +public interface IdentifierGenerator extends BeforeExecutionGenerator, ExportableProducer, Configurable { /** * The configuration parameter holding the entity name */ diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java index 979af56fdb..4cd26c94a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java @@ -8,13 +8,13 @@ package org.hibernate.id; import org.hibernate.dialect.Dialect; 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.InsertGeneratedIdentifierDelegate; 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. *

* Delegates to the {@link org.hibernate.dialect.identity.IdentityColumnSupport} provided diff --git a/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentifierGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentifierGenerator.java index bb070c5be2..e47fc9d68d 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentifierGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentifierGenerator.java @@ -9,7 +9,7 @@ package org.hibernate.id; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; import org.hibernate.service.ServiceRegistry; -import org.hibernate.generator.InDatabaseGenerator; +import org.hibernate.generator.OnExecutionGenerator; import org.hibernate.type.Type; 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. * 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. * * @see IdentifierGenerator * * @author Gavin King */ -public interface PostInsertIdentifierGenerator extends InDatabaseGenerator, Configurable { +public interface PostInsertIdentifierGenerator extends OnExecutionGenerator, Configurable { /** * @return {@link EventTypeSets#INSERT_ONLY} diff --git a/hibernate-core/src/main/java/org/hibernate/id/SelectGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/SelectGenerator.java index 6188fe8ae3..757af998ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/SelectGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/SelectGenerator.java @@ -9,7 +9,7 @@ package org.hibernate.id; import java.util.Properties; 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.persister.entity.EntityPersister; import org.hibernate.service.ServiceRegistry; @@ -64,7 +64,7 @@ import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPrope * {@link org.hibernate.id.insert.UniqueKeySelectingDelegate}. *

* 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 retrieved. * * @see org.hibernate.annotations.NaturalId diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/BasicSelectingDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/BasicSelectingDelegate.java index d75ec74650..6e17d22a7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/BasicSelectingDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/BasicSelectingDelegate.java @@ -15,7 +15,7 @@ import org.hibernate.jdbc.Expectation; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.sql.model.ast.builder.TableInsertBuilder; 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 @@ -34,7 +34,7 @@ public class BasicSelectingDelegate extends AbstractSelectingDelegate { @Override @Deprecated public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) { IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect ); - insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (InDatabaseGenerator) persister.getGenerator() ); + insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (OnExecutionGenerator) persister.getGenerator() ); return insert; } @@ -46,7 +46,7 @@ public class BasicSelectingDelegate extends AbstractSelectingDelegate { final TableInsertBuilder builder = new TableInsertBuilderStandard( persister, persister.getIdentifierTableMapping(), factory ); - final InDatabaseGenerator generator = (InDatabaseGenerator) persister.getGenerator(); + final OnExecutionGenerator generator = (OnExecutionGenerator) persister.getGenerator(); if ( generator.referenceColumnsInSql( dialect ) ) { final String[] columnNames = persister.getRootTableKeyColumnNames(); final String[] columnValues = generator.getReferencedColumnValues( dialect ); diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/GetGeneratedKeysDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/GetGeneratedKeysDelegate.java index 1e744eabfc..97246daa23 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/GetGeneratedKeysDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/GetGeneratedKeysDelegate.java @@ -26,7 +26,7 @@ import org.hibernate.jdbc.Expectation; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; import org.hibernate.sql.model.ast.builder.TableInsertBuilder; 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 org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity; @@ -52,7 +52,7 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate { @Override @Deprecated public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) { IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect ); - insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (InDatabaseGenerator) persister.getGenerator() ); + insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (OnExecutionGenerator) persister.getGenerator() ); return insert; } @@ -64,7 +64,7 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate { final TableInsertBuilder builder = new TableInsertBuilderStandard( persister, persister.getIdentifierTableMapping(), factory ); - final InDatabaseGenerator generator = (InDatabaseGenerator) persister.getGenerator(); + final OnExecutionGenerator generator = (OnExecutionGenerator) persister.getGenerator(); if ( generator.referenceColumnsInSql( dialect ) ) { final String[] columnNames = persister.getRootTableKeyColumnNames(); final String[] columnValues = generator.getReferencedColumnValues( dialect ); diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java index 9b17098d93..b2c618fbdb 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java @@ -19,7 +19,7 @@ import org.hibernate.sql.model.ast.builder.TableInsertBuilder; /** * 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} * statement. The generated primary key is usually an {@code IDENTITY} * column, but in principle it might be something else, for example, @@ -31,9 +31,9 @@ import org.hibernate.sql.model.ast.builder.TableInsertBuilder; *

  • retrieving the generated identifier value using JDBC. * * 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 */ diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertReturningDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertReturningDelegate.java index b24d4410bf..e3b7f29f7f 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertReturningDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertReturningDelegate.java @@ -21,7 +21,7 @@ import org.hibernate.id.PostInsertIdentityPersister; import org.hibernate.jdbc.Expectation; import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping; 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 org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity; @@ -46,7 +46,7 @@ public class InsertReturningDelegate extends AbstractReturningDelegate { @Override @Deprecated public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) { InsertSelectIdentityInsert insert = new InsertSelectIdentityInsert( dialect ); - insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (InDatabaseGenerator) persister.getGenerator() ); + insert.addGeneratedColumns( persister.getRootTableKeyColumnNames(), (OnExecutionGenerator) persister.getGenerator() ); return insert; } diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertSelectIdentityInsert.java b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertSelectIdentityInsert.java index ba3375a15f..df34a0d730 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertSelectIdentityInsert.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertSelectIdentityInsert.java @@ -8,7 +8,7 @@ package org.hibernate.id.insert; import org.hibernate.MappingException; import org.hibernate.dialect.Dialect; import org.hibernate.sql.Insert; -import org.hibernate.generator.InDatabaseGenerator; +import org.hibernate.generator.OnExecutionGenerator; /** * Specialized {@link IdentifierGeneratingInsert} which appends the database @@ -26,7 +26,7 @@ public class InsertSelectIdentityInsert extends IdentifierGeneratingInsert { } @Override - public Insert addGeneratedColumns(String[] columnNames, InDatabaseGenerator generator) { + public Insert addGeneratedColumns(String[] columnNames, OnExecutionGenerator generator) { if ( columnNames.length != 1 ) { //TODO: Should this allow multiple columns? Would require changing // IdentityColumnSupport.appendIdentitySelectToInsert() diff --git a/hibernate-core/src/main/java/org/hibernate/id/uuid/UuidGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/uuid/UuidGenerator.java index bd16f3a561..c1ddbd98c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/uuid/UuidGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/uuid/UuidGenerator.java @@ -15,7 +15,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; 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.ValueTransformer; @@ -28,7 +28,7 @@ import static org.hibernate.internal.util.ReflectHelper.getPropertyType; * * @see org.hibernate.annotations.UuidGenerator */ -public class UuidGenerator implements InMemoryGenerator { +public class UuidGenerator implements BeforeExecutionGenerator { interface ValueGenerator { UUID generateUuid(SharedSessionContractImplementor session); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index c42603f62b..c8f32da2d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -33,7 +33,7 @@ import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.tuple.entity.EntityMetamodel; import jakarta.transaction.SystemException; @@ -101,8 +101,8 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen final Object id; final Object[] state = persister.getValues( entity ); final Generator generator = persister.getGenerator(); - if ( !generator.generatedByDatabase() ) { - id = ( (InMemoryGenerator) generator).generate( this, entity, null, INSERT ); + if ( !generator.generatedOnExecute() ) { + id = ( (BeforeExecutionGenerator) generator).generate( this, entity, null, INSERT ); if ( persister.isVersioned() ) { if ( seedVersion( entity, state, persister, this ) ) { persister.setValues( entity, state ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Component.java b/hibernate-core/src/main/java/org/hibernate/mapping/Component.java index 3aadc0fe4e..8dca365c07 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Component.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Component.java @@ -27,7 +27,6 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.Dialect; -import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.CompositeNestedGeneratedValueGenerator; 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.property.access.spi.Setter; import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.type.ComponentType; import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.Type; @@ -640,8 +639,8 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable @Override public void execute(SharedSessionContractImplementor session, Object incomingObject, Object injectionContext) { - if ( !subgenerator.generatedByDatabase() ) { - Object generatedId = ( (InMemoryGenerator) subgenerator).generate( session, incomingObject, null, INSERT ); + if ( !subgenerator.generatedOnExecute() ) { + Object generatedId = ( (BeforeExecutionGenerator) subgenerator).generate( session, incomingObject, null, INSERT ); injector.set( injectionContext, generatedId ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/GeneratedValueResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/GeneratedValueResolver.java index 5250d54bd5..876db04054 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/GeneratedValueResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/GeneratedValueResolver.java @@ -28,7 +28,7 @@ public interface GeneratedValueResolver { // else { // return generator.generatedByDatabase() // ? new InDatabaseGeneratedValueResolver( requestedTiming, dbSelectionPosition ) // in-db generation (column-default, function, etc) -// : new InMemoryGeneratedValueResolver( (InMemoryGenerator) generator, requestedTiming ); +// : new InMemoryGeneratedValueResolver( (BeforeExecutionGenerator) generator, requestedTiming ); // } // } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/InMemoryGeneratedValueResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/InMemoryGeneratedValueResolver.java index 637bb8d779..c5429674f5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/InMemoryGeneratedValueResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/InMemoryGeneratedValueResolver.java @@ -9,7 +9,7 @@ package org.hibernate.metamodel.mapping; import org.hibernate.Internal; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; /** * GeneratedValueResolver impl for in-memory generation @@ -19,9 +19,9 @@ import org.hibernate.generator.InMemoryGenerator; @Internal public class InMemoryGeneratedValueResolver implements GeneratedValueResolver { 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.eventType = eventType; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java index 2c64370e93..d31184b3a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/GeneratedValuesProcessor.java @@ -16,7 +16,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; 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.NoCallbackExecutionContext; 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; /** - * Responsible for retrieving {@linkplain InDatabaseGenerator + * Responsible for retrieving {@linkplain OnExecutionGenerator * database-generated} attribute values after an {@code insert} statement is executed. *

    * 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 * instance of {@link org.hibernate.id.insert.InsertGeneratedIdentifierDelegate}. * - * @see InDatabaseGenerator + * @see OnExecutionGenerator * * @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 * return a list of {@link AttributeMapping}s. */ @@ -94,7 +94,7 @@ public class GeneratedValuesProcessor { entityDescriptor.forEachAttributeMapping( mapping -> { final Generator generator = generators[ mapping.getStateArrayPosition() ]; if ( generator != null - && generator.generatedByDatabase() + && generator.generatedOnExecute() && generator.generatesSometimes() ) { // this attribute is generated for the timing we are processing... valueDescriptors.add( new GeneratedValueDescriptor( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index ab62f4b021..c67c52484c 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -52,7 +52,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SubselectFetch; import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.id.IdentifierGenerator; import org.hibernate.internal.FilterAliasGenerator; import org.hibernate.internal.FilterHelper; @@ -226,7 +226,7 @@ public abstract class AbstractCollectionPersister protected final SqlExceptionHelper sqlExceptionHelper; private final SessionFactoryImplementor factory; private final EntityPersister ownerPersister; - private final InMemoryGenerator identifierGenerator; + private final BeforeExecutionGenerator identifierGenerator; private final PropertyMapping elementPropertyMapping; private final EntityPersister elementPersister; private final CollectionDataAccess cacheAccessStrategy; @@ -622,19 +622,19 @@ public abstract class AbstractCollectionPersister tableMapping = buildCollectionTableMapping( collectionBootDescriptor, qualifiedTableName ); } - private InMemoryGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) { + private BeforeExecutionGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) { final Generator generator = collection.getIdentifier().createGenerator( context.getBootstrapContext().getIdentifierGeneratorFactory(), factory.getJdbcServices().getDialect(), null ); - if ( generator.generatedByDatabase() ) { - throw new MappingException("must be an InMemoryGenerator"); //TODO fix message + if ( generator.generatedOnExecute() ) { + throw new MappingException("must be an BeforeExecutionGenerator"); //TODO fix message } if ( generator instanceof IdentifierGenerator ) { ( (IdentifierGenerator) generator ).initialize( context.getSessionFactory().getSqlStringGenerationContext() ); } - return (InMemoryGenerator) generator; + return (BeforeExecutionGenerator) generator; } @Override @@ -1162,7 +1162,7 @@ public abstract class AbstractCollectionPersister } @Override - public InMemoryGenerator getGenerator() { + public BeforeExecutionGenerator getGenerator() { return identifierGenerator; } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java index 9767692171..282b3715d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/CollectionPersister.java @@ -33,7 +33,7 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.sql.ast.tree.from.TableGroup; 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.Type; @@ -241,7 +241,7 @@ public interface CollectionPersister extends Restrictable { /** * Get the surrogate key generation strategy (optional operation) */ - default InMemoryGenerator getGenerator() { + default BeforeExecutionGenerator getGenerator() { return getIdentifierGenerator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index ef31c70696..4fbb1f0de3 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -97,8 +97,8 @@ import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.LoadEvent; import org.hibernate.generator.EventType; import org.hibernate.generator.Generator; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.generator.internal.VersionGeneration; import org.hibernate.id.Assigned; import org.hibernate.id.BulkInsertionCapableIdentifierGenerator; @@ -432,7 +432,7 @@ public abstract class AbstractEntityPersister protected AttributeMappingsMap declaredAttributeMappings = AttributeMappingsMap.builder().build(); protected AttributeMappingsList staticFetchableList; - private InMemoryGenerator versionGenerator; + private BeforeExecutionGenerator versionGenerator; protected ReflectionOptimizer.AccessOptimizer accessOptimizer; @@ -3066,7 +3066,7 @@ public abstract class AbstractEntityPersister private void doLateInit() { if ( isIdentifierAssignedByInsert() ) { - final InDatabaseGenerator generator = (InDatabaseGenerator) getGenerator(); + final OnExecutionGenerator generator = (OnExecutionGenerator) getGenerator(); identityDelegate = generator.getGeneratedIdentifierDelegate( this ); } @@ -3840,7 +3840,7 @@ public abstract class AbstractEntityPersister } @Override - public InMemoryGenerator getVersionGenerator() { + public BeforeExecutionGenerator getVersionGenerator() { return versionGenerator; } @@ -4627,7 +4627,7 @@ public abstract class AbstractEntityPersister final EntityMetamodel currentEntityMetamodel = getEntityMetamodel(); 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 :-( versionGenerator = generator == null ? new VersionGeneration( versionMapping ) : generator; } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java index 779b6f4226..96e5d34df0 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java @@ -28,7 +28,7 @@ import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.event.spi.EventSource; import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.generator.internal.VersionGeneration; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; @@ -472,7 +472,7 @@ public interface EntityPersister extends EntityMappingType, RootTableGroupProduc return getIdentifierGenerator(); } - default InMemoryGenerator getVersionGenerator() { + default BeforeExecutionGenerator getVersionGenerator() { return new VersionGeneration( getVersionMapping() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/AbstractMutationCoordinator.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/AbstractMutationCoordinator.java index 26a3dadd02..dd6bd409e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/AbstractMutationCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/AbstractMutationCoordinator.java @@ -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.MutationOperationGroupSingle; 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 @@ -97,7 +97,7 @@ public abstract class AbstractMutationCoordinator { void handleValueGeneration( AttributeMapping attributeMapping, MutationGroupBuilder mutationGroupBuilder, - InDatabaseGenerator generator) { + OnExecutionGenerator generator) { final Dialect dialect = factory.getJdbcServices().getDialect(); final boolean writePropertyValue = generator.writePropertyValue(); final String[] columnValues = writePropertyValue ? null : generator.getReferencedColumnValues( dialect ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java index 31a8c68406..e6d6c5a25c 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/InsertCoordinator.java @@ -23,10 +23,7 @@ import org.hibernate.generator.EventType; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.metamodel.mapping.AttributeMapping; 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.SelectableMapping; import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.persister.entity.AttributeMappingsList; 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.TableInsertBuilderStandard; import org.hibernate.generator.Generator; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.tuple.entity.EntityMetamodel; /** @@ -114,9 +111,9 @@ public class InsertCoordinator extends AbstractMutationCoordinator { for ( int i = 0; i < generators.length; i++ ) { final Generator generator = generators[i]; if ( generator != null - && !generator.generatedByDatabase() + && !generator.generatedOnExecute() && 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] ); } } @@ -404,7 +401,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { if ( !attributeInclusions[ attributeIndex ] ) { final Generator generator = attributeMapping.getGenerator(); if ( isValueGenerationInSql( generator, factory().getJdbcServices().getDialect()) ) { - handleValueGeneration( attributeMapping, insertGroupBuilder, (InDatabaseGenerator) generator ); + handleValueGeneration( attributeMapping, insertGroupBuilder, (OnExecutionGenerator) generator ); } continue; } @@ -434,7 +431,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator { private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) { return generator != null && generator.generatesOnInsert() - && generator.generatedByDatabase() - && ( (InDatabaseGenerator) generator ).referenceColumnsInSql(dialect); + && generator.generatedOnExecute() + && ( (OnExecutionGenerator) generator ).referenceColumnsInSql(dialect); } } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java index 22a812d6fa..cfebe66798 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java @@ -32,11 +32,8 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.mapping.AttributeMapping; -import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EntityRowIdMapping; 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.persister.entity.AbstractEntityPersister; 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.builder.MutationGroupBuilder; 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.TableUpdateBuilderSkipped; import org.hibernate.sql.model.ast.builder.TableUpdateBuilderStandard; import org.hibernate.sql.model.internal.MutationOperationGroupSingle; import org.hibernate.sql.model.jdbc.JdbcMutationOperation; import org.hibernate.generator.Generator; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.tuple.entity.EntityMetamodel; import static org.hibernate.engine.OptimisticLockStyle.ALL; @@ -351,16 +347,16 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple private boolean isValueGenerationInSql(Generator generator, Dialect dialect) { return generator != null && generator.generatesOnUpdate() - && generator.generatedByDatabase() - && ((InDatabaseGenerator) generator).referenceColumnsInSql(dialect); + && generator.generatedOnExecute() + && ((OnExecutionGenerator) generator).referenceColumnsInSql(dialect); } private boolean isValueGenerationInSqlNoWrite(Generator generator, Dialect dialect) { return generator != null && generator.generatesOnUpdate() - && generator.generatedByDatabase() - && ((InDatabaseGenerator) generator).referenceColumnsInSql(dialect) - && !((InDatabaseGenerator) generator).writePropertyValue(); + && generator.generatedOnExecute() + && ((OnExecutionGenerator) generator).referenceColumnsInSql(dialect) + && !((OnExecutionGenerator) generator).writePropertyValue(); } /** @@ -463,9 +459,9 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple for ( int i = 0; i < generators.length; i++ ) { Generator generator = generators[i]; if ( generator != null - && !generator.generatedByDatabase() + && !generator.generatedOnExecute() && 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] ); fieldsPreUpdateNeeded[count++] = i; } @@ -947,7 +943,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple final Generator generator = attributeMapping.getGenerator(); if ( isValueGenerationInSql( generator, dialect() ) ) { - handleValueGeneration( attributeMapping, updateGroupBuilder, (InDatabaseGenerator) generator ); + handleValueGeneration( attributeMapping, updateGroupBuilder, (OnExecutionGenerator) generator ); } else if ( versionMapping != null && versionMapping.getVersionAttribute() == attributeMapping ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java index 9f323a457c..f64664afc7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java @@ -272,7 +272,7 @@ public class CteInsertHandler implements InsertHandler { rowNumberColumn ); } - if ( !assignsId && entityDescriptor.getGenerator().generatedByDatabase() ) { + if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecute() ) { querySpec.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, @@ -336,7 +336,7 @@ public class CteInsertHandler implements InsertHandler { processingStateStack.push( oldState ); sqmConverter.pruneTableGroupJoins(); - if ( !assignsId && entityDescriptor.getGenerator().generatedByDatabase() ) { + if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecute() ) { // Add the row number to the assignments final CteColumn rowNumberColumn = cteTable.getCteColumns() .get( cteTable.getCteColumns().size() - 1 ); @@ -580,7 +580,7 @@ public class CteInsertHandler implements InsertHandler { statement.addCteStatement( entityCte ); } } - else if ( !assignsId && entityDescriptor.getGenerator().generatedByDatabase() ) { + else if ( !assignsId && entityDescriptor.getGenerator().generatedOnExecute() ) { final String baseTableName = "base_" + entityCteTable.getTableExpression(); final CteStatement baseEntityCte = new CteStatement( entityCteTable.withName( baseTableName ), @@ -777,7 +777,7 @@ public class CteInsertHandler implements InsertHandler { final Generator identifierGenerator = entityDescriptor.getEntityPersister().getGenerator(); final List, Assignment>> tableAssignments = assignmentsByTable.get( rootTableReference ); if ( ( tableAssignments == null || tableAssignments.isEmpty() ) - && !( identifierGenerator.generatedByDatabase() ) ) { + && !identifierGenerator.generatedOnExecute() ) { 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 ); CteStatement finalCteStatement = null; final CteTable dmlResultCte; - if ( i == 0 && !assignsId && identifierGenerator.generatedByDatabase() ) { + if ( i == 0 && !assignsId && identifierGenerator.generatedOnExecute() ) { // Special handling for identity generation final String cteTableName = getCteTableName( tableExpression, "base_" ); if ( statement.getCteStatement( cteTableName ) != null ) { @@ -1074,7 +1074,7 @@ public class CteInsertHandler implements InsertHandler { if ( finalCteStatement != null ) { statement.addCteStatement( finalCteStatement ); } - if ( i == 0 && !assignsId && identifierGenerator.generatedByDatabase() ) { + if ( i == 0 && !assignsId && identifierGenerator.generatedOnExecute() ) { // Special handling for identity generation statement.addCteStatement( queryCte ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java index 81265d6546..9d86a047d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java @@ -75,8 +75,8 @@ import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.spi.ListResultsConsumer; import org.hibernate.generator.Generator; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.type.descriptor.ValueBinder; /** @@ -308,7 +308,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio final Generator generator = entityPersister.getGenerator(); final List assignments = assignmentsByTable.get( updatingTableReference ); if ( ( assignments == null || assignments.isEmpty() ) - && !generator.generatedByDatabase() + && !generator.generatedOnExecute() && ( !( generator instanceof BulkInsertionCapableIdentifierGenerator ) || ( (BulkInsertionCapableIdentifierGenerator) generator ).supportsBulkInsertionIdentifierGeneration() ) ) { 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 Map entityTableToRootIdentity; - if ( generator.generatedByDatabase() ) { + if ( generator.generatedOnExecute() ) { final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityDescriptor.getIdentifierMapping(); final QuerySpec idSelectQuerySpec = new QuerySpec( true ); idSelectQuerySpec.getFromClause().addRoot( temporaryTableGroup ); @@ -510,7 +510,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio rootIdentity, new JdbcParameterBindingImpl( identifierMapping.getJdbcMapping(), - ( (InMemoryGenerator) generator ).generate( executionContext.getSession(), null, null, EventType.INSERT ) + ( (BeforeExecutionGenerator) generator ).generate( executionContext.getSession(), null, null, EventType.INSERT ) ) ); jdbcServices.getJdbcMutationExecutor().execute( @@ -558,8 +558,8 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio .buildInsertTranslator( sessionFactory, insertStatement ) .translate( null, executionContext.getQueryOptions() ); - if ( generator.generatedByDatabase() ) { - final InDatabaseGenerator databaseGenerator = (InDatabaseGenerator) generator; + if ( generator.generatedOnExecute() ) { + final OnExecutionGenerator databaseGenerator = (OnExecutionGenerator) generator; final InsertGeneratedIdentifierDelegate identifierDelegate = databaseGenerator.getGeneratedIdentifierDelegate( (PostInsertIdentityPersister) entityPersister ); final String finalSql = identifierDelegate.prepareIdentifierGeneratingInsert( jdbcInsert.getSqlString() ); @@ -719,7 +719,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio final AbstractEntityPersister entityPersister = (AbstractEntityPersister) entityDescriptor.getEntityPersister(); final Generator identifierGenerator = entityPersister.getGenerator(); final boolean needsKeyInsert; - if ( identifierGenerator.generatedByDatabase() ) { + if ( identifierGenerator.generatedOnExecute() ) { needsKeyInsert = true; } else if ( identifierGenerator instanceof OptimizableGenerator ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 12b6f82557..838d3c192a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -42,7 +42,7 @@ import org.hibernate.engine.profile.FetchProfile; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.generator.Generator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.graph.spi.AppliedGraph; import org.hibernate.id.BulkInsertionCapableIdentifierGenerator; import org.hibernate.id.CompositeNestedGeneratedValueGenerator; @@ -1355,7 +1355,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base } // 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 = null; } @@ -1440,10 +1440,10 @@ public abstract class BaseSqmToSqlAstConverter extends Base if ( discriminatorExpression != null ) { expressions.add( discriminatorExpression ); } - if ( identifierGenerator != null && !identifierGenerator.generatedByDatabase() ) { + if ( identifierGenerator != null && !identifierGenerator.generatedOnExecute() ) { if ( identifierGeneratorParameter == null ) { identifierGeneratorParameter = - new IdGeneratorParameter( identifierMapping, (InMemoryGenerator) identifierGenerator ); + new IdGeneratorParameter( identifierMapping, (BeforeExecutionGenerator) identifierGenerator ); } expressions.add( identifierGeneratorParameter ); } @@ -1517,9 +1517,9 @@ public abstract class BaseSqmToSqlAstConverter extends Base 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() ); this.generator = generator; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Insert.java b/hibernate-core/src/main/java/org/hibernate/sql/Insert.java index 25bf6439e6..8f51546004 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Insert.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Insert.java @@ -14,7 +14,7 @@ import org.hibernate.Internal; import org.hibernate.MappingException; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.identity.IdentityColumnSupport; -import org.hibernate.generator.InDatabaseGenerator; +import org.hibernate.generator.OnExecutionGenerator; /** * An SQL {@code INSERT} statement @@ -98,7 +98,7 @@ public class Insert { return this; } - public Insert addGeneratedColumns(String[] columnNames, InDatabaseGenerator generator) { + public Insert addGeneratedColumns(String[] columnNames, OnExecutionGenerator generator) { if ( generator.referenceColumnsInSql( dialect ) ) { String[] columnValues = generator.getReferencedColumnValues( dialect ); if ( columnNames.length != columnValues.length ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/IdentifierProperty.java b/hibernate-core/src/main/java/org/hibernate/tuple/IdentifierProperty.java index 330441b101..92f4da3659 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/IdentifierProperty.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/IdentifierProperty.java @@ -42,7 +42,7 @@ public class IdentifierProperty extends AbstractAttribute implements IdentifierA this.embedded = embedded; this.hasIdentifierMapper = false; 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.hasIdentifierMapper = hasIdentifierMapper; this.identifierGenerator = identifierGenerator; - this.identifierAssignedByInsert = identifierGenerator.generatedByDatabase(); + this.identifierAssignedByInsert = identifierGenerator.generatedOnExecute(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/ValueGeneration.java b/hibernate-core/src/main/java/org/hibernate/tuple/ValueGeneration.java index ec4d90aa55..73dfc5dbf7 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/ValueGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/ValueGeneration.java @@ -8,19 +8,18 @@ package org.hibernate.tuple; import java.util.EnumSet; -import org.hibernate.Session; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; import org.hibernate.generator.Generator; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; /** * A value generator that can adapt to both Java value generation and database value generation. *

    * 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 Gavin King @@ -30,7 +29,7 @@ import org.hibernate.generator.InMemoryGenerator; * @deprecated Replaced by {@link Generator} */ @Deprecated(since = "6", forRemoval = true) -public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator { +public interface ValueGeneration extends BeforeExecutionGenerator, OnExecutionGenerator { /** * Specifies that the property value is generated: *

      @@ -84,7 +83,7 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator /** * 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 * might be: *
        @@ -101,7 +100,7 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator /** * 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 * might be: *
          @@ -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 * generated in Java using a {@link ValueGenerator}. */ - default boolean generatedByDatabase() { + @Override + default boolean generatedOnExecute() { return getValueGenerator() == null; } @@ -155,8 +155,9 @@ public interface ValueGeneration extends InMemoryGenerator, InDatabaseGenerator * * @see org.hibernate.annotations.Generated#writable() */ + @Override 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 || referenceColumnInSql() && getDatabaseGeneratedReferencedColumnValue()==null; } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/VmValueGeneration.java b/hibernate-core/src/main/java/org/hibernate/tuple/VmValueGeneration.java index 418ce1d780..a760953ffe 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/VmValueGeneration.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/VmValueGeneration.java @@ -11,16 +11,15 @@ import java.util.EnumSet; import org.hibernate.HibernateException; import org.hibernate.Internal; -import org.hibernate.Session; import org.hibernate.annotations.GeneratorType; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; 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. * * @author Gunnar Morling @@ -29,7 +28,7 @@ import static org.hibernate.internal.util.ReflectHelper.getDefaultConstructor; */ @Internal @Deprecated(since = "6.2") -public class VmValueGeneration implements InMemoryGenerator { +public class VmValueGeneration implements BeforeExecutionGenerator { private final EnumSet eventTypes; private final ValueGenerator generator; diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index 3acff37b25..7501a66f35 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -34,8 +34,8 @@ import org.hibernate.engine.spi.CascadingActions; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.generator.EventType; import org.hibernate.generator.Generator; -import org.hibernate.generator.InDatabaseGenerator; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.OnExecutionGenerator; +import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.ArrayHelper; @@ -141,7 +141,7 @@ public class EntityMetamodel implements Serializable { private final Set subclassEntityNames; private final Map,String> entityNameByInheritanceClassMap; - private final InMemoryGenerator versionGenerator; + private final BeforeExecutionGenerator versionGenerator; private final BytecodeEnhancementMetadata bytecodeEnhancementMetadata; @@ -237,7 +237,7 @@ public class EntityMetamodel implements Serializable { BitSet mutableIndexes = new BitSet(); boolean foundNonIdentifierPropertyNamedId = false; boolean foundUpdateableNaturalIdProperty = false; - InMemoryGenerator tempVersionGenerator = null; + BeforeExecutionGenerator tempVersionGenerator = null; List props = persistentClass.getPropertyClosure(); for ( int i=0; i inDatabaseStrategies; + private List inDatabaseStrategies; public CompositeGeneratorBuilder(Property mappingProperty, Dialect dialect) { this.mappingProperty = mappingProperty; @@ -520,26 +520,26 @@ public class EntityMetamodel implements Serializable { public void addPair(Generator generator) { if ( generator != null ) { - if ( generator.generatedByDatabase() ) { - if ( generator instanceof InDatabaseGenerator ) { - add( (InDatabaseGenerator) generator ); + if ( generator.generatedOnExecute() ) { + if ( generator instanceof OnExecutionGenerator ) { + add( (OnExecutionGenerator) generator ); } } else { - if ( generator instanceof InMemoryGenerator ) { - add( (InMemoryGenerator) generator ); + if ( generator instanceof BeforeExecutionGenerator ) { + add( (BeforeExecutionGenerator) generator ); } } } } - private void add(InMemoryGenerator inMemoryStrategy) { + private void add(BeforeExecutionGenerator inMemoryStrategy) { if ( inMemoryStrategy.generatesSometimes() ) { hadInMemoryGeneration = true; } } - private void add(InDatabaseGenerator inDatabaseStrategy) { + private void add(OnExecutionGenerator inDatabaseStrategy) { if ( inDatabaseStrategies == null ) { inDatabaseStrategies = new ArrayList<>(); } @@ -582,7 +582,7 @@ public class EntityMetamodel implements Serializable { int columnIndex = 0; for ( Property property : composite.getProperties() ) { propertyIndex++; - final InDatabaseGenerator generator = inDatabaseStrategies.get( propertyIndex ); + final OnExecutionGenerator generator = inDatabaseStrategies.get( propertyIndex ); eventTypes.addAll( generator.getEventTypes() ); if ( generator.referenceColumnsInSql(dialect) ) { // override base-line value @@ -607,7 +607,7 @@ public class EntityMetamodel implements Serializable { } // then use the aggregated values to build the InDatabaseValueGenerationStrategy - return new InDatabaseGeneratorImpl( eventTypes, referenceColumns, columnValues ); + return new OnExecutionGeneratorImpl( eventTypes, referenceColumns, columnValues ); } else { return new Generator() { @@ -615,7 +615,8 @@ public class EntityMetamodel implements Serializable { public EnumSet getEventTypes() { return NONE; } - public boolean generatedByDatabase() { + @Override + public boolean generatedOnExecute() { 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 eventTypes; private final boolean referenceColumnInSql; private final String[] referencedColumnValues; - private InDatabaseGeneratorImpl( + private OnExecutionGeneratorImpl( EnumSet eventTypes, boolean referenceColumnInSql, String[] referencedColumnValues) { @@ -691,12 +692,12 @@ public class EntityMetamodel implements Serializable { public boolean isVersionGeneratedByDatabase() { final Generator strategy = generators[ versionPropertyIndex ]; - return strategy != null && strategy.generatesSometimes() && strategy.generatedByDatabase(); + return strategy != null && strategy.generatesSometimes() && strategy.generatedOnExecute(); } public boolean isVersionGeneratedInMemory() { final Generator strategy = generators[ versionPropertyIndex ]; - return strategy != null && strategy.generatesSometimes() && !strategy.generatedByDatabase(); + return strategy != null && strategy.generatesSometimes() && !strategy.generatedOnExecute(); } public int[] getNaturalIdentifierProperties() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java index 4ba81ef721..18d445d803 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java @@ -22,7 +22,7 @@ import org.hibernate.annotations.ValueGenerationType; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; 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.SessionFactory; @@ -85,7 +85,7 @@ public class GeneratedUuidTests { //end::mapping-generated-custom-ex2[] //tag::mapping-generated-custom-ex3[] - public static class UuidValueGeneration implements InMemoryGenerator { + public static class UuidValueGeneration implements BeforeExecutionGenerator { private final EnumSet eventTypes; public UuidValueGeneration(GeneratedUuidValue annotation) {