HHH-16900 Rework mutation group API
This commit is contained in:
parent
814923dd46
commit
c608ee3a98
|
@ -71,7 +71,7 @@ public class MutationExecutorPostInsert implements MutationExecutor, JdbcValueBi
|
||||||
);
|
);
|
||||||
this.mutationOperationGroup = mutationOperationGroup;
|
this.mutationOperationGroup = mutationOperationGroup;
|
||||||
|
|
||||||
final PreparableMutationOperation identityInsertOperation = mutationOperationGroup.getOperation( mutationTarget.getIdentifierTableName() );
|
final PreparableMutationOperation identityInsertOperation = (PreparableMutationOperation) mutationOperationGroup.getOperation( mutationTarget.getIdentifierTableName() );
|
||||||
this.identityInsertStatementDetails = ModelMutationHelper.identityPreparation(
|
this.identityInsertStatementDetails = ModelMutationHelper.identityPreparation(
|
||||||
identityInsertOperation,
|
identityInsertOperation,
|
||||||
session
|
session
|
||||||
|
@ -79,9 +79,8 @@ public class MutationExecutorPostInsert implements MutationExecutor, JdbcValueBi
|
||||||
|
|
||||||
List<PreparableMutationOperation> secondaryTableMutations = null;
|
List<PreparableMutationOperation> secondaryTableMutations = null;
|
||||||
|
|
||||||
final List<MutationOperation> operations = mutationOperationGroup.getOperations();
|
for ( int i = 0; i < mutationOperationGroup.getNumberOfOperations(); i++ ) {
|
||||||
for ( int i = 0; i < operations.size(); i++ ) {
|
final MutationOperation operation = mutationOperationGroup.getOperation( i );
|
||||||
final MutationOperation operation = operations.get( i );
|
|
||||||
|
|
||||||
if ( operation.getTableDetails().isIdentifierTable() ) {
|
if ( operation.getTableDetails().isIdentifierTable() ) {
|
||||||
// the identifier table is handled via `identityInsertStatementDetails`
|
// the identifier table is handled via `identityInsertStatementDetails`
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class MutationExecutorPostInsertSingleTable implements MutationExecutor,
|
||||||
|
|
||||||
assert mutationOperationGroup.getNumberOfOperations() == 1;
|
assert mutationOperationGroup.getNumberOfOperations() == 1;
|
||||||
|
|
||||||
this.operation = mutationOperationGroup.getOperation( mutationTarget.getIdentifierTableName() );
|
this.operation = (PreparableMutationOperation) mutationOperationGroup.getOperation( mutationTarget.getIdentifierTableName() );
|
||||||
this.identityInsertStatementDetails = identityPreparation( operation, session );
|
this.identityInsertStatementDetails = identityPreparation( operation, session );
|
||||||
|
|
||||||
this.valueBindings = new JdbcValueBindingsImpl(
|
this.valueBindings = new JdbcValueBindingsImpl(
|
||||||
|
|
|
@ -11,7 +11,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.hibernate.engine.jdbc.batch.spi.Batch;
|
import org.hibernate.engine.jdbc.batch.spi.Batch;
|
||||||
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
|
import org.hibernate.engine.jdbc.batch.spi.BatchKey;
|
||||||
|
@ -23,7 +22,6 @@ import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
|
||||||
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementGroup;
|
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementGroup;
|
||||||
import org.hibernate.engine.jdbc.mutation.spi.BatchKeyAccess;
|
import org.hibernate.engine.jdbc.mutation.spi.BatchKeyAccess;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
|
||||||
import org.hibernate.sql.model.MutationOperation;
|
import org.hibernate.sql.model.MutationOperation;
|
||||||
import org.hibernate.sql.model.MutationOperationGroup;
|
import org.hibernate.sql.model.MutationOperationGroup;
|
||||||
import org.hibernate.sql.model.PreparableMutationOperation;
|
import org.hibernate.sql.model.PreparableMutationOperation;
|
||||||
|
@ -79,12 +77,10 @@ public class MutationExecutorStandard extends AbstractMutationExecutor implement
|
||||||
List<PreparableMutationOperation> nonBatchedJdbcMutations = null;
|
List<PreparableMutationOperation> nonBatchedJdbcMutations = null;
|
||||||
List<SelfExecutingUpdateOperation> selfExecutingMutations = null;
|
List<SelfExecutingUpdateOperation> selfExecutingMutations = null;
|
||||||
|
|
||||||
final List<MutationOperation> operations = mutationOperationGroup.getOperations();
|
|
||||||
|
|
||||||
boolean hasAnyNonBatchedJdbcOperations = false;
|
boolean hasAnyNonBatchedJdbcOperations = false;
|
||||||
|
|
||||||
for ( int i = operations.size() - 1; i >= 0; i-- ) {
|
for ( int i = mutationOperationGroup.getNumberOfOperations() - 1; i >= 0; i-- ) {
|
||||||
final MutationOperation operation = operations.get( i );
|
final MutationOperation operation = mutationOperationGroup.getOperation( i );
|
||||||
if ( operation instanceof SelfExecutingUpdateOperation ) {
|
if ( operation instanceof SelfExecutingUpdateOperation ) {
|
||||||
final SelfExecutingUpdateOperation selfExecutingMutation = (SelfExecutingUpdateOperation) operation;
|
final SelfExecutingUpdateOperation selfExecutingMutation = (SelfExecutingUpdateOperation) operation;
|
||||||
if ( selfExecutingMutations == null ) {
|
if ( selfExecutingMutations == null ) {
|
||||||
|
|
|
@ -255,6 +255,7 @@ import org.hibernate.sql.ast.tree.select.SelectClause;
|
||||||
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
import org.hibernate.sql.ast.tree.select.SelectStatement;
|
||||||
import org.hibernate.sql.exec.spi.JdbcOperation;
|
import org.hibernate.sql.exec.spi.JdbcOperation;
|
||||||
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
import org.hibernate.sql.exec.spi.JdbcParametersList;
|
||||||
|
import org.hibernate.sql.model.MutationOperation;
|
||||||
import org.hibernate.sql.model.MutationOperationGroup;
|
import org.hibernate.sql.model.MutationOperationGroup;
|
||||||
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
|
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
|
||||||
import org.hibernate.sql.results.graph.DomainResult;
|
import org.hibernate.sql.results.graph.DomainResult;
|
||||||
|
@ -2919,25 +2920,41 @@ public abstract class AbstractEntityPersister
|
||||||
LOG.debugf( " Version select: %s", sqlVersionSelectString );
|
LOG.debugf( " Version select: %s", sqlVersionSelectString );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( insertCoordinator.getStaticInsertGroup() != null ) {
|
{
|
||||||
insertCoordinator.getStaticInsertGroup().forEachOperation( (tablePosition, mutation) -> {
|
final MutationOperationGroup staticInsertGroup = insertCoordinator.getStaticInsertGroup();
|
||||||
|
if ( staticInsertGroup != null ) {
|
||||||
|
for ( int i = 0; i < staticInsertGroup.getNumberOfOperations(); i++ ) {
|
||||||
|
final MutationOperation mutation = staticInsertGroup.getOperation( i );
|
||||||
if ( mutation instanceof JdbcOperation ) {
|
if ( mutation instanceof JdbcOperation ) {
|
||||||
LOG.debugf( " Insert (%s): %s", tablePosition, ( (JdbcOperation) mutation ).getSqlString() );
|
LOG.debugf( " Insert (%s): %s", i, ( (JdbcOperation) mutation ).getSqlString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCoordinator.getStaticUpdateGroup().forEachOperation( (tablePosition, mutation) -> {
|
{
|
||||||
|
final MutationOperationGroup staticUpdateGroup = updateCoordinator.getStaticUpdateGroup();
|
||||||
|
if ( staticUpdateGroup != null ) {
|
||||||
|
for ( int i = 0; i < staticUpdateGroup.getNumberOfOperations(); i++ ) {
|
||||||
|
final MutationOperation mutation = staticUpdateGroup.getOperation( i );
|
||||||
if ( mutation instanceof JdbcOperation ) {
|
if ( mutation instanceof JdbcOperation ) {
|
||||||
LOG.debugf( " Update (%s): %s", tablePosition, ( (JdbcOperation) mutation ).getSqlString() );
|
LOG.debugf( " Update (%s): %s", i, ( (JdbcOperation) mutation ).getSqlString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
|
|
||||||
deleteCoordinator.getStaticDeleteGroup().forEachOperation( (tablePosition, mutation) -> {
|
{
|
||||||
|
final MutationOperationGroup staticDeleteGroup = deleteCoordinator.getStaticDeleteGroup();
|
||||||
|
if ( staticDeleteGroup != null ) {
|
||||||
|
for ( int i = 0; i < staticDeleteGroup.getNumberOfOperations(); i++ ) {
|
||||||
|
final MutationOperation mutation = staticDeleteGroup.getOperation( i );
|
||||||
if ( mutation instanceof JdbcOperation ) {
|
if ( mutation instanceof JdbcOperation ) {
|
||||||
LOG.debugf( " Delete (%s): %s", tablePosition, ( (JdbcOperation) mutation ).getSqlString() );
|
LOG.debugf( " Delete (%s): %s", i, ( (JdbcOperation) mutation ).getSqlString() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6087,12 +6104,14 @@ public abstract class AbstractEntityPersister
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] extractSqlStrings(MutationOperationGroup operationGroup) {
|
private String[] extractSqlStrings(MutationOperationGroup operationGroup) {
|
||||||
final String[] strings = new String[operationGroup.getNumberOfOperations()];
|
final int numberOfOperations = operationGroup.getNumberOfOperations();
|
||||||
operationGroup.forEachOperation( (tableIndex, mutation) -> {
|
final String[] strings = new String[numberOfOperations];
|
||||||
if ( mutation instanceof JdbcOperation ) {
|
for ( int i = 0; i < numberOfOperations; i++ ) {
|
||||||
strings[tableIndex] = ( (JdbcOperation) mutation ).getSqlString();
|
final MutationOperation operation = operationGroup.getOperation( i );
|
||||||
|
if ( operation instanceof JdbcOperation ) {
|
||||||
|
strings[i] = ( (JdbcOperation) operation ).getSqlString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} );
|
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
|
||||||
import org.hibernate.sql.model.internal.MutationOperationGroupNone;
|
import org.hibernate.sql.model.internal.MutationOperationGroupNone;
|
||||||
import org.hibernate.sql.model.internal.MutationOperationGroupSingle;
|
import org.hibernate.sql.model.internal.MutationOperationGroupSingle;
|
||||||
import org.hibernate.sql.model.internal.MutationOperationGroupStandard;
|
import org.hibernate.sql.model.internal.MutationOperationGroupStandard;
|
||||||
|
import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
|
||||||
|
|
||||||
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
|
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ public abstract class AbstractMutationCoordinator {
|
||||||
.createMutationOperation( valuesAnalysis, factory() );
|
.createMutationOperation( valuesAnalysis, factory() );
|
||||||
return operation == null
|
return operation == null
|
||||||
? new MutationOperationGroupNone( mutationGroup )
|
? new MutationOperationGroupNone( mutationGroup )
|
||||||
: new MutationOperationGroupSingle( mutationGroup, operation );
|
: new MutationOperationGroupSingle( mutationGroup, (JdbcMutationOperation) operation );
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
final List<MutationOperation> operations = arrayList( numberOfTableMutations );
|
final List<MutationOperation> operations = arrayList( numberOfTableMutations );
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.hibernate.metamodel.mapping.EntityRowIdMapping;
|
||||||
import org.hibernate.metamodel.mapping.EntityVersionMapping;
|
import org.hibernate.metamodel.mapping.EntityVersionMapping;
|
||||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
|
import org.hibernate.sql.model.MutationOperation;
|
||||||
import org.hibernate.sql.model.MutationOperationGroup;
|
import org.hibernate.sql.model.MutationOperationGroup;
|
||||||
import org.hibernate.sql.model.MutationType;
|
import org.hibernate.sql.model.MutationType;
|
||||||
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
|
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
|
||||||
|
@ -97,12 +98,13 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
||||||
|
|
||||||
final MutationExecutor mutationExecutor = executor( session, operationGroup );
|
final MutationExecutor mutationExecutor = executor( session, operationGroup );
|
||||||
|
|
||||||
operationGroup.forEachOperation( (position, mutation) -> {
|
for ( int i = 0; i < operationGroup.getNumberOfOperations(); i++ ) {
|
||||||
|
final MutationOperation mutation = operationGroup.getOperation( i );
|
||||||
if ( mutation != null ) {
|
if ( mutation != null ) {
|
||||||
final String tableName = mutation.getTableDetails().getTableName();
|
final String tableName = mutation.getTableDetails().getTableName();
|
||||||
mutationExecutor.getPreparedStatementDetails( tableName );
|
mutationExecutor.getPreparedStatementDetails( tableName );
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
|
|
||||||
applyLocking( null, loadedState, mutationExecutor, session );
|
applyLocking( null, loadedState, mutationExecutor, session );
|
||||||
|
|
||||||
|
@ -213,10 +215,12 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
||||||
MutationExecutor mutationExecutor,
|
MutationExecutor mutationExecutor,
|
||||||
MutationOperationGroup operationGroup,
|
MutationOperationGroup operationGroup,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
|
|
||||||
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
|
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
|
||||||
final EntityRowIdMapping rowIdMapping = entityPersister().getRowIdMapping();
|
final EntityRowIdMapping rowIdMapping = entityPersister().getRowIdMapping();
|
||||||
|
|
||||||
operationGroup.forEachOperation( (position, jdbcMutation) -> {
|
for ( int position = 0; position < operationGroup.getNumberOfOperations(); position++ ) {
|
||||||
|
final MutationOperation jdbcMutation = operationGroup.getOperation( position );
|
||||||
final EntityTableMapping tableDetails = (EntityTableMapping) jdbcMutation.getTableDetails();
|
final EntityTableMapping tableDetails = (EntityTableMapping) jdbcMutation.getTableDetails();
|
||||||
breakDownIdJdbcValues( id, rowId, session, jdbcValueBindings, rowIdMapping, tableDetails );
|
breakDownIdJdbcValues( id, rowId, session, jdbcValueBindings, rowIdMapping, tableDetails );
|
||||||
final PreparedStatementDetails statementDetails = mutationExecutor.getPreparedStatementDetails( tableDetails.getTableName() );
|
final PreparedStatementDetails statementDetails = mutationExecutor.getPreparedStatementDetails( tableDetails.getTableName() );
|
||||||
|
@ -225,7 +229,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
||||||
//noinspection resource
|
//noinspection resource
|
||||||
statementDetails.resolveStatement();
|
statementDetails.resolveStatement();
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void breakDownIdJdbcValues(
|
private static void breakDownIdJdbcValues(
|
||||||
|
@ -279,11 +283,12 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
||||||
|
|
||||||
final MutationExecutor mutationExecutor = executor( session, operationGroupToUse );
|
final MutationExecutor mutationExecutor = executor( session, operationGroupToUse );
|
||||||
|
|
||||||
staticOperationGroup.forEachOperation( (position, mutation) -> {
|
for ( int position = 0; position < staticOperationGroup.getNumberOfOperations(); position++ ) {
|
||||||
|
final MutationOperation mutation = staticOperationGroup.getOperation( position );
|
||||||
if ( mutation != null ) {
|
if ( mutation != null ) {
|
||||||
mutationExecutor.getPreparedStatementDetails( mutation.getTableDetails().getTableName() );
|
mutationExecutor.getPreparedStatementDetails( mutation.getTableDetails().getTableName() );
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
|
|
||||||
if ( applyVersion ) {
|
if ( applyVersion ) {
|
||||||
applyLocking( version, null, mutationExecutor, session );
|
applyLocking( version, null, mutationExecutor, session );
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.metamodel.mapping.AttributeMappingsList;
|
||||||
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
|
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
|
||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
|
import org.hibernate.sql.model.MutationOperation;
|
||||||
import org.hibernate.sql.model.MutationOperationGroup;
|
import org.hibernate.sql.model.MutationOperationGroup;
|
||||||
import org.hibernate.sql.model.MutationType;
|
import org.hibernate.sql.model.MutationType;
|
||||||
import org.hibernate.sql.model.TableMapping;
|
import org.hibernate.sql.model.TableMapping;
|
||||||
|
@ -196,22 +197,25 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
|
||||||
TableInclusionChecker tableInclusionChecker,
|
TableInclusionChecker tableInclusionChecker,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
|
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
|
||||||
|
final AttributeMappingsList attributeMappings = entityPersister().getAttributeMappings();
|
||||||
|
|
||||||
mutationGroup.forEachOperation( (position, operation) -> {
|
for ( int position = 0; position < mutationGroup.getNumberOfOperations(); position++ ) {
|
||||||
|
final MutationOperation operation = mutationGroup.getOperation( position );
|
||||||
final EntityTableMapping tableDetails = (EntityTableMapping) operation.getTableDetails();
|
final EntityTableMapping tableDetails = (EntityTableMapping) operation.getTableDetails();
|
||||||
if ( tableInclusionChecker.include( tableDetails ) ) {
|
if ( tableInclusionChecker.include( tableDetails ) ) {
|
||||||
final int[] attributeIndexes = tableDetails.getAttributeIndexes();
|
final int[] attributeIndexes = tableDetails.getAttributeIndexes();
|
||||||
for ( int i = 0; i < attributeIndexes.length; i++ ) {
|
for ( int i = 0; i < attributeIndexes.length; i++ ) {
|
||||||
final int attributeIndex = attributeIndexes[ i ];
|
final int attributeIndex = attributeIndexes[ i ];
|
||||||
if ( propertyInclusions[attributeIndex] ) {
|
if ( propertyInclusions[attributeIndex] ) {
|
||||||
final AttributeMapping mapping = entityPersister().getAttributeMappings().get( attributeIndex );
|
final AttributeMapping mapping = attributeMappings.get( attributeIndex );
|
||||||
decomposeAttribute( values[attributeIndex], session, jdbcValueBindings, mapping );
|
decomposeAttribute( values[attributeIndex], session, jdbcValueBindings, mapping );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
|
|
||||||
mutationGroup.forEachOperation( (position, jdbcOperation) -> {
|
for ( int position = 0; position < mutationGroup.getNumberOfOperations(); position++ ) {
|
||||||
|
final MutationOperation jdbcOperation = mutationGroup.getOperation( position );
|
||||||
if ( id == null ) {
|
if ( id == null ) {
|
||||||
assert entityPersister().getIdentityInsertDelegate() != null;
|
assert entityPersister().getIdentityInsertDelegate() != null;
|
||||||
}
|
}
|
||||||
|
@ -219,7 +223,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
|
||||||
final EntityTableMapping tableDetails = (EntityTableMapping) jdbcOperation.getTableDetails();
|
final EntityTableMapping tableDetails = (EntityTableMapping) jdbcOperation.getTableDetails();
|
||||||
breakDownJdbcValue( id, session, jdbcValueBindings, tableDetails );
|
breakDownJdbcValue( id, session, jdbcValueBindings, tableDetails );
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void breakDownJdbcValue(
|
protected void breakDownJdbcValue(
|
||||||
|
|
|
@ -775,7 +775,8 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
||||||
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
|
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
|
||||||
|
|
||||||
// apply values
|
// apply values
|
||||||
jdbcOperationGroup.forEachOperation( (position, operation) -> {
|
for ( int position = 0; position < jdbcOperationGroup.getNumberOfOperations(); position++ ) {
|
||||||
|
final MutationOperation operation = jdbcOperationGroup.getOperation( position );
|
||||||
final EntityTableMapping tableMapping = (EntityTableMapping) operation.getTableDetails();
|
final EntityTableMapping tableMapping = (EntityTableMapping) operation.getTableDetails();
|
||||||
if ( valuesAnalysis.tablesNeedingUpdate.contains( tableMapping ) ) {
|
if ( valuesAnalysis.tablesNeedingUpdate.contains( tableMapping ) ) {
|
||||||
final int[] attributeIndexes = tableMapping.getAttributeIndexes();
|
final int[] attributeIndexes = tableMapping.getAttributeIndexes();
|
||||||
|
@ -791,13 +792,14 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
}
|
||||||
|
|
||||||
// apply keys
|
// apply keys
|
||||||
jdbcOperationGroup.forEachOperation( (position, operation) -> {
|
for ( int position = 0; position < jdbcOperationGroup.getNumberOfOperations(); position++ ) {
|
||||||
|
final MutationOperation operation = jdbcOperationGroup.getOperation( position );
|
||||||
final EntityTableMapping tableMapping = (EntityTableMapping) operation.getTableDetails();
|
final EntityTableMapping tableMapping = (EntityTableMapping) operation.getTableDetails();
|
||||||
breakDownKeyJdbcValues( id, rowId, session, jdbcValueBindings, tableMapping );
|
breakDownKeyJdbcValues( id, rowId, session, jdbcValueBindings, tableMapping );
|
||||||
} );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decomposeAttributeForUpdate(
|
private void decomposeAttributeForUpdate(
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.function.BiFunction;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface MutationOperationGroup {
|
public interface MutationOperationGroup {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of mutation (at the model-level) represented by this group.
|
* The type of mutation (at the model-level) represented by this group.
|
||||||
*/
|
*/
|
||||||
|
@ -37,22 +38,41 @@ public interface MutationOperationGroup {
|
||||||
*
|
*
|
||||||
* Throws an exception if there are more than one.
|
* Throws an exception if there are more than one.
|
||||||
*/
|
*/
|
||||||
<O extends MutationOperation> O getSingleOperation();
|
MutationOperation getSingleOperation();
|
||||||
|
|
||||||
<O extends MutationOperation> List<O> getOperations();
|
/**
|
||||||
|
* Gets a specific MutationOperation from the group
|
||||||
|
* @param idx the index, starting from zero.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MutationOperation getOperation(int idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the operation for a specific table.
|
* Get the operation for a specific table.
|
||||||
*/
|
*/
|
||||||
<O extends MutationOperation> O getOperation(String tableName);
|
MutationOperation getOperation(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Will be removed - use a combination of {@link #getNumberOfOperations()} and {@link #getOperation(int)}
|
||||||
|
* to iterate the list of operations.
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
List<MutationOperation> getOperations();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit each operation
|
* Visit each operation
|
||||||
|
* @deprecated Will be removed - use a combination of {@link #getNumberOfOperations()} and {@link #getOperation(int)}
|
||||||
|
* to iterate the list of operations.
|
||||||
*/
|
*/
|
||||||
<O extends MutationOperation> void forEachOperation(BiConsumer<Integer, O> action);
|
@Deprecated(forRemoval = true)
|
||||||
|
void forEachOperation(BiConsumer<Integer, MutationOperation> action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether any operations match the condition
|
* Test whether any operations match the condition
|
||||||
|
* @deprecated Will be removed - use a combination of {@link #getNumberOfOperations()} and {@link #getOperation(int)}
|
||||||
|
* to iterate the list of operations.
|
||||||
*/
|
*/
|
||||||
<O extends MutationOperation> boolean hasMatching(BiFunction<Integer, O, Boolean> matcher);
|
@Deprecated(forRemoval = true)
|
||||||
|
boolean hasMatching(BiFunction<Integer, MutationOperation, Boolean> matcher);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,26 +35,32 @@ public class MutationOperationGroupNone extends AbstractMutationOperationGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> O getSingleOperation() {
|
public MutationOperation getSingleOperation() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> List<O> getOperations() {
|
public MutationOperation getOperation(int idx) {
|
||||||
|
throw new IndexOutOfBoundsException( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MutationOperation> getOperations() {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> O getOperation(String tableName) {
|
public MutationOperation getOperation(String tableName) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> void forEachOperation(BiConsumer<Integer, O> action) {
|
public void forEachOperation(BiConsumer<Integer, MutationOperation> action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> boolean hasMatching(BiFunction<Integer, O, Boolean> matcher) {
|
public boolean hasMatching(BiFunction<Integer, MutationOperation, Boolean> matcher) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.sql.model.MutationOperation;
|
||||||
import org.hibernate.sql.model.MutationTarget;
|
import org.hibernate.sql.model.MutationTarget;
|
||||||
import org.hibernate.sql.model.MutationType;
|
import org.hibernate.sql.model.MutationType;
|
||||||
import org.hibernate.sql.model.ast.MutationGroup;
|
import org.hibernate.sql.model.ast.MutationGroup;
|
||||||
|
import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
|
||||||
|
|
||||||
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
|
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
|
||||||
|
|
||||||
|
@ -22,14 +23,15 @@ import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class MutationOperationGroupSingle extends AbstractMutationOperationGroup {
|
public class MutationOperationGroupSingle extends AbstractMutationOperationGroup {
|
||||||
private final MutationOperation operation;
|
|
||||||
|
|
||||||
public MutationOperationGroupSingle(MutationType mutationType, MutationTarget<?> mutationTarget, MutationOperation operation) {
|
private final JdbcMutationOperation operation;
|
||||||
|
|
||||||
|
public MutationOperationGroupSingle(MutationType mutationType, MutationTarget<?> mutationTarget, JdbcMutationOperation operation) {
|
||||||
super( mutationType, mutationTarget );
|
super( mutationType, mutationTarget );
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutationOperationGroupSingle(MutationGroup mutationGroup, MutationOperation operation) {
|
public MutationOperationGroupSingle(MutationGroup mutationGroup, JdbcMutationOperation operation) {
|
||||||
this( mutationGroup.getMutationType(), mutationGroup.getMutationTarget(), operation );
|
this( mutationGroup.getMutationType(), mutationGroup.getMutationTarget(), operation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,19 +41,23 @@ public class MutationOperationGroupSingle extends AbstractMutationOperationGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> O getSingleOperation() {
|
public JdbcMutationOperation getSingleOperation() {
|
||||||
//noinspection unchecked
|
return operation;
|
||||||
return (O) operation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> List<O> getOperations() {
|
public MutationOperation getOperation(int idx) {
|
||||||
//noinspection unchecked
|
if ( idx != 0 ) throw new IndexOutOfBoundsException( idx );
|
||||||
return Collections.singletonList( (O) operation );
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> O getOperation(String tableName) {
|
public List<MutationOperation> getOperations() {
|
||||||
|
return Collections.singletonList( operation );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MutationOperation getOperation(String tableName) {
|
||||||
if ( !tableName.equals( operation.getTableDetails().getTableName() ) ) {
|
if ( !tableName.equals( operation.getTableDetails().getTableName() ) ) {
|
||||||
MODEL_MUTATION_LOGGER.debugf(
|
MODEL_MUTATION_LOGGER.debugf(
|
||||||
"Unexpected table name mismatch : `%s` - `%s`",
|
"Unexpected table name mismatch : `%s` - `%s`",
|
||||||
|
@ -60,19 +66,17 @@ public class MutationOperationGroupSingle extends AbstractMutationOperationGroup
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection unchecked
|
return operation;
|
||||||
return (O) operation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> void forEachOperation(BiConsumer<Integer, O> action) {
|
public void forEachOperation(BiConsumer<Integer, MutationOperation> action) {
|
||||||
//noinspection unchecked
|
action.accept( 0, operation );
|
||||||
action.accept( 0, (O) operation );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> boolean hasMatching(BiFunction<Integer, O, Boolean> matcher) {
|
public boolean hasMatching(BiFunction<Integer, MutationOperation, Boolean> matcher) {
|
||||||
//noinspection unchecked
|
return matcher.apply( 0, operation );
|
||||||
return matcher.apply( 0, (O) operation );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,9 @@ public class MutationOperationGroupStandard extends AbstractMutationOperationGro
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> O getSingleOperation() {
|
public MutationOperation getSingleOperation() {
|
||||||
if ( operations.size() == 1 ) {
|
if ( operations.size() == 1 ) {
|
||||||
//noinspection unchecked
|
return operations.get( 0 );
|
||||||
return (O) operations.get( 0 );
|
|
||||||
}
|
}
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -47,38 +46,38 @@ public class MutationOperationGroupStandard extends AbstractMutationOperationGro
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> List<O> getOperations() {
|
public MutationOperation getOperation(int idx) {
|
||||||
//noinspection rawtypes
|
return operations.get( idx );
|
||||||
return (List) operations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> O getOperation(String tableName) {
|
public List<MutationOperation> getOperations() {
|
||||||
|
return operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MutationOperation getOperation(String tableName) {
|
||||||
for ( int i = 0; i < operations.size(); i++ ) {
|
for ( int i = 0; i < operations.size(); i++ ) {
|
||||||
final MutationOperation operation = operations.get( i );
|
final MutationOperation operation = operations.get( i );
|
||||||
if ( operation.getTableDetails().getTableName().equals( tableName ) ) {
|
if ( operation.getTableDetails().getTableName().equals( tableName ) ) {
|
||||||
return (O) operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> void forEachOperation(BiConsumer<Integer, O> action) {
|
public void forEachOperation(BiConsumer<Integer, MutationOperation> action) {
|
||||||
for ( int i = 0; i < operations.size(); i++ ) {
|
for ( int i = 0; i < operations.size(); i++ ) {
|
||||||
action.accept( i, (O) operations.get( i ) );
|
action.accept( i, operations.get( i ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <O extends MutationOperation> boolean hasMatching(BiFunction<Integer, O, Boolean> matcher) {
|
public boolean hasMatching(BiFunction<Integer, MutationOperation, Boolean> matcher) {
|
||||||
for ( int i = 0; i < operations.size(); i++ ) {
|
for ( int i = 0; i < operations.size(); i++ ) {
|
||||||
if ( matcher.apply( i, (O) operations.get( i ) ) ) {
|
if ( matcher.apply( i, operations.get( i ) ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue