Skip to content

Commit 6bba877

Browse files
committed
[#255] Refactor temporary tables creation
* Separate the logic between Db2 (global temporary tables) and the other databases (local temporary tables). * Remove custom logic to figure out how to run queries * Rename ReactiveConnection#executeStatement to ReactiveConnection#executeUnprepared
1 parent 961eb04 commit 6bba877

File tree

8 files changed

+155
-152
lines changed

8 files changed

+155
-152
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/bulk/StatementsWithParameters.java

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
import org.hibernate.engine.spi.QueryParameters;
1111
import org.hibernate.param.ParameterSpecification;
1212
import org.hibernate.reactive.adaptor.impl.QueryParametersAdaptor;
13-
import org.hibernate.reactive.pool.ReactiveConnection;
1413
import org.hibernate.reactive.session.ReactiveQueryExecutor;
15-
import org.hibernate.reactive.util.impl.CompletionStages;
1614

1715
import static org.hibernate.reactive.util.impl.CompletionStages.total;
1816

19-
2017
/**
2118
* A list of SQL statements to be executed as a single logical unit.
2219
* May include both DDL and DML statements.
@@ -35,55 +32,17 @@ public interface StatementsWithParameters {
3532
*/
3633
ParameterSpecification[][] getParameterSpecifications();
3734

38-
/**
39-
* Is the given statement executed inside the current transaction?
40-
*
41-
* @return true by default
42-
*/
43-
default boolean isTransactionalStatement(String statement) {
44-
return true;
45-
}
46-
47-
/**
48-
* Should the result of this statement contribute to the running
49-
* updated row count?
50-
*
51-
* @return false for DDL statements by default
52-
*/
53-
default boolean isSchemaDefinitionStatement(String statement) {
54-
return statement.startsWith("create ")
55-
|| statement.startsWith("drop ");
56-
}
57-
5835
/**
5936
* Execute the statements using the query parameters
6037
*/
6138
default CompletionStage<Integer> execute(ReactiveQueryExecutor session, QueryParameters queryParameters) {
6239
return total( 0, getSqlStatements().length, i -> {
63-
final String sql = getSqlStatements()[i];
64-
ReactiveConnection connection = session.getReactiveConnection();
65-
if ( !isSchemaDefinitionStatement( sql ) ) {
66-
final Object[] arguments = QueryParametersAdaptor.arguments(
67-
queryParameters,
68-
getParameterSpecifications()[i],
69-
session.getSharedContract()
70-
);
71-
return connection.update( sql, arguments );
72-
}
73-
else if ( isTransactionalStatement( sql ) ) {
74-
// a DML statement that should be executed within the
75-
// transaction (local temporary tables)
76-
return connection.execute( sql )
77-
.thenCompose( CompletionStages::zeroFuture );
78-
}
79-
else {
80-
// a DML statement that should be executed outside the
81-
// transaction (global temporary tables)
82-
return connection.executeOutsideTransaction( sql )
83-
// ignore errors creating tables, since a create
84-
// table fails whenever the table already exists
85-
.handle( (v, x) -> 0 );
86-
}
40+
final Object[] arguments = QueryParametersAdaptor.arguments(
41+
queryParameters,
42+
getParameterSpecifications()[i],
43+
session.getSharedContract()
44+
);
45+
return session.getReactiveConnection().update( getSqlStatements()[i], arguments );
8746
} );
8847
}
8948
}

0 commit comments

Comments
 (0)