Skip to content

Commit 25790c2

Browse files
committed
HHH-18854 OptionalTableUpdateOperation: change scopes and minor
refactoring Allow me to remove some duplicated code in Hibernate Reactive
1 parent 8ac93c6 commit 25790c2

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

hibernate-core/src/main/java/org/hibernate/sql/model/jdbc/OptionalTableUpdateOperation.java

+47-35
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ private static void bindKeyValue(
263263
}
264264
}
265265

266-
private JdbcDeleteMutation createJdbcDelete(SharedSessionContractImplementor session) {
266+
/*
267+
* Used by Hibernate Reactive
268+
*/
269+
protected JdbcDeleteMutation createJdbcDelete(SharedSessionContractImplementor session) {
267270
final TableDelete tableDelete;
268271
if ( tableMapping.getDeleteDetails() != null
269272
&& tableMapping.getDeleteDetails().getCustomSql() != null ) {
@@ -305,39 +308,7 @@ private boolean performUpdate(
305308
JdbcValueBindings jdbcValueBindings,
306309
SharedSessionContractImplementor session) {
307310
MODEL_MUTATION_LOGGER.tracef( "#performUpdate(%s)", tableMapping.getTableName() );
308-
309-
final TableUpdate<JdbcMutationOperation> tableUpdate;
310-
if ( tableMapping.getUpdateDetails() != null
311-
&& tableMapping.getUpdateDetails().getCustomSql() != null ) {
312-
tableUpdate = new TableUpdateCustomSql(
313-
new MutatingTableReference( tableMapping ),
314-
mutationTarget,
315-
"upsert update for " + mutationTarget.getRolePath(),
316-
valueBindings,
317-
keyBindings,
318-
optimisticLockBindings,
319-
parameters
320-
);
321-
}
322-
else {
323-
tableUpdate = new TableUpdateStandard(
324-
new MutatingTableReference( tableMapping ),
325-
mutationTarget,
326-
"upsert update for " + mutationTarget.getRolePath(),
327-
valueBindings,
328-
keyBindings,
329-
optimisticLockBindings,
330-
parameters
331-
);
332-
}
333-
334-
final SqlAstTranslator<JdbcMutationOperation> translator = session
335-
.getJdbcServices()
336-
.getJdbcEnvironment()
337-
.getSqlAstTranslatorFactory()
338-
.buildModelMutationTranslator( tableUpdate, session.getFactory() );
339-
340-
final JdbcMutationOperation jdbcUpdate = translator.translate( null, MutationQueryOptions.INSTANCE );
311+
final JdbcMutationOperation jdbcUpdate = createJdbcUpdate( session );
341312

342313
final PreparedStatementGroupSingleTable statementGroup = new PreparedStatementGroupSingleTable( jdbcUpdate, session );
343314
final PreparedStatementDetails statementDetails = statementGroup.resolvePreparedStatementDetails( tableMapping.getTableName() );
@@ -374,6 +345,44 @@ private boolean performUpdate(
374345
}
375346
}
376347

348+
/*
349+
* Used by Hibernate Reactive
350+
*/
351+
protected JdbcMutationOperation createJdbcUpdate(SharedSessionContractImplementor session) {
352+
final TableUpdate<JdbcMutationOperation> tableUpdate;
353+
if ( tableMapping.getUpdateDetails() != null
354+
&& tableMapping.getUpdateDetails().getCustomSql() != null ) {
355+
tableUpdate = new TableUpdateCustomSql(
356+
new MutatingTableReference( tableMapping ),
357+
mutationTarget,
358+
"upsert update for " + mutationTarget.getRolePath(),
359+
valueBindings,
360+
keyBindings,
361+
optimisticLockBindings,
362+
parameters
363+
);
364+
}
365+
else {
366+
tableUpdate = new TableUpdateStandard(
367+
new MutatingTableReference( tableMapping ),
368+
mutationTarget,
369+
"upsert update for " + mutationTarget.getRolePath(),
370+
valueBindings,
371+
keyBindings,
372+
optimisticLockBindings,
373+
parameters
374+
);
375+
}
376+
377+
final SqlAstTranslator<JdbcMutationOperation> translator = session
378+
.getJdbcServices()
379+
.getJdbcEnvironment()
380+
.getSqlAstTranslatorFactory()
381+
.buildModelMutationTranslator( tableUpdate, session.getFactory() );
382+
383+
return translator.translate( null, MutationQueryOptions.INSTANCE );
384+
}
385+
377386
private void performInsert(JdbcValueBindings jdbcValueBindings, SharedSessionContractImplementor session) {
378387
final JdbcInsertMutation jdbcInsert = createJdbcInsert( session );
379388

@@ -414,7 +423,10 @@ private void performInsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
414423
}
415424
}
416425

417-
private JdbcInsertMutation createJdbcInsert(SharedSessionContractImplementor session) {
426+
/*
427+
* Used by Hibernate Reactive
428+
*/
429+
protected JdbcInsertMutation createJdbcInsert(SharedSessionContractImplementor session) {
418430
final TableInsert tableInsert;
419431
if ( tableMapping.getInsertDetails() != null
420432
&& tableMapping.getInsertDetails().getCustomSql() != null ) {

0 commit comments

Comments
 (0)