1
1
2
2
package io .helidon .benchmark .nima .models ;
3
3
4
+ import java .util .concurrent .CompletableFuture ;
5
+ import java .util .concurrent .ExecutionException ;
6
+
4
7
import io .vertx .pgclient .PgConnection ;
5
8
import io .vertx .sqlclient .PreparedQuery ;
9
+ import io .vertx .sqlclient .PreparedStatement ;
6
10
import io .vertx .sqlclient .Row ;
7
11
import io .vertx .sqlclient .RowSet ;
8
12
@@ -11,9 +15,9 @@ public class PgClientConnection implements AutoCloseable {
11
15
private static String SELECT_WORLD = "SELECT id, randomnumber from WORLD where id=$1" ;
12
16
private static String SELECT_FORTUNE = "SELECT * from FORTUNE" ;
13
17
14
- private PreparedQuery < RowSet < Row > > worldQuery ;
15
- private PreparedQuery < RowSet < Row > > fortuneQuery ;
16
- private PreparedQuery < RowSet < Row > >[] updateQuery ;
18
+ private CompletableFuture < PreparedStatement > worldQuery ;
19
+ private CompletableFuture < PreparedStatement > fortuneQuery ;
20
+ private CompletableFuture < PreparedStatement >[] updateQuery ;
17
21
18
22
private final PgConnection conn ;
19
23
@@ -30,30 +34,28 @@ public void close() {
30
34
conn .close ();
31
35
}
32
36
33
- public PreparedQuery <RowSet <Row >> worldQuery () {
34
- return worldQuery ;
37
+ public PreparedQuery <RowSet <Row >> worldQuery () throws ExecutionException , InterruptedException {
38
+ return worldQuery . get (). query () ;
35
39
}
36
40
37
- public PreparedQuery <RowSet <Row >> fortuneQuery () {
38
- return fortuneQuery ;
41
+ public PreparedQuery <RowSet <Row >> fortuneQuery () throws ExecutionException , InterruptedException {
42
+ return fortuneQuery . get (). query () ;
39
43
}
40
44
41
- public PreparedQuery <RowSet <Row >> updateQuery (int queryCount ) {
42
- return updateQuery [queryCount - 1 ];
45
+ public PreparedQuery <RowSet <Row >> updateQuery (int queryCount ) throws ExecutionException , InterruptedException {
46
+ return updateQuery [queryCount - 1 ]. get (). query () ;
43
47
}
44
48
45
49
@ SuppressWarnings ("unchecked" )
46
50
void prepare () {
47
51
try {
48
- worldQuery = conn .prepare (SELECT_WORLD )
49
- .toCompletionStage ().toCompletableFuture ().get ().query ();
50
- fortuneQuery = conn .prepare (SELECT_FORTUNE )
51
- .toCompletionStage ().toCompletableFuture ().get ().query ();
52
- updateQuery = (PreparedQuery <RowSet <Row >>[]) new PreparedQuery <?>[UPDATE_QUERIES ];
52
+ worldQuery = conn .prepare (SELECT_WORLD ).toCompletionStage ().toCompletableFuture ();
53
+ fortuneQuery = conn .prepare (SELECT_FORTUNE ).toCompletionStage ().toCompletableFuture ();
54
+ updateQuery = (CompletableFuture <PreparedStatement >[]) new CompletableFuture <?>[UPDATE_QUERIES ];
53
55
for (int i = 0 ; i < UPDATE_QUERIES ; i ++) {
54
56
updateQuery [i ] = conn .prepare (singleUpdate (i + 1 ))
55
- .toCompletionStage ().toCompletableFuture (). get (). query ();
56
- }
57
+ .toCompletionStage ().toCompletableFuture ();
58
+ }
57
59
} catch (Exception e ) {
58
60
throw new RuntimeException (e );
59
61
}
0 commit comments