Skip to content

Commit d1461e6

Browse files
committed
Revert "[#1756] Fix ignored RowId for delete query"
This reverts commit 370df64.
1 parent af88649 commit d1461e6

File tree

3 files changed

+55
-42
lines changed

3 files changed

+55
-42
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/ReactiveEntityDeleteAction.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ public CompletionStage<Void> reactiveExecute() throws HibernateException {
6464
final boolean veto = isInstanceLoaded() && preDelete();
6565

6666
final Object ck = lockCacheItem();
67-
return deleteStep(
68-
veto,
69-
(ReactiveEntityPersister) persister,
70-
id,
71-
version,
72-
instance,
73-
session
74-
).thenAccept( v -> {
67+
68+
final CompletionStage<Void> deleteStep = !isCascadeDeleteEnabled() && !veto
69+
? ( (ReactiveEntityPersister) persister ).deleteReactive( id, version, instance, session )
70+
: voidFuture();
71+
72+
return deleteStep.thenAccept( v -> {
7573
if ( isInstanceLoaded() ) {
7674
postDeleteLoaded( id, persister, session, instance, ck );
7775
}
@@ -86,16 +84,4 @@ public CompletionStage<Void> reactiveExecute() throws HibernateException {
8684
}
8785
} );
8886
}
89-
90-
private CompletionStage<Void> deleteStep(
91-
boolean veto,
92-
ReactiveEntityPersister persister,
93-
Object id,
94-
Object version,
95-
Object instance,
96-
SharedSessionContractImplementor session) {
97-
return !isCascadeDeleteEnabled() && !veto
98-
? persister.deleteReactive( id, version, instance, session )
99-
: voidFuture();
100-
}
10187
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/persister/entity/mutation/ReactiveDeleteCoordinator.java

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
import org.hibernate.engine.jdbc.mutation.JdbcValueBindings;
1313
import org.hibernate.engine.jdbc.mutation.MutationExecutor;
14+
import org.hibernate.engine.jdbc.mutation.ParameterUsage;
1415
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
1516
import org.hibernate.engine.jdbc.mutation.spi.MutationExecutorService;
1617
import org.hibernate.engine.spi.SessionFactoryImplementor;
1718
import org.hibernate.engine.spi.SharedSessionContractImplementor;
19+
import org.hibernate.metamodel.mapping.EntityRowIdMapping;
1820
import org.hibernate.persister.entity.AbstractEntityPersister;
1921
import org.hibernate.persister.entity.mutation.DeleteCoordinator;
2022
import org.hibernate.persister.entity.mutation.EntityTableMapping;
@@ -23,7 +25,6 @@
2325
import org.hibernate.reactive.engine.jdbc.env.internal.ReactiveMutationExecutor;
2426
import org.hibernate.reactive.logging.impl.Log;
2527
import org.hibernate.reactive.logging.impl.LoggerFactory;
26-
import org.hibernate.sql.model.MutationOperation;
2728
import org.hibernate.sql.model.MutationOperationGroup;
2829

2930
import static org.hibernate.engine.jdbc.mutation.internal.ModelMutationHelper.identifiedResultsCheck;
@@ -50,7 +51,7 @@ public CompletionStage<Void> coordinateReactiveDelete(Object entity, Object id,
5051
super.coordinateDelete( entity, id, version, session );
5152
return stage != null ? stage : voidFuture();
5253
}
53-
catch (RuntimeException t) {
54+
catch (Throwable t) {
5455
if ( stage == null ) {
5556
return failedFuture( t );
5657
}
@@ -60,18 +61,17 @@ public CompletionStage<Void> coordinateReactiveDelete(Object entity, Object id,
6061
}
6162

6263
@Override
63-
protected void doDynamicDelete(Object entity, Object id, Object[] loadedState, SharedSessionContractImplementor session) {
64+
protected void doDynamicDelete(Object entity, Object id, Object rowId, Object[] loadedState, SharedSessionContractImplementor session) {
6465
stage = new CompletableFuture<>();
65-
final MutationOperationGroup operationGroup = generateOperationGroup( null, loadedState, true, session );
66+
final MutationOperationGroup operationGroup = generateOperationGroup( loadedState, true, session );
6667
final ReactiveMutationExecutor mutationExecutor = mutationExecutor( session, operationGroup );
6768

68-
for ( int i = 0; i < operationGroup.getNumberOfOperations(); i++ ) {
69-
final MutationOperation mutation = operationGroup.getOperation( i );
69+
operationGroup.forEachOperation( (position, mutation) -> {
7070
if ( mutation != null ) {
7171
final String tableName = mutation.getTableDetails().getTableName();
7272
mutationExecutor.getPreparedStatementDetails( tableName );
7373
}
74-
}
74+
} );
7575

7676
applyLocking( null, loadedState, mutationExecutor, session );
7777
applyId( id, null, mutationExecutor, getStaticDeleteGroup(), session );
@@ -102,49 +102,44 @@ protected void applyId(
102102
MutationOperationGroup operationGroup,
103103
SharedSessionContractImplementor session) {
104104
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
105+
final EntityRowIdMapping rowIdMapping = entityPersister().getRowIdMapping();
105106

106-
for ( int position = 0; position < operationGroup.getNumberOfOperations(); position++ ) {
107-
final MutationOperation jdbcMutation = operationGroup.getOperation( position );
107+
operationGroup.forEachOperation( (position, jdbcMutation) -> {
108108
final EntityTableMapping tableDetails = (EntityTableMapping) jdbcMutation.getTableDetails();
109-
breakDownKeyJdbcValues( id, rowId, session, jdbcValueBindings, tableDetails );
109+
breakDownIdJdbcValues( id, rowId, session, jdbcValueBindings, rowIdMapping, tableDetails );
110110
final PreparedStatementDetails statementDetails = mutationExecutor.getPreparedStatementDetails( tableDetails.getTableName() );
111111
if ( statementDetails != null ) {
112112
PreparedStatementAdaptor.bind( statement -> {
113-
PrepareStatementDetailsAdaptor detailsAdaptor = new PrepareStatementDetailsAdaptor(
114-
statementDetails,
115-
statement,
116-
session.getJdbcServices()
117-
);
113+
PrepareStatementDetailsAdaptor detailsAdaptor = new PrepareStatementDetailsAdaptor( statementDetails, statement, session.getJdbcServices() );
118114
// force creation of the PreparedStatement
119115
//noinspection resource
120116
detailsAdaptor.resolveStatement();
121117
} );
122118
}
123-
}
119+
} );
124120
}
125121

126122
@Override
127-
protected void doStaticDelete(Object entity, Object id, Object rowId, Object[] loadedState, Object version, SharedSessionContractImplementor session) {
123+
protected void doStaticDelete(Object entity, Object id, Object[] loadedState, Object version, SharedSessionContractImplementor session) {
128124
stage = new CompletableFuture<>();
129125
final boolean applyVersion = entity != null;
130126
final MutationOperationGroup operationGroupToUse = entity == null
131127
? resolveNoVersionDeleteGroup( session )
132128
: getStaticDeleteGroup();
133129

134130
final ReactiveMutationExecutor mutationExecutor = mutationExecutor( session, operationGroupToUse );
135-
for ( int position = 0; position < getStaticDeleteGroup().getNumberOfOperations(); position++ ) {
136-
final MutationOperation mutation = getStaticDeleteGroup().getOperation( position );
131+
getStaticDeleteGroup().forEachOperation( (position, mutation) -> {
137132
if ( mutation != null ) {
138133
mutationExecutor.getPreparedStatementDetails( mutation.getTableDetails().getTableName() );
139134
}
140-
}
135+
} );
141136

142137
if ( applyVersion ) {
143138
applyLocking( version, null, mutationExecutor, session );
144139
}
145140
final JdbcValueBindings jdbcValueBindings = mutationExecutor.getJdbcValueBindings();
146141
bindPartitionColumnValueBindings( loadedState, session, jdbcValueBindings );
147-
applyId( id, rowId, mutationExecutor, getStaticDeleteGroup(), session );
142+
applyId( id, null, mutationExecutor, getStaticDeleteGroup(), session );
148143
mutationExecutor.executeReactive(
149144
entity,
150145
null,
@@ -163,6 +158,38 @@ protected void doStaticDelete(Object entity, Object id, Object rowId, Object[] l
163158
.whenComplete( this::complete );
164159
}
165160

161+
/**
162+
* Copy and paste of the on in ORM
163+
*/
164+
private static void breakDownIdJdbcValues(
165+
Object id,
166+
Object rowId,
167+
SharedSessionContractImplementor session,
168+
JdbcValueBindings jdbcValueBindings,
169+
EntityRowIdMapping rowIdMapping,
170+
EntityTableMapping tableDetails) {
171+
if ( rowId != null && rowIdMapping != null && tableDetails.isIdentifierTable() ) {
172+
jdbcValueBindings.bindValue(
173+
rowId,
174+
tableDetails.getTableName(),
175+
rowIdMapping.getRowIdName(),
176+
ParameterUsage.RESTRICT
177+
);
178+
}
179+
else {
180+
tableDetails.getKeyMapping().breakDownKeyJdbcValues(
181+
id,
182+
(jdbcValue, columnMapping) -> jdbcValueBindings.bindValue(
183+
jdbcValue,
184+
tableDetails.getTableName(),
185+
columnMapping.getColumnName(),
186+
ParameterUsage.RESTRICT
187+
),
188+
session
189+
);
190+
}
191+
}
192+
166193
private void complete(Object o, Throwable throwable) {
167194
if ( throwable != null ) {
168195
stage.toCompletableFuture().completeExceptionally( throwable );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public CompletionStage<int[]> updateBatch(String sql, List<Tuple> parametersBatc
184184

185185
int i = 0;
186186
RowSet<Row> resultNext = result;
187-
if ( !parametersBatch.isEmpty() ) {
187+
if ( parametersBatch.size() > 0 ) {
188188
final RowIterator<Row> iterator = resultNext.iterator();
189189
if ( iterator.hasNext() ) {
190190
while ( iterator.hasNext() ) {

0 commit comments

Comments
 (0)