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:
parent
f3e31fe427
commit
64d0cf804a
|
@ -23,7 +23,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||
* <p>
|
||||
* For example, if we have a custom identifier generator:
|
||||
* <pre>{@code
|
||||
* public class CustomSequenceGenerator implements InMemoryGenerator {
|
||||
* public class CustomSequenceGenerator implements BeforeExecutionGenerator {
|
||||
* public CustomSequenceGenerator(CustomSequence config, Member annotatedMember,
|
||||
* CustomIdGeneratorCreationContext context) {
|
||||
* ...
|
||||
|
|
|
@ -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:
|
||||
* <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
|
||||
* <li>an {@link InDatabaseGenerator}, for values which are generated by the
|
||||
* <li>an {@link OnExecutionGenerator}, for values which are generated by the
|
||||
* database.
|
||||
* </ul>
|
||||
* 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
|
||||
|
|
|
@ -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<? extends Generator> 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'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
* 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[])}.
|
||||
* <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() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<C>
|
|||
|
||||
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() );
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import java.lang.reflect.Member;
|
|||
* {@code AnnotationType} is the generator annotation type used to configure the
|
||||
* generator.
|
||||
* <p>
|
||||
* 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 <A> The generator annotation type supported by an implementation
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
* <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
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <ul>
|
||||
* <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
|
||||
* 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
|
||||
* 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. In this case, the generated value may be retrieved from the database using a
|
||||
* 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>
|
||||
* 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.
|
||||
* <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
|
||||
* 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
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <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>
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -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<EventType> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {}
|
||||
|
||||
|
|
|
@ -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<EventType> eventTypes;
|
||||
private final boolean writable;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
* <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
|
||||
* {@linkplain #initialize(SqlStringGenerationContext) generated SQL}.
|
||||
* <p>
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* Delegates to the {@link org.hibernate.dialect.identity.IdentityColumnSupport} provided
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}.
|
||||
* <p>
|
||||
* 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>.
|
||||
*
|
||||
* @see org.hibernate.annotations.NaturalId
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
|||
* <li>retrieving the generated identifier value using JDBC.
|
||||
* </ul>
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 );
|
||||
// }
|
||||
// }
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* 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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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<Map.Entry<List<CteColumn>, 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 );
|
||||
}
|
||||
|
|
|
@ -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<Assignment> 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<Object, Object> 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 ) {
|
||||
|
|
|
@ -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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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;
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* 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:
|
||||
* <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
|
||||
* 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:
|
||||
* <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
|
||||
* 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:
|
||||
* <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
|
||||
* 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;
|
||||
}
|
||||
|
|
|
@ -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<EventType> eventTypes;
|
||||
private final ValueGenerator<?> generator;
|
||||
|
|
|
@ -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<String> subclassEntityNames;
|
||||
private final Map<Class<?>,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<Property> props = persistentClass.getPropertyClosure();
|
||||
for ( int i=0; i<props.size(); i++ ) {
|
||||
|
@ -312,12 +312,12 @@ public class EntityMetamodel implements Serializable {
|
|||
// generated value strategies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
final Generator generator = buildGenerator( property, creationContext );
|
||||
if ( generator != null ) {
|
||||
if ( i == tempVersionProperty && !generator.generatedByDatabase() ) {
|
||||
if ( i == tempVersionProperty && !generator.generatedOnExecute() ) {
|
||||
// when we have an in-memory generator for the version, we
|
||||
// want to plug it in to the older infrastructure specific
|
||||
// to version generation, instead of treating it like a
|
||||
// plain "value" generator for a regular attribute
|
||||
tempVersionGenerator = (InMemoryGenerator) generator;
|
||||
tempVersionGenerator = (BeforeExecutionGenerator) generator;
|
||||
}
|
||||
else {
|
||||
generators[i] = generator;
|
||||
|
@ -326,7 +326,7 @@ public class EntityMetamodel implements Serializable {
|
|||
propertyUpdateability[i] = false;
|
||||
}
|
||||
if ( generator.generatesOnInsert() ) {
|
||||
if ( generator.generatedByDatabase() ) {
|
||||
if ( generator.generatedOnExecute() ) {
|
||||
foundPostInsertGeneratedValues = true;
|
||||
}
|
||||
else {
|
||||
|
@ -334,7 +334,7 @@ public class EntityMetamodel implements Serializable {
|
|||
}
|
||||
}
|
||||
if ( generator.generatesOnUpdate() ) {
|
||||
if ( generator.generatedByDatabase() ) {
|
||||
if ( generator.generatedOnExecute() ) {
|
||||
foundPostUpdateGeneratedValues = true;
|
||||
}
|
||||
else {
|
||||
|
@ -464,8 +464,8 @@ public class EntityMetamodel implements Serializable {
|
|||
}
|
||||
|
||||
private static boolean generatedWithNoParameter(Generator generator) {
|
||||
return generator.generatedByDatabase()
|
||||
&& !((InDatabaseGenerator) generator).writePropertyValue();
|
||||
return generator.generatedOnExecute()
|
||||
&& !((OnExecutionGenerator) generator).writePropertyValue();
|
||||
}
|
||||
|
||||
private static Generator buildGenerator(
|
||||
|
@ -494,7 +494,7 @@ public class EntityMetamodel implements Serializable {
|
|||
return generators;
|
||||
}
|
||||
|
||||
public InMemoryGenerator getVersionGenerator() {
|
||||
public BeforeExecutionGenerator getVersionGenerator() {
|
||||
return versionGenerator;
|
||||
}
|
||||
|
||||
|
@ -511,7 +511,7 @@ public class EntityMetamodel implements Serializable {
|
|||
private boolean hadInMemoryGeneration;
|
||||
private boolean hadInDatabaseGeneration;
|
||||
|
||||
private List<InDatabaseGenerator> inDatabaseStrategies;
|
||||
private List<OnExecutionGenerator> 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<EventType> 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<EventType> eventTypes;
|
||||
private final boolean referenceColumnInSql;
|
||||
private final String[] referencedColumnValues;
|
||||
|
||||
private InDatabaseGeneratorImpl(
|
||||
private OnExecutionGeneratorImpl(
|
||||
EnumSet<EventType> 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() {
|
||||
|
|
|
@ -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<EventType> eventTypes;
|
||||
|
||||
public UuidValueGeneration(GeneratedUuidValue annotation) {
|
||||
|
|
Loading…
Reference in New Issue