8
8
import java .lang .invoke .MethodHandles ;
9
9
import java .util .concurrent .CompletionStage ;
10
10
11
+ import org .hibernate .dialect .Dialect ;
12
+ import org .hibernate .dialect .PostgreSQLDialect ;
11
13
import org .hibernate .engine .jdbc .mutation .JdbcValueBindings ;
12
14
import org .hibernate .engine .jdbc .mutation .group .PreparedStatementDetails ;
13
15
import org .hibernate .engine .jdbc .spi .JdbcServices ;
22
24
import org .hibernate .reactive .session .ReactiveConnectionSupplier ;
23
25
24
26
import static java .util .function .Function .identity ;
27
+ import static org .hibernate .dialect .DialectDelegateWrapper .extractRealDialect ;
25
28
26
29
public interface ReactiveAbstractReturningDelegate extends ReactiveInsertGeneratedIdentifierDelegate {
27
30
@@ -31,16 +34,13 @@ public interface ReactiveAbstractReturningDelegate extends ReactiveInsertGenerat
31
34
32
35
@ Override
33
36
default CompletionStage <Object > reactivePerformInsert (PreparedStatementDetails insertStatementDetails , JdbcValueBindings jdbcValueBindings , Object entity , SharedSessionContractImplementor session ) {
34
- // FIXME: I should be able to generate the sql string beforehand
35
37
final Class <?> idType = getPersister ().getIdentifierType ().getReturnedClass ();
36
- final String identifierColumnName = getPersister ().getIdentifierColumnNames ()[0 ];
37
- final String insertSql = insertStatementDetails .getSqlString () + " returning " + identifierColumnName ;
38
-
39
38
final JdbcServices jdbcServices = session .getJdbcServices ();
40
- jdbcServices .getSqlStatementLogger ().logStatement ( insertSql );
39
+ final String identifierColumnName = getPersister ().getIdentifierColumnNames ()[0 ];
40
+ final String insertSql = createInsert ( insertStatementDetails , identifierColumnName , jdbcServices .getDialect () );
41
41
42
42
Object [] params = PreparedStatementAdaptor .bind ( statement -> {
43
- PreparedStatementDetails details = new PrepareStatementDetailsAdaptor ( insertStatementDetails , statement , session . getJdbcServices () );
43
+ PreparedStatementDetails details = new PrepareStatementDetailsAdaptor ( insertStatementDetails , statement , jdbcServices );
44
44
jdbcValueBindings .beforeStatement ( details );
45
45
} );
46
46
@@ -50,6 +50,17 @@ default CompletionStage<Object> reactivePerformInsert(PreparedStatementDetails i
50
50
.thenApply ( identity () );
51
51
}
52
52
53
+ private static String createInsert (PreparedStatementDetails insertStatementDetails , String identifierColumnName , Dialect dialect ) {
54
+ if ( instanceOf ( dialect , PostgreSQLDialect .class ) ) {
55
+ return insertStatementDetails .getSqlString () + " returning " + identifierColumnName ;
56
+ }
57
+ return insertStatementDetails .getSqlString ();
58
+ }
59
+
60
+ private static boolean instanceOf (Dialect dialect , Class <?> dialectClass ) {
61
+ return dialectClass .isInstance ( extractRealDialect ( dialect ) );
62
+ }
63
+
53
64
@ Override
54
65
default CompletionStage <Object > reactivePerformInsert (String insertSQL , SharedSessionContractImplementor session , Binder binder ) {
55
66
throw LOG .notYetImplemented ();
0 commit comments