17
17
import io .vertx .core .net .SocketAddress ;
18
18
import io .vertx .oracleclient .OracleConnectOptions ;
19
19
import io .vertx .oracleclient .OraclePrepareOptions ;
20
+ import io .vertx .oracleclient .impl .commands .PrepareStatementCommand ;
21
+ import io .vertx .oracleclient .impl .commands .SimpleQueryCommand ;
20
22
import io .vertx .oracleclient .impl .commands .*;
21
23
import io .vertx .sqlclient .impl .Connection ;
22
24
import io .vertx .sqlclient .impl .PreparedStatement ;
23
- import io .vertx .sqlclient .impl .QueryResultHandler ;
24
- import io .vertx .sqlclient .impl .command .CommandBase ;
25
- import io .vertx .sqlclient .impl .command .ExtendedQueryCommand ;
26
- import io .vertx .sqlclient .impl .command .TxCommand ;
25
+ import io .vertx .sqlclient .impl .command .*;
27
26
import io .vertx .sqlclient .spi .DatabaseMetadata ;
28
27
import oracle .jdbc .OracleConnection ;
29
28
30
29
import java .sql .SQLException ;
30
+ import java .util .concurrent .ConcurrentHashMap ;
31
+ import java .util .concurrent .ConcurrentMap ;
31
32
32
33
import static io .vertx .oracleclient .impl .Helper .*;
33
34
@@ -36,6 +37,8 @@ public class CommandHandler implements Connection {
36
37
private final ContextInternal context ;
37
38
private final OracleConnectOptions options ;
38
39
private Holder holder ;
40
+ @ SuppressWarnings ("rawtypes" )
41
+ private ConcurrentMap <String , RowReader > cursors = new ConcurrentHashMap <>();
39
42
40
43
public CommandHandler (ContextInternal ctx , OracleConnectOptions options , OracleConnection oc ) {
41
44
this .context = ctx ;
@@ -123,7 +126,7 @@ public Future<Void> beforeRecycle() {
123
126
public <R > Future <R > schedule (ContextInternal contextInternal , CommandBase <R > commandBase ) {
124
127
Future <R > result ;
125
128
if (commandBase instanceof io .vertx .sqlclient .impl .command .SimpleQueryCommand ) {
126
- result = (Future <R >) handle ((io .vertx .sqlclient .impl .command .SimpleQueryCommand ) commandBase );
129
+ result = (Future <R >) handle ((io .vertx .sqlclient .impl .command .SimpleQueryCommand <?> ) commandBase );
127
130
} else if (commandBase instanceof io .vertx .sqlclient .impl .command .PrepareStatementCommand ) {
128
131
result = (Future <R >) handle ((io .vertx .sqlclient .impl .command .PrepareStatementCommand ) commandBase );
129
132
} else if (commandBase instanceof ExtendedQueryCommand ) {
@@ -132,6 +135,10 @@ public <R> Future<R> schedule(ContextInternal contextInternal, CommandBase<R> co
132
135
result = handle ((TxCommand <R >) commandBase );
133
136
} else if (commandBase instanceof PingCommand ) {
134
137
result = (Future <R >) handle ((PingCommand ) commandBase );
138
+ } else if (commandBase instanceof CloseStatementCommand ) {
139
+ result = context .succeededFuture ();
140
+ } else if (commandBase instanceof CloseCursorCommand ) {
141
+ result = (Future <R >) handle ((CloseCursorCommand ) commandBase );
135
142
} else {
136
143
result = context .failedFuture ("Not yet implemented " + commandBase );
137
144
}
@@ -158,42 +165,46 @@ public <R> Future<R> schedule(ContextInternal contextInternal, CommandBase<R> co
158
165
});
159
166
}
160
167
168
+ private Future <Void > handle (CloseCursorCommand cmd ) {
169
+ RowReader <?, ?> reader = cursors .remove (cmd .id ());
170
+ if (reader == null ) {
171
+ return context .succeededFuture ();
172
+ }
173
+ return reader .close ();
174
+ }
175
+
161
176
private Future <Integer > handle (PingCommand ping ) {
162
177
return ping .execute (connection , context );
163
178
}
164
179
165
- @ SuppressWarnings ({ "unchecked" , "rawtypes" })
166
- private <R > Future <Boolean > handle (io .vertx .sqlclient .impl .command .SimpleQueryCommand command ) {
167
- QueryCommand <?, R > action = new SimpleQueryCommand <>(command . sql (), command .collector ());
168
- return handle ( action , command . resultHandler () );
180
+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
181
+ private <R > Future <Boolean > handle (io .vertx .sqlclient .impl .command .SimpleQueryCommand cmd ) {
182
+ QueryCommand <?, R > action = new SimpleQueryCommand <>(cmd , cmd .collector ());
183
+ return action . execute ( connection , context );
169
184
}
170
185
171
186
private Future <PreparedStatement > handle (io .vertx .sqlclient .impl .command .PrepareStatementCommand command ) {
172
187
PrepareStatementCommand action = new PrepareStatementCommand (OraclePrepareOptions .createFrom (command .options ()), command .sql ());
173
188
return action .execute (connection , context );
174
189
}
175
190
176
- private <R > Future <Boolean > handle (QueryCommand <?, R > action , QueryResultHandler <R > handler ) {
177
- Future <OracleResponse <R >> fut = action .execute (connection , context );
178
- return fut
179
- .onSuccess (ar -> ar .handle (handler )).map (false )
180
- .onFailure (t -> holder .handleException (t ));
181
-
182
- }
183
-
184
- private <R > Future <Boolean > handle (ExtendedQueryCommand <R > command ) {
185
- if (command .cursorId () != null ) {
186
- QueryCommand <?, R > cmd = new OracleCursorQueryCommand <>(command , command .params ());
187
- return cmd .execute (connection , context )
188
- .map (false );
191
+ @ SuppressWarnings ("unchecked" )
192
+ private <R > Future <Boolean > handle (ExtendedQueryCommand <R > cmd ) {
193
+ AbstractCommand <Boolean > action ;
194
+ String cursorId = cmd .cursorId ();
195
+ if (cursorId != null ) {
196
+ RowReader <?, R > rowReader = cursors .get (cursorId );
197
+ if (rowReader != null ) {
198
+ action = new OracleCursorFetchCommand <>(cmd , rowReader );
199
+ } else {
200
+ action = new OracleCursorQueryCommand <>(cmd , cmd .collector (), rr -> cursors .put (cursorId , rr ));
201
+ }
202
+ } else if (cmd .isBatch ()) {
203
+ action = new OraclePreparedBatch <>(cmd , cmd .collector ());
204
+ } else {
205
+ action = new OraclePreparedQuery <>(cmd , cmd .collector ());
189
206
}
190
-
191
- QueryCommand <?, R > action =
192
- command .isBatch () ?
193
- new OraclePreparedBatch <>(command , command .collector (), command .paramsList ())
194
- : new OraclePreparedQuery <>(command , command .collector (), command .params ());
195
-
196
- return handle (action , command .resultHandler ());
207
+ return action .execute (connection , context );
197
208
}
198
209
199
210
private <R > Future <R > handle (TxCommand <R > command ) {
0 commit comments