Skip to content

WIP #10186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed

WIP #10186

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MutationExecutorPostInsert implements MutationExecutor, JdbcValueBi
protected final EntityMutationTarget mutationTarget;
protected final MutationOperationGroup mutationOperationGroup;

protected final SharedSessionContractImplementor session;
protected final PreparedStatementDetails identityInsertStatementDetails;

/**
Expand All @@ -69,6 +70,7 @@ public MutationExecutorPostInsert(EntityMutationOperationGroup mutationOperation
session
);
this.mutationOperationGroup = mutationOperationGroup;
this.session = session;

final PreparableMutationOperation identityInsertOperation = (PreparableMutationOperation) mutationOperationGroup.getOperation( mutationTarget.getIdentifierTableName() );
this.identityInsertStatementDetails = ModelMutationHelper.identityPreparation(
Expand Down Expand Up @@ -223,6 +225,7 @@ private void executeWithId(

@Override
public void release() {
identityInsertStatementDetails.releaseStatement( session );
secondaryTablesStatementGroup.release();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementGroup;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.jdbc.Expectation;
Expand Down Expand Up @@ -66,8 +67,10 @@ public TableMapping getMutatingTableDetails() {
@Override
public void releaseStatement(SharedSessionContractImplementor session) {
if ( statement != null ) {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( statement );
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( statement );
statement = null;
jdbcCoordinator.afterStatementExecution();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public Object performInsert(
}
finally {
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( insertStatement );
jdbcCoordinator.afterStatementExecution();
}
}
catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,38 +285,41 @@ protected void doStaticDelete(

final MutationExecutor mutationExecutor = executor( session, operationGroupToUse );

for ( int position = 0; position < staticOperationGroup.getNumberOfOperations(); position++ ) {
final MutationOperation mutation = staticOperationGroup.getOperation( position );
if ( mutation != null ) {
mutationExecutor.getPreparedStatementDetails( mutation.getTableDetails().getTableName() );
try {
for ( int position = 0; position < staticOperationGroup.getNumberOfOperations(); position++ ) {
final MutationOperation mutation = staticOperationGroup.getOperation( position );
if ( mutation != null ) {
mutationExecutor.getPreparedStatementDetails( mutation.getTableDetails().getTableName() );
}
}
}

if ( applyVersion ) {
applyLocking( version, null, mutationExecutor, session );
}
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
if ( applyVersion ) {
applyLocking( version, null, mutationExecutor, session );
}
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();

bindPartitionColumnValueBindings( loadedState, session, jdbcValueBindings );

bindPartitionColumnValueBindings( loadedState, session, jdbcValueBindings );

applyId( id, null, mutationExecutor, staticOperationGroup, session );

mutationExecutor.execute(
entity,
null,
null,
(statementDetails, affectedRowCount, batchPosition) -> identifiedResultsCheck(
statementDetails,
affectedRowCount,
batchPosition,
entityPersister(),
id,
factory()
),
session
);

mutationExecutor.release();
applyId( id, null, mutationExecutor, staticOperationGroup, session );

mutationExecutor.execute(
entity,
null,
null,
(statementDetails, affectedRowCount, batchPosition) -> identifiedResultsCheck(
statementDetails,
affectedRowCount,
batchPosition,
entityPersister(),
id,
factory()
),
session
);
}
finally {
mutationExecutor.release();
}
}

protected MutationOperationGroup resolveNoVersionDeleteGroup(SharedSessionContractImplementor session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ private ProcedureOutputsImpl buildOutputs() {
}
catch (SQLException e) {
getSession().getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( statement );
getSession().getJdbcCoordinator().afterStatementExecution();
throw getSession().getJdbcServices().getSqlExceptionHelper().convert(
e,
"Error registering CallableStatement parameters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,4 @@ protected Output buildFunctionReturn() {
return buildResultSetOutput( () -> results );
}
}

@Override
public void release() {
super.release();
getResultContext().getSession().getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( callableStatement );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.Supplier;

import org.hibernate.JDBCException;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.procedure.internal.ProcedureCallImpl;
Expand Down Expand Up @@ -131,7 +132,9 @@ public boolean goToNext() {

@Override
public void release() {
context.getSession().getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( jdbcStatement );
final JdbcCoordinator jdbcCoordinator = context.getSession().getJdbcCoordinator();
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( jdbcStatement );
jdbcCoordinator.afterStatementExecution();
}

private List<?> extractCurrentResults() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,25 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon

final PreparedStatementGroupSingleTable statementGroup = new PreparedStatementGroupSingleTable( upsertDelete, session );
final PreparedStatementDetails statementDetails = statementGroup.resolvePreparedStatementDetails( tableMapping.getTableName() );
final PreparedStatement upsertDeleteStatement = statementDetails.resolveStatement();
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );

bindDeleteKeyValues(
jdbcValueBindings,
optionalTableUpdate.getParameters(),
statementDetails,
session
);

final int rowCount = session.getJdbcCoordinator().getResultSetReturn()
.executeUpdate( upsertDeleteStatement, statementDetails.getSqlString() );
MODEL_MUTATION_LOGGER.tracef( "`%s` rows upsert-deleted from `%s`", rowCount, tableMapping.getTableName() );
try {
final PreparedStatement upsertDeleteStatement = statementDetails.resolveStatement();
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );

bindDeleteKeyValues(
jdbcValueBindings,
optionalTableUpdate.getParameters(),
statementDetails,
session
);

final int rowCount = session.getJdbcCoordinator().getResultSetReturn()
.executeUpdate( upsertDeleteStatement, statementDetails.getSqlString() );
MODEL_MUTATION_LOGGER.tracef( "`%s` rows upsert-deleted from `%s`", rowCount, tableMapping.getTableName() );
}
finally {
statementDetails.releaseStatement( session );
}
}

private void bindDeleteKeyValues(
Expand Down Expand Up @@ -189,14 +195,19 @@ private void performUpsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
final PreparedStatementGroupSingleTable statementGroup = new PreparedStatementGroupSingleTable( upsertOperation, session );
final PreparedStatementDetails statementDetails = statementGroup.resolvePreparedStatementDetails( tableMapping.getTableName() );

final PreparedStatement updateStatement = statementDetails.resolveStatement();
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );
try {
final PreparedStatement updateStatement = statementDetails.resolveStatement();
session.getJdbcServices().getSqlStatementLogger().logStatement( statementDetails.getSqlString() );

jdbcValueBindings.beforeStatement( statementDetails );
jdbcValueBindings.beforeStatement( statementDetails );

final int rowCount = session.getJdbcCoordinator().getResultSetReturn()
.executeUpdate( updateStatement, statementDetails.getSqlString() );
final int rowCount = session.getJdbcCoordinator().getResultSetReturn()
.executeUpdate( updateStatement, statementDetails.getSqlString() );

MODEL_MUTATION_LOGGER.tracef( "`%s` rows upserted into `%s`", rowCount, tableMapping.getTableName() );
MODEL_MUTATION_LOGGER.tracef( "`%s` rows upserted into `%s`", rowCount, tableMapping.getTableName() );
}
finally {
statementDetails.releaseStatement( session );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ public void performMutation(
private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionContractImplementor session) {
final JdbcDeleteMutation jdbcDelete = createJdbcDelete( session );

final PreparedStatement deleteStatement = createStatementDetails( jdbcDelete, session );
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
final PreparedStatement deleteStatement = createStatementDetails( jdbcDelete, jdbcCoordinator );
session.getJdbcServices().getSqlStatementLogger().logStatement( jdbcDelete.getSqlString() );

bindKeyValues( jdbcValueBindings, deleteStatement, jdbcDelete, session );

session.getJdbcCoordinator().getResultSetReturn()
.executeUpdate( deleteStatement, jdbcDelete.getSqlString() );
try {
session.getJdbcCoordinator().getResultSetReturn()
.executeUpdate( deleteStatement, jdbcDelete.getSqlString() );
}
finally {
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( deleteStatement );
jdbcCoordinator.afterStatementExecution();
}
}

private void bindKeyValues(
Expand Down Expand Up @@ -373,12 +380,16 @@ private boolean performUpdate(
statementDetails.getSqlString()
);
}
finally {
statementDetails.releaseStatement( session );
}
}

private void performInsert(JdbcValueBindings jdbcValueBindings, SharedSessionContractImplementor session) {
final JdbcInsertMutation jdbcInsert = createJdbcInsert( session );

final PreparedStatement insertStatement = createStatementDetails( jdbcInsert, session );
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
final PreparedStatement insertStatement = createStatementDetails( jdbcInsert, jdbcCoordinator );

try {
session.getJdbcServices().getSqlStatementLogger().logStatement( jdbcInsert.getSqlString() );
Expand All @@ -404,11 +415,12 @@ private void performInsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
} );
}

session.getJdbcCoordinator().getResultSetReturn()
jdbcCoordinator.getResultSetReturn()
.executeUpdate( insertStatement, jdbcInsert.getSqlString() );
}
finally {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( insertStatement );
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( insertStatement );
jdbcCoordinator.afterStatementExecution();
}
}

Expand Down Expand Up @@ -449,11 +461,10 @@ private JdbcInsertMutation createJdbcInsert(SharedSessionContractImplementor ses

private static PreparedStatement createStatementDetails(
PreparableMutationOperation operation,
SharedSessionContractImplementor session) {
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
JdbcCoordinator jdbcCoordinator) {
final MutationStatementPreparer statementPreparer = jdbcCoordinator.getMutationStatementPreparer();
final PreparedStatement statement = statementPreparer.prepareStatement( operation.getSqlString(), false );
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().register( null, statement );
jdbcCoordinator.getLogicalConnection().getResourceRegistry().register( null, statement );
return statement;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.NoopLimitHandler;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.engine.spi.SessionEventListenerManager;
import org.hibernate.engine.spi.SessionFactoryImplementor;
Expand Down Expand Up @@ -321,11 +322,12 @@ public void release() {
}

if ( preparedStatement != null ) {
getPersistenceContext().getJdbcCoordinator()
.getLogicalConnection()
final JdbcCoordinator jdbcCoordinator = getPersistenceContext().getJdbcCoordinator();
jdbcCoordinator.getLogicalConnection()
.getResourceRegistry()
.release( preparedStatement );
preparedStatement = null;
jdbcCoordinator.afterStatementExecution();
}
}
}
Loading