Skip to content

Commit

Permalink
HHH-17406 Change EntityPersister mutation api to expose coordinators
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Dec 22, 2023
1 parent b630fc8 commit cd9e86a
Show file tree
Hide file tree
Showing 22 changed files with 757 additions and 665 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void execute() throws HibernateException {
final Object ck = lockCacheItem();

if ( !isCascadeDeleteEnabled && !veto ) {
persister.delete( id, version, instance, session );
persister.getDeleteCoordinator().delete( instance, id, version, session );
}

if ( isInstanceLoaded() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ public void execute() throws HibernateException {
if ( !veto ) {
final EntityPersister persister = getPersister();
final Object instance = getInstance();
final GeneratedValues generatedValues = persister.insertReturning( id, getState(), instance, session );
final GeneratedValues generatedValues = persister.getInsertCoordinator().insert(
instance,
id,
getState(),
session
);
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( instance );
if ( entry == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ public void execute() throws HibernateException {
final Object instance = getInstance();
final Object previousVersion = getPreviousVersion();
final Object ck = lockCacheItem( previousVersion );
final GeneratedValues generatedValues = persister.updateReturning(
final GeneratedValues generatedValues = persister.getUpdateCoordinator().update(
instance,
id,
rowId,
state,
previousVersion,
previousState,
dirtyFields,
hasDirtyCollection,
previousState,
previousVersion,
instance,
rowId,
session
);
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( instance );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public UniqueKeySelectingDelegate(
}
}

@Override
protected String getSelectSQL() {
return selectString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.hibernate.engine.internal.Versioning.seedVersion;
import static org.hibernate.engine.internal.Versioning.setVersion;
import static org.hibernate.generator.EventType.INSERT;
import static org.hibernate.internal.util.NullnessUtil.castNonNull;
import static org.hibernate.pretty.MessageHelper.infoString;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;

Expand Down Expand Up @@ -108,11 +109,11 @@ public Object insert(String entityName, Object entity) {
persister.setValues( entity, state );
}
}
persister.insertReturning( id, state, entity, this );
persister.getInsertCoordinator().insert( entity, id, state, this );
}
else {
final GeneratedValues generatedValues = persister.insertReturning( state, entity, this );
id = generatedValues.getGeneratedValue( persister.getIdentifierMapping() );
final GeneratedValues generatedValues = persister.getInsertCoordinator().insert( entity, state, this );
id = castNonNull( generatedValues ).getGeneratedValue( persister.getIdentifierMapping() );
}
persister.setIdentifier( entity, id, this );
return id;
Expand All @@ -133,7 +134,7 @@ public void delete(String entityName, Object entity) {
final EntityPersister persister = getEntityPersister( entityName, entity );
final Object id = persister.getIdentifier( entity, this );
final Object version = persister.getVersion( entity );
persister.delete( id, version, entity, this );
persister.getDeleteCoordinator().delete( entity, id, version, this );
}


Expand Down Expand Up @@ -167,7 +168,7 @@ public void update(String entityName, Object entity) {
else {
oldVersion = null;
}
persister.updateReturning( id, state, null, false, null, oldVersion, entity, null, this );
persister.getUpdateCoordinator().update( entity, id, null, state, oldVersion, null, null, false, this );
}

@Override
Expand Down Expand Up @@ -203,7 +204,7 @@ public void upsert(String entityName, Object entity) {
else {
oldVersion = null;
}
persister.merge( id, state, null, false, null, oldVersion, entity, null, this );
persister.getMergeCoordinator().update( entity, id, null, state, oldVersion, null, null, false, this );
// persister.setIdentifier( entity, id, this );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
import org.hibernate.persister.entity.mutation.EntityMutationTarget;
import org.hibernate.persister.entity.mutation.EntityTableMapping;
import org.hibernate.persister.entity.mutation.InsertCoordinator;
import org.hibernate.persister.entity.mutation.InsertCoordinatorStandard;
import org.hibernate.persister.entity.mutation.MergeCoordinator;
import org.hibernate.persister.entity.mutation.UpdateCoordinator;
import org.hibernate.persister.entity.mutation.UpdateCoordinatorNoOp;
Expand Down Expand Up @@ -1050,22 +1051,22 @@ SingleIdArrayLoadPlan getSQLLazySelectLoadPlan(String fetchGroup) {
return lazyLoadPlanByFetchGroup.get( fetchGroup );
}

@Internal
@Override
public InsertCoordinator getInsertCoordinator() {
return insertCoordinator;
}

@Internal
@Override
public UpdateCoordinator getUpdateCoordinator() {
return updateCoordinator;
}

@Internal
@Override
public DeleteCoordinator getDeleteCoordinator() {
return deleteCoordinator;
}

@Internal
@Override
public UpdateCoordinator getMergeCoordinator() {
return mergeCoordinator;
}
Expand Down Expand Up @@ -2811,60 +2812,6 @@ public String getSelectByUniqueKeyString(String[] propertyNames, String[] column
return select.toStatementString();
}

/**
* Update an object
*/
@Override
public GeneratedValues updateReturning(
final Object id,
final Object[] values,
int[] dirtyAttributeIndexes,
final boolean hasDirtyCollection,
final Object[] oldValues,
final Object oldVersion,
final Object object,
final Object rowId,
final SharedSessionContractImplementor session) throws HibernateException {
return updateCoordinator.coordinateUpdate(
object,
id,
rowId,
values,
oldVersion,
oldValues,
dirtyAttributeIndexes,
hasDirtyCollection,
session
);
}

/**
* Merge an object
*/
@Override
public void merge(
final Object id,
final Object[] values,
int[] dirtyAttributeIndexes,
final boolean hasDirtyCollection,
final Object[] oldValues,
final Object oldVersion,
final Object object,
final Object rowId,
final SharedSessionContractImplementor session) throws HibernateException {
mergeCoordinator.coordinateUpdate(
object,
id,
rowId,
values,
oldVersion,
oldValues,
dirtyAttributeIndexes,
hasDirtyCollection,
session
);
}

@Internal
public boolean hasLazyDirtyFields(int[] dirtyFields) {
final boolean[] propertyLaziness = getPropertyLaziness();
Expand All @@ -2886,16 +2833,6 @@ public GeneratedValuesMutationDelegate getUpdateDelegate() {
return updateDelegate;
}

@Override
public GeneratedValues insertReturning(Object[] fields, Object object, SharedSessionContractImplementor session) {
return insertCoordinator.coordinateInsert( null, fields, object, session );
}

@Override
public GeneratedValues insertReturning(Object id, Object[] fields, Object object, SharedSessionContractImplementor session) {
return insertCoordinator.coordinateInsert( id, fields, object, session );
}

protected EntityTableMapping[] getTableMappings() {
return tableMappings;
}
Expand Down Expand Up @@ -2999,7 +2936,7 @@ protected boolean hasAnySkippableTables(boolean[] optionalTables, boolean[] inve
*/
@Override
public void delete(Object id, Object version, Object object, SharedSessionContractImplementor session) {
deleteCoordinator.coordinateDelete( object, id, version, session );
deleteCoordinator.delete( object, id, version, session );
}

/**
Expand All @@ -3021,7 +2958,7 @@ protected void logStaticSQL() {
}

{
final MutationOperationGroup staticInsertGroup = insertCoordinator.getStaticInsertGroup();
final MutationOperationGroup staticInsertGroup = insertCoordinator.getStaticMutationOperationGroup();
if ( staticInsertGroup != null ) {
for ( int i = 0; i < staticInsertGroup.getNumberOfOperations(); i++ ) {
final MutationOperation mutation = staticInsertGroup.getOperation( i );
Expand All @@ -3033,7 +2970,7 @@ protected void logStaticSQL() {
}

{
final MutationOperationGroup staticUpdateGroup = updateCoordinator.getStaticUpdateGroup();
final MutationOperationGroup staticUpdateGroup = updateCoordinator.getStaticMutationOperationGroup();
if ( staticUpdateGroup != null ) {
for ( int i = 0; i < staticUpdateGroup.getNumberOfOperations(); i++ ) {
final MutationOperation mutation = staticUpdateGroup.getOperation( i );
Expand All @@ -3045,7 +2982,7 @@ protected void logStaticSQL() {
}

{
final MutationOperationGroup staticDeleteGroup = deleteCoordinator.getStaticDeleteGroup();
final MutationOperationGroup staticDeleteGroup = deleteCoordinator.getStaticMutationOperationGroup();
if ( staticDeleteGroup != null ) {
for ( int i = 0; i < staticDeleteGroup.getNumberOfOperations(); i++ ) {
final MutationOperation mutation = staticDeleteGroup.getOperation( i );
Expand Down Expand Up @@ -3670,7 +3607,7 @@ private void collectAttributesIndexesForTable(int naturalTableIndex, Consumer<In
protected abstract boolean isIdentifierTable(String tableExpression);

protected InsertCoordinator buildInsertCoordinator() {
return new InsertCoordinator( this, factory );
return new InsertCoordinatorStandard( this, factory );
}

protected UpdateCoordinator buildUpdateCoordinator() {
Expand Down Expand Up @@ -6400,7 +6337,7 @@ protected boolean isInverseSubclassTable(int j) {
@Deprecated(forRemoval = true)
@Remove
public String[] getSQLDeleteStrings() {
return extractSqlStrings( deleteCoordinator.getStaticDeleteGroup() );
return extractSqlStrings( deleteCoordinator.getStaticMutationOperationGroup() );
}

private String[] extractSqlStrings(MutationOperationGroup operationGroup) {
Expand All @@ -6422,7 +6359,7 @@ private String[] extractSqlStrings(MutationOperationGroup operationGroup) {
@Deprecated(forRemoval = true)
@Remove
public String[] getSQLUpdateStrings() {
return extractSqlStrings( updateCoordinator.getStaticUpdateGroup() );
return extractSqlStrings( updateCoordinator.getStaticMutationOperationGroup() );
}

/**
Expand Down
Loading

0 comments on commit cd9e86a

Please sign in to comment.