9
9
import java .util .concurrent .CompletionStage ;
10
10
import java .util .function .Function ;
11
11
12
+ import org .hibernate .dialect .CockroachDialect ;
13
+ import org .hibernate .dialect .Dialect ;
12
14
import org .hibernate .dialect .temptable .TemporaryTable ;
13
15
import org .hibernate .dialect .temptable .TemporaryTableExporter ;
14
16
import org .hibernate .engine .jdbc .internal .FormatStyle ;
20
22
import org .hibernate .reactive .logging .impl .Log ;
21
23
import org .hibernate .reactive .logging .impl .LoggerFactory ;
22
24
import org .hibernate .reactive .pool .ReactiveConnection ;
23
- import org .hibernate .reactive .pool .impl .Parameters ;
24
25
import org .hibernate .reactive .session .ReactiveConnectionSupplier ;
25
26
import org .hibernate .reactive .util .impl .CompletionStages ;
26
27
@@ -144,9 +145,8 @@ public static CompletionStage<Void> cleanTemporaryTableRows(
144
145
TemporaryTableExporter exporter ,
145
146
Function <SharedSessionContractImplementor , String > sessionUidAccess ,
146
147
SharedSessionContractImplementor session ) {
147
- // Workaround for https://hibernate.atlassian.net/browse/HHH-16486
148
- final String sql = Parameters .instance ( temporaryTable .getDialect () )
149
- .process ( exporter .getSqlTruncateCommand ( temporaryTable , sessionUidAccess , session ) );
148
+
149
+ final String sql = fixforCockroach ( temporaryTable .getDialect (), exporter .getSqlTruncateCommand ( temporaryTable , sessionUidAccess , session ) );
150
150
151
151
Object [] params = PreparedStatementAdaptor .bind ( ps -> {
152
152
if ( temporaryTable .getSessionUidColumn () != null ) {
@@ -160,6 +160,17 @@ public static CompletionStage<Void> cleanTemporaryTableRows(
160
160
.thenCompose ( CompletionStages ::voidFuture );
161
161
}
162
162
163
+ // A hack so that we can release: the issue is that the query generated by ORM uses $0 as placeholder, but the
164
+ // driver only accept placeholders starting from $1
165
+ private static String fixforCockroach (Dialect dialect , String sqlTruncateCommand ) {
166
+ if ( sqlTruncateCommand .endsWith ( "$0" ) ) {
167
+ if ( dialect instanceof CockroachDialect ) {
168
+ return sqlTruncateCommand .replaceAll ( "\\ $0$" , "\\ $1" );
169
+ }
170
+ }
171
+ return sqlTruncateCommand ;
172
+ }
173
+
163
174
private static ReactiveConnection reactiveConnection (SharedSessionContractImplementor session ) {
164
175
return ( (ReactiveConnectionSupplier ) session ).getReactiveConnection ();
165
176
}
0 commit comments