HHH-15393 - Improve write-paths to use mapping model
This commit is contained in:
parent
ee1788c3c3
commit
6035ab8e66
|
@ -127,31 +127,8 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
SharedSessionContractImplementor session) {
|
||||
final EntityVersionMapping versionMapping = entityPersister().getVersionMapping();
|
||||
if ( versionMapping != null ) {
|
||||
// see if this is a simple version update
|
||||
boolean isSimpleVersionUpdate = false;
|
||||
Object newVersion = null;
|
||||
|
||||
if ( incomingDirtyAttributeIndexes != null ) {
|
||||
if ( incomingDirtyAttributeIndexes.length == 1
|
||||
&& versionMapping.getVersionAttribute() == entityPersister().getAttributeMapping( incomingDirtyAttributeIndexes[0] ) ) {
|
||||
// special case of only the version attribute itself as dirty
|
||||
isSimpleVersionUpdate = true;
|
||||
newVersion = values[incomingDirtyAttributeIndexes[0]];
|
||||
}
|
||||
else if ( incomingDirtyAttributeIndexes.length == 0 && oldVersion != null ) {
|
||||
isSimpleVersionUpdate = !versionMapping.areEqual(
|
||||
values[ versionMapping.getVersionAttribute().getStateArrayPosition() ],
|
||||
oldVersion,
|
||||
session
|
||||
);
|
||||
newVersion = values[versionMapping.getVersionAttribute().getStateArrayPosition()];
|
||||
}
|
||||
}
|
||||
|
||||
if ( isSimpleVersionUpdate ) {
|
||||
// we have just the version being updated - use the special handling
|
||||
assert newVersion != null;
|
||||
doVersionUpdate( entity, id, newVersion, oldVersion, session );
|
||||
final boolean isForcedVersionIncrement = handlePotentialImplicitForcedVersionIncrement( entity, id, values, oldVersion, incomingDirtyAttributeIndexes, session, versionMapping );
|
||||
if ( isForcedVersionIncrement ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -315,6 +292,46 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
}
|
||||
}
|
||||
|
||||
private boolean handlePotentialImplicitForcedVersionIncrement(
|
||||
Object entity,
|
||||
Object id,
|
||||
Object[] values,
|
||||
Object oldVersion,
|
||||
int[] incomingDirtyAttributeIndexes,
|
||||
SharedSessionContractImplementor session,
|
||||
EntityVersionMapping versionMapping) {
|
||||
// handle case where the only value being updated is the version.
|
||||
// we handle this case specially from `#coordinateUpdate` to leverage
|
||||
// `#doVersionUpdate`
|
||||
boolean isSimpleVersionUpdate = false;
|
||||
Object newVersion = null;
|
||||
|
||||
if ( incomingDirtyAttributeIndexes != null ) {
|
||||
if ( incomingDirtyAttributeIndexes.length == 1
|
||||
&& versionMapping.getVersionAttribute() == entityPersister().getAttributeMapping( incomingDirtyAttributeIndexes[0] ) ) {
|
||||
// special case of only the version attribute itself as dirty
|
||||
isSimpleVersionUpdate = true;
|
||||
newVersion = values[ incomingDirtyAttributeIndexes[0]];
|
||||
}
|
||||
else if ( incomingDirtyAttributeIndexes.length == 0 && oldVersion != null ) {
|
||||
isSimpleVersionUpdate = !versionMapping.areEqual(
|
||||
values[ versionMapping.getVersionAttribute().getStateArrayPosition() ],
|
||||
oldVersion,
|
||||
session
|
||||
);
|
||||
newVersion = values[ versionMapping.getVersionAttribute().getStateArrayPosition()];
|
||||
}
|
||||
}
|
||||
|
||||
if ( isSimpleVersionUpdate ) {
|
||||
// we have just the version being updated - use the special handling
|
||||
assert newVersion != null;
|
||||
doVersionUpdate( entity, id, newVersion, oldVersion, session );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isValueGenerationInSql(Generator generator) {
|
||||
return generator != null
|
||||
&& generator.getGenerationTiming().includesUpdate()
|
||||
|
|
|
@ -39,15 +39,16 @@ import org.hibernate.mapping.GeneratorCreator;
|
|||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.Subclass;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.spi.PersisterCreationContext;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.tuple.GenerationTiming;
|
||||
import org.hibernate.tuple.Generator;
|
||||
import org.hibernate.tuple.GeneratorCreationContext;
|
||||
import org.hibernate.tuple.InDatabaseGenerator;
|
||||
import org.hibernate.tuple.GenerationTiming;
|
||||
import org.hibernate.tuple.IdentifierProperty;
|
||||
import org.hibernate.tuple.InDatabaseGenerator;
|
||||
import org.hibernate.tuple.InMemoryGenerator;
|
||||
import org.hibernate.tuple.NonIdentifierAttribute;
|
||||
import org.hibernate.tuple.PropertyFactory;
|
||||
|
@ -65,7 +66,11 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
|
|||
* Centralizes metamodel information about an entity.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @deprecated Replaced by {@link EntityMappingType}. EntityMetamodel
|
||||
* was a first attempt at what has become {@link EntityMappingType}
|
||||
*/
|
||||
@Deprecated( since = "6", forRemoval = true )
|
||||
public class EntityMetamodel implements Serializable {
|
||||
private static final CoreMessageLogger LOG = messageLogger( EntityMetamodel.class );
|
||||
|
||||
|
|
Loading…
Reference in New Issue