Make session part of JdbcValueBindings
This commit is contained in:
parent
e841b0aaae
commit
033eeb7241
|
@ -126,7 +126,7 @@ public class BatchImpl implements Batch {
|
|||
//noinspection resource
|
||||
final PreparedStatement statement = statementDetails.resolveStatement();
|
||||
sqlStatementLogger.logStatement( statementDetails.getSqlString() );
|
||||
jdbcValueBindings.beforeStatement( statementDetails, session );
|
||||
jdbcValueBindings.beforeStatement( statementDetails );
|
||||
|
||||
try {
|
||||
statement.addBatch();
|
||||
|
@ -140,7 +140,7 @@ public class BatchImpl implements Batch {
|
|||
);
|
||||
}
|
||||
finally {
|
||||
jdbcValueBindings.afterStatement( statementDetails.getMutatingTableDetails(), session );
|
||||
jdbcValueBindings.afterStatement( statementDetails.getMutatingTableDetails() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.engine.jdbc.mutation;
|
|||
import org.hibernate.Incubating;
|
||||
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
|
||||
import org.hibernate.engine.jdbc.mutation.spi.BindingGroup;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||
import org.hibernate.sql.model.TableMapping;
|
||||
|
||||
|
@ -28,31 +27,22 @@ public interface JdbcValueBindings {
|
|||
/**
|
||||
* Binds a value for a specific column+usage
|
||||
*/
|
||||
void bindValue(
|
||||
Object value,
|
||||
String tableName,
|
||||
String columnName,
|
||||
ParameterUsage usage,
|
||||
SharedSessionContractImplementor session);
|
||||
void bindValue(Object value, String tableName, String columnName, ParameterUsage usage);
|
||||
|
||||
/**
|
||||
* Binds a value for a specific column+usage
|
||||
*/
|
||||
default void bindValue(
|
||||
Object value,
|
||||
SelectableMapping selectableMapping,
|
||||
ParameterUsage usage,
|
||||
SharedSessionContractImplementor session) {
|
||||
bindValue( value, selectableMapping.getContainingTableExpression(), selectableMapping.getSelectionExpression(), usage, session );
|
||||
default void bindValue(Object value, SelectableMapping selectableMapping, ParameterUsage usage) {
|
||||
bindValue( value, selectableMapping.getContainingTableExpression(), selectableMapping.getSelectionExpression(), usage );
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the execution of the operation for the specified table
|
||||
*/
|
||||
void beforeStatement(PreparedStatementDetails statementDetails, SharedSessionContractImplementor session);
|
||||
void beforeStatement(PreparedStatementDetails statementDetails);
|
||||
|
||||
/**
|
||||
* Called after the execution of the operation for the specified table
|
||||
*/
|
||||
void afterStatement(TableMapping mutatingTable, SharedSessionContractImplementor session);
|
||||
void afterStatement(TableMapping mutatingTable);
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public abstract class AbstractMutationExecutor implements MutationExecutor {
|
|||
|
||||
// If we get here the statement is needed - make sure it is resolved
|
||||
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
|
||||
valueBindings.beforeStatement( statementDetails, session );
|
||||
valueBindings.beforeStatement( statementDetails );
|
||||
|
||||
try {
|
||||
final int affectedRowCount = session.getJdbcCoordinator()
|
||||
|
@ -118,7 +118,7 @@ public abstract class AbstractMutationExecutor implements MutationExecutor {
|
|||
if ( statementDetails.getStatement() != null ) {
|
||||
statementDetails.releaseStatement( session );
|
||||
}
|
||||
valueBindings.afterStatement( tableDetails, session );
|
||||
valueBindings.afterStatement( tableDetails );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Locale;
|
|||
import org.hibernate.engine.jdbc.mutation.JdbcValueBindings;
|
||||
import org.hibernate.engine.jdbc.mutation.ParameterUsage;
|
||||
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.sql.model.PreparableMutationOperation;
|
||||
import org.hibernate.sql.model.jdbc.JdbcValueDescriptor;
|
||||
|
||||
|
@ -21,12 +22,15 @@ public abstract class AbstractSingleMutationExecutor extends AbstractMutationExe
|
|||
private final PreparableMutationOperation mutationOperation;
|
||||
private final JdbcValueBindingsImpl valueBindings;
|
||||
|
||||
public AbstractSingleMutationExecutor(PreparableMutationOperation mutationOperation) {
|
||||
public AbstractSingleMutationExecutor(
|
||||
PreparableMutationOperation mutationOperation,
|
||||
SharedSessionContractImplementor session) {
|
||||
this.mutationOperation = mutationOperation;
|
||||
this.valueBindings = new JdbcValueBindingsImpl(
|
||||
mutationOperation.getMutationType(),
|
||||
mutationOperation.getMutationTarget(),
|
||||
this::findJdbcValueDescriptor
|
||||
this::findJdbcValueDescriptor,
|
||||
session
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,16 +29,19 @@ public class JdbcValueBindingsImpl implements JdbcValueBindings {
|
|||
private final MutationType mutationType;
|
||||
private final MutationTarget<?> mutationTarget;
|
||||
private final JdbcValueDescriptorAccess jdbcValueDescriptorAccess;
|
||||
private final SharedSessionContractImplementor session;
|
||||
|
||||
private final Map<String, BindingGroup> bindingGroupMap = new HashMap<>();
|
||||
|
||||
public JdbcValueBindingsImpl(
|
||||
MutationType mutationType,
|
||||
MutationTarget<?> mutationTarget,
|
||||
JdbcValueDescriptorAccess jdbcValueDescriptorAccess) {
|
||||
JdbcValueDescriptorAccess jdbcValueDescriptorAccess,
|
||||
SharedSessionContractImplementor session) {
|
||||
this.mutationType = mutationType;
|
||||
this.mutationTarget = mutationTarget;
|
||||
this.jdbcValueDescriptorAccess = jdbcValueDescriptorAccess;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,8 +54,7 @@ public class JdbcValueBindingsImpl implements JdbcValueBindings {
|
|||
Object value,
|
||||
String tableName,
|
||||
String columnName,
|
||||
ParameterUsage usage,
|
||||
SharedSessionContractImplementor session) {
|
||||
ParameterUsage usage) {
|
||||
final JdbcValueDescriptor jdbcValueDescriptor = jdbcValueDescriptorAccess.resolveValueDescriptor( tableName, columnName, usage );
|
||||
if ( jdbcValueDescriptor == null ) {
|
||||
throw new UnknownParameterException( mutationType, mutationTarget, tableName, columnName, usage );
|
||||
|
@ -74,9 +76,7 @@ public class JdbcValueBindingsImpl implements JdbcValueBindings {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeStatement(
|
||||
PreparedStatementDetails statementDetails,
|
||||
SharedSessionContractImplementor session) {
|
||||
public void beforeStatement(PreparedStatementDetails statementDetails) {
|
||||
final BindingGroup bindingGroup = bindingGroupMap.get( statementDetails.getMutatingTableDetails().getTableName() );
|
||||
if ( bindingGroup == null ) {
|
||||
statementDetails.resolveStatement();
|
||||
|
@ -107,9 +107,7 @@ public class JdbcValueBindingsImpl implements JdbcValueBindings {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void afterStatement(
|
||||
TableMapping mutatingTable,
|
||||
SharedSessionContractImplementor session) {
|
||||
public void afterStatement(TableMapping mutatingTable) {
|
||||
final BindingGroup bindingGroup = bindingGroupMap.remove( mutatingTable.getTableName() );
|
||||
if ( bindingGroup == null ) {
|
||||
return;
|
||||
|
|
|
@ -66,7 +66,8 @@ public class MutationExecutorPostInsert implements MutationExecutor {
|
|||
this.valueBindings = new JdbcValueBindingsImpl(
|
||||
MutationType.INSERT,
|
||||
mutationTarget,
|
||||
this::findJdbcValueDescriptor
|
||||
this::findJdbcValueDescriptor,
|
||||
session
|
||||
);
|
||||
this.mutationOperationGroup = mutationOperationGroup;
|
||||
|
||||
|
@ -191,18 +192,19 @@ public class MutationExecutorPostInsert implements MutationExecutor {
|
|||
|
||||
tableDetails.getKeyMapping().breakDownKeyJdbcValues(
|
||||
id,
|
||||
(jdbcValue, columnMapping) -> valueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableName,
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.SET,
|
||||
session
|
||||
),
|
||||
(jdbcValue, columnMapping) -> {
|
||||
valueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableName,
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.SET
|
||||
);
|
||||
},
|
||||
session
|
||||
);
|
||||
|
||||
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
|
||||
valueBindings.beforeStatement( statementDetails, session );
|
||||
valueBindings.beforeStatement( statementDetails );
|
||||
|
||||
try {
|
||||
final int affectedRowCount = session.getJdbcCoordinator()
|
||||
|
|
|
@ -66,7 +66,8 @@ public class MutationExecutorPostInsertSingleTable implements MutationExecutor {
|
|||
(tableName, columnName, usage) -> {
|
||||
assert identityInsertStatementDetails.getMutatingTableDetails().getTableName().equals( tableName );
|
||||
return operation.findValueDescriptor( columnName, usage );
|
||||
}
|
||||
},
|
||||
session
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class MutationExecutorSingleBatched extends AbstractSingleMutationExecuto
|
|||
BatchKey batchKey,
|
||||
int batchSize,
|
||||
SharedSessionContractImplementor session) {
|
||||
super( mutationOperation );
|
||||
super( mutationOperation, session );
|
||||
|
||||
this.batchSize = batchSize;
|
||||
this.session = session;
|
||||
|
|
|
@ -21,7 +21,7 @@ public class MutationExecutorSingleNonBatched extends AbstractSingleMutationExec
|
|||
public MutationExecutorSingleNonBatched(
|
||||
PreparableMutationOperation mutationOperation,
|
||||
SharedSessionContractImplementor session) {
|
||||
super( mutationOperation );
|
||||
super( mutationOperation, session );
|
||||
|
||||
this.statementGroup = new PreparedStatementGroupSingleTable( mutationOperation, session );
|
||||
}
|
||||
|
|
|
@ -22,13 +22,16 @@ public class MutationExecutorSingleSelfExecuting extends AbstractMutationExecuto
|
|||
private final SelfExecutingUpdateOperation operation;
|
||||
private final JdbcValueBindingsImpl valueBindings;
|
||||
|
||||
public MutationExecutorSingleSelfExecuting(SelfExecutingUpdateOperation operation) {
|
||||
public MutationExecutorSingleSelfExecuting(
|
||||
SelfExecutingUpdateOperation operation,
|
||||
SharedSessionContractImplementor session) {
|
||||
this.operation = operation;
|
||||
|
||||
this.valueBindings = new JdbcValueBindingsImpl(
|
||||
operation.getMutationType(),
|
||||
operation.getMutationTarget(),
|
||||
this::findJdbcValueDescriptor
|
||||
this::findJdbcValueDescriptor,
|
||||
session
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,8 @@ public class MutationExecutorStandard extends AbstractMutationExecutor {
|
|||
this.valueBindings = new JdbcValueBindingsImpl(
|
||||
mutationOperationGroup.getMutationType(),
|
||||
mutationOperationGroup.getMutationTarget(),
|
||||
this::findJdbcValueDescriptor
|
||||
this::findJdbcValueDescriptor,
|
||||
session
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class StandardMutationExecutorService implements MutationExecutorService
|
|||
if ( numberOfOperations == 1 ) {
|
||||
final MutationOperation singleOperation = operationGroup.getSingleOperation();
|
||||
if ( singleOperation instanceof SelfExecutingUpdateOperation ) {
|
||||
return new MutationExecutorSingleSelfExecuting( (SelfExecutingUpdateOperation) singleOperation );
|
||||
return new MutationExecutorSingleSelfExecuting( (SelfExecutingUpdateOperation) singleOperation, session );
|
||||
}
|
||||
|
||||
final PreparableMutationOperation jdbcOperation = (PreparableMutationOperation) singleOperation;
|
||||
|
|
|
@ -38,7 +38,7 @@ public abstract class AbstractReturningDelegate implements InsertGeneratedIdenti
|
|||
Object entity,
|
||||
SharedSessionContractImplementor session) {
|
||||
session.getJdbcServices().getSqlStatementLogger().logStatement( insertStatementDetails.getSqlString() );
|
||||
valueBindings.beforeStatement( insertStatementDetails, session );
|
||||
valueBindings.beforeStatement( insertStatementDetails );
|
||||
return executeAndExtract( insertStatementDetails.getSqlString(), insertStatementDetails.getStatement(), session );
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public abstract class AbstractSelectingDelegate implements InsertGeneratedIdenti
|
|||
final JdbcServices jdbcServices = session.getJdbcServices();
|
||||
|
||||
jdbcServices.getSqlStatementLogger().logStatement( insertStatementDetails.getSqlString() );
|
||||
jdbcValueBindings.beforeStatement( insertStatementDetails, session );
|
||||
jdbcValueBindings.beforeStatement( insertStatementDetails );
|
||||
|
||||
jdbcCoordinator.getResultSetReturn()
|
||||
.executeUpdate( insertStatementDetails.resolveStatement(), insertStatementDetails.getSqlString() );
|
||||
|
|
|
@ -101,7 +101,7 @@ public class GetGeneratedKeysDelegate extends AbstractReturningDelegate {
|
|||
jdbcServices.getSqlStatementLogger().logStatement( insertSql );
|
||||
|
||||
final PreparedStatement insertStatement = insertStatementDetails.resolveStatement();
|
||||
jdbcValueBindings.beforeStatement( insertStatementDetails, session );
|
||||
jdbcValueBindings.beforeStatement( insertStatementDetails );
|
||||
|
||||
try {
|
||||
jdbcCoordinator.getResultSetReturn().executeUpdate( insertStatement, insertSql );
|
||||
|
|
|
@ -138,6 +138,7 @@ public interface ModelPart extends MappingModelExpressible {
|
|||
@FunctionalInterface
|
||||
interface JdbcValueConsumer {
|
||||
void consume(Object value, SelectableMapping jdbcValueMapping);
|
||||
|
||||
}
|
||||
|
||||
void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session);
|
||||
|
|
|
@ -245,8 +245,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
|
|||
(jdbcValue, jdbcValueMapping, usage) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
usage,
|
||||
session
|
||||
usage
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -259,8 +258,7 @@ public class OneToManyPersister extends AbstractCollectionPersister {
|
|||
(jdbcValue, jdbcValueMapping) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -106,10 +106,8 @@ public class DeleteRowsCoordinatorStandard implements DeleteRowsCoordinator {
|
|||
}
|
||||
jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
mutationTarget.getIdentifierTableName(),
|
||||
jdbcValueMapping.getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
jdbcValueMapping,
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -106,19 +106,14 @@ public class InsertRowsCoordinatorStandard implements InsertRowsCoordinator {
|
|||
|
||||
if ( entryChecker == null || entryChecker.include( entry, entryCount, collection, pluralAttribute ) ) {
|
||||
// if the entry is included, perform the "insert"
|
||||
insertRowValues.applyValues( collection, id, entry, entryCount, session, (value, jdbcValueMapping, usage) -> {
|
||||
// if ( !jdbcValueMapping.isInsertable() ) {
|
||||
// return;
|
||||
// }
|
||||
jdbcValueBindings.bindValue(
|
||||
value,
|
||||
jdbcValueMapping.getContainingTableExpression(),
|
||||
jdbcValueMapping.getSelectionExpression(),
|
||||
usage,
|
||||
session
|
||||
);
|
||||
} );
|
||||
|
||||
insertRowValues.applyValues(
|
||||
collection,
|
||||
id,
|
||||
entry,
|
||||
entryCount,
|
||||
session,
|
||||
jdbcValueBindings::bindValue
|
||||
);
|
||||
mutationExecutor.execute( entry, null, null, null, session );
|
||||
}
|
||||
|
||||
|
|
|
@ -100,13 +100,13 @@ public class RemoveCoordinatorStandard implements RemoveCoordinator {
|
|||
final ForeignKeyDescriptor fkDescriptor = mutationTarget.getTargetPart().getKeyDescriptor();
|
||||
fkDescriptor.getKeyPart().decompose(
|
||||
key,
|
||||
(jdbcValue, jdbcValueMapping) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
mutationTarget.getIdentifierTableMapping().getTableName(),
|
||||
jdbcValueMapping.getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
),
|
||||
(jdbcValue, jdbcValueMapping) -> {
|
||||
jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
},
|
||||
session
|
||||
);
|
||||
|
||||
|
|
|
@ -91,8 +91,7 @@ public class UpdateRowsCoordinatorOneToMany extends AbstractUpdateRowsCoordinato
|
|||
(jdbcValue, jdbcValueMapping) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -154,8 +153,7 @@ public class UpdateRowsCoordinatorOneToMany extends AbstractUpdateRowsCoordinato
|
|||
(jdbcValue, jdbcValueMapping, usage) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
usage,
|
||||
session
|
||||
usage
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -129,8 +129,7 @@ public class UpdateRowsCoordinatorStandard extends AbstractUpdateRowsCoordinator
|
|||
(jdbcValue, jdbcValueMapping, usage) -> mutationExecutor.getJdbcValueBindings().bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
usage,
|
||||
session
|
||||
usage
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -143,8 +142,7 @@ public class UpdateRowsCoordinatorStandard extends AbstractUpdateRowsCoordinator
|
|||
(jdbcValue, jdbcValueMapping) -> mutationExecutor.getJdbcValueBindings().bindValue(
|
||||
jdbcValue,
|
||||
jdbcValueMapping,
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.hibernate.engine.jdbc.mutation.JdbcValueBindings;
|
|||
import org.hibernate.engine.jdbc.mutation.ParameterUsage;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||
import org.hibernate.sql.model.ModelMutationLogging;
|
||||
|
@ -124,8 +123,7 @@ public abstract class AbstractMutationCoordinator {
|
|||
jdbcValueBindings.bindValue(
|
||||
value,
|
||||
jdbcValueMapping,
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityRowIdMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityVersionMapping;
|
||||
import org.hibernate.metamodel.mapping.SelectableMapping;
|
||||
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
|
||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||
|
@ -29,7 +30,6 @@ import org.hibernate.sql.model.ast.builder.RestrictedTableMutationBuilder;
|
|||
import org.hibernate.sql.model.ast.builder.TableDeleteBuilder;
|
||||
import org.hibernate.sql.model.ast.builder.TableDeleteBuilderSkipped;
|
||||
import org.hibernate.sql.model.ast.builder.TableDeleteBuilderStandard;
|
||||
import org.hibernate.sql.model.ast.builder.TableMutationBuilder;
|
||||
|
||||
import static org.hibernate.engine.jdbc.mutation.internal.ModelMutationHelper.identifiedResultsCheck;
|
||||
|
||||
|
@ -175,13 +175,11 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
|||
// presumably the SQL was generated with `is null`
|
||||
return;
|
||||
}
|
||||
|
||||
jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
mutationTableName,
|
||||
jdbcValueMapping.getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
},
|
||||
session
|
||||
|
@ -196,13 +194,14 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
|||
Object version,
|
||||
SharedSessionContractImplementor session,
|
||||
JdbcValueBindings jdbcValueBindings) {
|
||||
if ( version != null && entityPersister().getVersionMapping() != null ) {
|
||||
final AbstractEntityPersister persister = entityPersister();
|
||||
final EntityVersionMapping versionMapping = persister.getVersionMapping();
|
||||
if ( version != null && versionMapping != null ) {
|
||||
jdbcValueBindings.bindValue(
|
||||
version,
|
||||
entityPersister().getIdentifierTableMapping().getTableName(),
|
||||
entityPersister().getVersionMapping().getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
persister.physicalTableNameForMutation( versionMapping ),
|
||||
versionMapping.getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -240,20 +239,20 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
|
|||
rowId,
|
||||
tableDetails.getTableName(),
|
||||
rowIdMapping.getRowIdName(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
}
|
||||
else {
|
||||
tableDetails.getKeyMapping().breakDownKeyJdbcValues(
|
||||
id,
|
||||
(jdbcValue, columnMapping) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableDetails.getTableName(),
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
),
|
||||
(jdbcValue, columnMapping) -> {
|
||||
jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableDetails.getTableName(),
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
},
|
||||
session
|
||||
);
|
||||
}
|
||||
|
|
|
@ -223,13 +223,14 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
|
|||
final String tableName = tableDetails.getTableName();
|
||||
tableDetails.getKeyMapping().breakDownKeyJdbcValues(
|
||||
id,
|
||||
(jdbcValue, columnMapping) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableName,
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.SET,
|
||||
session
|
||||
),
|
||||
(jdbcValue, columnMapping) -> {
|
||||
jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableName,
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.SET
|
||||
);
|
||||
},
|
||||
session
|
||||
);
|
||||
}
|
||||
|
@ -248,8 +249,7 @@ public class InsertCoordinator extends AbstractMutationCoordinator {
|
|||
jdbcValue,
|
||||
entityPersister().physicalTableNameForMutation( selectableMapping ),
|
||||
selectableMapping.getSelectionExpression(),
|
||||
ParameterUsage.SET,
|
||||
session
|
||||
ParameterUsage.SET
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -450,20 +450,20 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
version,
|
||||
mutatingTableDetails.getTableName(),
|
||||
versionMapping.getSelectionExpression(),
|
||||
ParameterUsage.SET,
|
||||
session
|
||||
ParameterUsage.SET
|
||||
);
|
||||
|
||||
// restrict the key
|
||||
mutatingTableDetails.getKeyMapping().breakDownKeyJdbcValues(
|
||||
id,
|
||||
(jdbcValue, columnMapping) -> mutationExecutor.getJdbcValueBindings().bindValue(
|
||||
jdbcValue,
|
||||
mutatingTableDetails.getTableName(),
|
||||
columnMapping.getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
),
|
||||
(jdbcValue, columnMapping) -> {
|
||||
mutationExecutor.getJdbcValueBindings().bindValue(
|
||||
jdbcValue,
|
||||
mutatingTableDetails.getTableName(),
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
},
|
||||
session
|
||||
);
|
||||
|
||||
|
@ -472,8 +472,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
oldVersion,
|
||||
mutatingTableDetails.getTableName(),
|
||||
versionMapping.getSelectionExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
|
||||
try {
|
||||
|
@ -798,14 +797,13 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
JdbcValueBindings jdbcValueBindings,
|
||||
EntityTableMapping tableMapping,
|
||||
IncludedAttributeAnalysis attributeAnalysis) {
|
||||
attributeAnalysis.columnLockingAnalyses.forEach( (columnLockingAnalysis) -> {
|
||||
attributeAnalysis.columnLockingAnalyses.forEach( columnLockingAnalysis -> {
|
||||
if ( columnLockingAnalysis.getLockValue() != null ) {
|
||||
jdbcValueBindings.bindValue(
|
||||
columnLockingAnalysis.getLockValue(),
|
||||
tableMapping.getTableName(),
|
||||
columnLockingAnalysis.getReadExpression(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
@ -824,20 +822,20 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
rowId,
|
||||
tableMapping.getTableName(),
|
||||
entityPersister().getRowIdMapping().getRowIdName(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
}
|
||||
else {
|
||||
tableMapping.getKeyMapping().breakDownKeyJdbcValues(
|
||||
id,
|
||||
(jdbcValue, columnMapping) -> jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableMapping.getTableName(),
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.RESTRICT,
|
||||
session
|
||||
),
|
||||
(jdbcValue, columnMapping) -> {
|
||||
jdbcValueBindings.bindValue(
|
||||
jdbcValue,
|
||||
tableMapping.getTableName(),
|
||||
columnMapping.getColumnName(),
|
||||
ParameterUsage.RESTRICT
|
||||
);
|
||||
},
|
||||
session
|
||||
);
|
||||
}
|
||||
|
@ -857,8 +855,7 @@ public class UpdateCoordinatorStandard extends AbstractMutationCoordinator imple
|
|||
jdbcValue,
|
||||
tableMapping.getTableName(),
|
||||
jdbcMapping.getSelectionExpression(),
|
||||
ParameterUsage.SET,
|
||||
session
|
||||
ParameterUsage.SET
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.hibernate.engine.jdbc.mutation.spi.Binding;
|
|||
import org.hibernate.engine.jdbc.mutation.spi.BindingGroup;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.jdbc.spi.MutationStatementPreparer;
|
||||
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
@ -164,7 +163,7 @@ public class OptionalTableUpdateOperation implements SelfExecutingUpdateOperatio
|
|||
}
|
||||
}
|
||||
finally {
|
||||
jdbcValueBindings.afterStatement( tableMapping, session );
|
||||
jdbcValueBindings.afterStatement( tableMapping );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -347,7 +346,7 @@ public class OptionalTableUpdateOperation implements SelfExecutingUpdateOperatio
|
|||
|
||||
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
|
||||
|
||||
jdbcValueBindings.beforeStatement( statementDetails, session );
|
||||
jdbcValueBindings.beforeStatement( statementDetails );
|
||||
|
||||
final int rowCount = session.getJdbcCoordinator().getResultSetReturn()
|
||||
.executeUpdate( updateStatement, statementDetails.getSqlString() );
|
||||
|
|
|
@ -76,8 +76,8 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
final JdbcValueBindingsImpl jdbcValueBindings = sandboxInsertValueBindings( sessionImpl );
|
||||
|
||||
// bind values for #1 - should do nothing at the JDBC level
|
||||
jdbcValueBindings.bindValue( 1, SANDBOX_TBL, "ID", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( "name", SANDBOX_TBL, "NAME", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( 1, SANDBOX_TBL, "ID", ParameterUsage.SET );
|
||||
jdbcValueBindings.bindValue( "name", SANDBOX_TBL, "NAME", ParameterUsage.SET );
|
||||
assertThat( batchObserver.getExplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( batchObserver.getImplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isFalse();
|
||||
|
@ -89,8 +89,8 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isTrue();
|
||||
|
||||
// bind values for #2 - again, nothing at JDBC level (we have statement from earlier)
|
||||
jdbcValueBindings.bindValue( 2, SANDBOX_TBL, "ID", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( "another name", SANDBOX_TBL, "NAME", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( 2, SANDBOX_TBL, "ID", ParameterUsage.SET );
|
||||
jdbcValueBindings.bindValue( "another name", SANDBOX_TBL, "NAME", ParameterUsage.SET );
|
||||
assertThat( batchObserver.getExplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( batchObserver.getImplicitExecutionCount() ).isEqualTo( 0 );
|
||||
|
||||
|
@ -174,7 +174,8 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
}
|
||||
|
||||
throw new IllegalArgumentException( "Unknown column : " + columnName );
|
||||
}
|
||||
},
|
||||
session
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -205,8 +206,8 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
final JdbcValueBindingsImpl jdbcValueBindings = sandboxInsertValueBindings( sessionImpl );
|
||||
|
||||
// bind values for #1 - this does nothing at the JDBC level
|
||||
jdbcValueBindings.bindValue( 1, SANDBOX_TBL, "ID", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( "name", SANDBOX_TBL, "NAME", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( 1, SANDBOX_TBL, "ID", ParameterUsage.SET );
|
||||
jdbcValueBindings.bindValue( "name", SANDBOX_TBL, "NAME", ParameterUsage.SET );
|
||||
assertThat( batchObserver.getExplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( batchObserver.getImplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isFalse();
|
||||
|
@ -218,8 +219,8 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isTrue();
|
||||
|
||||
// bind values for #2 - this does nothing at the JDBC level : we do still have the statement defining the batch
|
||||
jdbcValueBindings.bindValue( 2, SANDBOX_TBL, "ID", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( "another name", SANDBOX_TBL, "NAME", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( 2, SANDBOX_TBL, "ID", ParameterUsage.SET );
|
||||
jdbcValueBindings.bindValue( "another name", SANDBOX_TBL, "NAME", ParameterUsage.SET );
|
||||
assertThat( batchObserver.getExplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( batchObserver.getImplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isTrue();
|
||||
|
@ -231,8 +232,8 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey
|
|||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isTrue();
|
||||
|
||||
// bind values for #3 - this does nothing at the JDBC level : we do still have the statement defining the batch
|
||||
jdbcValueBindings.bindValue( 3, SANDBOX_TBL, "ID", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( "yet another name", SANDBOX_TBL, "NAME", ParameterUsage.SET, sessionImpl );
|
||||
jdbcValueBindings.bindValue( 3, SANDBOX_TBL, "ID", ParameterUsage.SET );
|
||||
jdbcValueBindings.bindValue( "yet another name", SANDBOX_TBL, "NAME", ParameterUsage.SET );
|
||||
assertThat( batchObserver.getExplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( batchObserver.getImplicitExecutionCount() ).isEqualTo( 0 );
|
||||
assertThat( jdbcCoordinator.getLogicalConnection().getResourceRegistry().hasRegisteredResources() ).isTrue();
|
||||
|
|
Loading…
Reference in New Issue