Skip to content

Commit 59f37b0

Browse files
committed
Configurable statement options for Oracle Client
In the Vert.x JDBC Client, it is possible to configure different statement options in JDBCConnectOptions: - query timeout - max rows - fetch direction - fetch size This change provides a similar feature for the Reactive Oracle Client. Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent 88ff5f7 commit 59f37b0

10 files changed

Lines changed: 149 additions & 29 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
11+
package io.vertx.oracleclient;
12+
13+
import java.sql.ResultSet;
14+
15+
/**
16+
* Represents the fetch direction hint
17+
*/
18+
public enum FetchDirection {
19+
20+
FORWARD(ResultSet.FETCH_FORWARD),
21+
REVERSE(ResultSet.FETCH_REVERSE),
22+
UNKNOWN(ResultSet.FETCH_UNKNOWN);
23+
24+
private final int type;
25+
26+
FetchDirection(int type) {
27+
this.type = type;
28+
}
29+
30+
public int getType() {
31+
return type;
32+
}
33+
}

vertx-oracle-client/src/main/java/io/vertx/oracleclient/OracleConnectOptions.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2022 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -50,6 +50,12 @@ public static OracleConnectOptions wrap(SqlConnectOptions options) {
5050
private String tnsAlias;
5151
private String tnsAdmin;
5252

53+
private int queryTimeout;
54+
private int maxRows;
55+
private FetchDirection fetchDirection;
56+
private int fetchSize;
57+
58+
5359
public OracleConnectOptions() {
5460
super();
5561
}
@@ -66,6 +72,10 @@ private void copyFields(OracleConnectOptions other) {
6672
this.instanceName = other.instanceName;
6773
this.tnsAlias = other.tnsAlias;
6874
this.tnsAdmin = other.tnsAdmin;
75+
this.queryTimeout = other.queryTimeout;
76+
this.maxRows = other.maxRows;
77+
this.fetchDirection = other.fetchDirection;
78+
this.fetchSize = other.fetchSize;
6979
}
7080

7181
public OracleConnectOptions(SqlConnectOptions options) {
@@ -205,6 +215,54 @@ public OracleConnectOptions setTnsAdmin(String tnsAdmin) {
205215
return this;
206216
}
207217

218+
public int getQueryTimeout() {
219+
return queryTimeout;
220+
}
221+
222+
/**
223+
* @see java.sql.PreparedStatement#setQueryTimeout(int)
224+
*/
225+
public OracleConnectOptions setQueryTimeout(int queryTimeout) {
226+
this.queryTimeout = queryTimeout;
227+
return this;
228+
}
229+
230+
public int getMaxRows() {
231+
return maxRows;
232+
}
233+
234+
/**
235+
* @see java.sql.PreparedStatement#setMaxRows(int)
236+
*/
237+
public OracleConnectOptions setMaxRows(int maxRows) {
238+
this.maxRows = maxRows;
239+
return this;
240+
}
241+
242+
public FetchDirection getFetchDirection() {
243+
return fetchDirection;
244+
}
245+
246+
/**
247+
* @see java.sql.PreparedStatement#setFetchDirection(int)
248+
*/
249+
public OracleConnectOptions setFetchDirection(FetchDirection fetchDirection) {
250+
this.fetchDirection = fetchDirection;
251+
return this;
252+
}
253+
254+
public int getFetchSize() {
255+
return fetchSize;
256+
}
257+
258+
/**
259+
* @see java.sql.PreparedStatement#setFetchSize(int)
260+
*/
261+
public OracleConnectOptions setFetchSize(int fetchSize) {
262+
this.fetchSize = fetchSize;
263+
return this;
264+
}
265+
208266
// Non-specific options
209267

210268
@Override

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/OracleJdbcConnection.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -219,9 +219,9 @@ private void checkPending() {
219219
private OracleCommand wrap(CommandBase cmd) {
220220
OracleCommand action;
221221
if (cmd instanceof SimpleQueryCommand) {
222-
action = OracleSimpleQueryCommand.create(connection, context, (SimpleQueryCommand) cmd);
222+
action = OracleSimpleQueryCommand.create(connection, context, (SimpleQueryCommand) cmd, options);
223223
} else if (cmd instanceof PrepareStatementCommand) {
224-
action = new OraclePrepareStatementCommand(connection, context, (PrepareStatementCommand) cmd);
224+
action = new OraclePrepareStatementCommand(connection, context, (PrepareStatementCommand) cmd, options);
225225
} else if (cmd instanceof ExtendedQueryCommand) {
226226
action = forExtendedQuery((ExtendedQueryCommand) cmd);
227227
} else if (cmd instanceof TxCommand) {
@@ -249,12 +249,12 @@ private OracleCommand forExtendedQuery(ExtendedQueryCommand cmd) {
249249
if (rowReader != null) {
250250
action = OracleCursorFetchCommand.create(connection, context, cmd, rowReader);
251251
} else {
252-
action = OracleCursorQueryCommand.create(connection, context, cmd, cmd.collector(), rr -> cursors.put(cursorId, rr));
252+
action = OracleCursorQueryCommand.create(connection, context, cmd, cmd.collector(), rr -> cursors.put(cursorId, rr), options);
253253
}
254254
} else if (cmd.isBatch()) {
255-
action = new OraclePreparedBatchQuery(connection, context, cmd, cmd.collector());
255+
action = new OraclePreparedBatchQueryCommand(connection, context, cmd, cmd.collector(), options);
256256
} else {
257-
action = new OraclePreparedQueryCommand(connection, context, cmd, cmd.collector());
257+
action = new OraclePreparedQueryCommand(connection, context, cmd, cmd.collector(), options);
258258
}
259259
return action;
260260
}

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCommand.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -13,11 +13,14 @@
1313
import io.vertx.core.Future;
1414
import io.vertx.core.Promise;
1515
import io.vertx.core.impl.ContextInternal;
16+
import io.vertx.oracleclient.OracleConnectOptions;
1617
import io.vertx.oracleclient.impl.Helper.SQLBlockingCodeHandler;
1718
import io.vertx.sqlclient.impl.command.CommandBase;
1819
import io.vertx.sqlclient.impl.command.CommandResponse;
1920
import oracle.jdbc.OracleConnection;
2021

22+
import java.sql.SQLException;
23+
import java.sql.Statement;
2124
import java.util.concurrent.Flow;
2225

2326
import static io.vertx.oracleclient.impl.FailureUtil.sanitize;
@@ -89,4 +92,21 @@ public void onComplete() {
8992
public final void fireResponse() {
9093
response.fire();
9194
}
95+
96+
protected void applyStatementOptions(Statement stmt, OracleConnectOptions connectOptions) throws SQLException {
97+
if (connectOptions != null) {
98+
if (connectOptions.getQueryTimeout() > 0) {
99+
stmt.setQueryTimeout(connectOptions.getQueryTimeout());
100+
}
101+
if (connectOptions.getMaxRows() > 0) {
102+
stmt.setMaxRows(connectOptions.getMaxRows());
103+
}
104+
if (connectOptions.getFetchDirection() != null) {
105+
stmt.setFetchDirection(connectOptions.getFetchDirection().getType());
106+
}
107+
if (connectOptions.getFetchSize() > 0) {
108+
stmt.setFetchSize(connectOptions.getFetchSize());
109+
}
110+
}
111+
}
92112
}

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCursorQueryCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -38,8 +38,8 @@ public class OracleCursorQueryCommand<C, R> extends OracleQueryCommand<C, R> {
3838
private final Collector<Row, C, R> collector;
3939
private final QueryResultHandler<R> resultHandler;
4040

41-
private OracleCursorQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<R> cmd, Collector<Row, C, R> collector, Consumer<RowReader<C, R>> store) {
42-
super(oracleConnection, connectionContext, collector);
41+
private OracleCursorQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<R> cmd, Collector<Row, C, R> collector, Consumer<RowReader<C, R>> store, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
42+
super(oracleConnection, connectionContext, collector, connectOptions);
4343
sql = cmd.sql();
4444
fetch = cmd.fetch();
4545
params = cmd.params();
@@ -49,8 +49,8 @@ private OracleCursorQueryCommand(OracleConnection oracleConnection, ContextInter
4949
this.store = store;
5050
}
5151

52-
public static <U, V> OracleCursorQueryCommand<U, V> create(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<V> cmd, Collector<Row, U, V> collector, Consumer<RowReader<U, V>> store) {
53-
return new OracleCursorQueryCommand<>(oracleConnection, connectionContext, cmd, collector, store);
52+
public static <U, V> OracleCursorQueryCommand<U, V> create(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<V> cmd, Collector<Row, U, V> collector, Consumer<RowReader<U, V>> store, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
53+
return new OracleCursorQueryCommand<>(oracleConnection, connectionContext, cmd, collector, store, connectOptions);
5454
}
5555

5656
@Override

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePrepareStatementCommand.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -13,6 +13,7 @@
1313
import io.vertx.core.Future;
1414
import io.vertx.core.impl.ContextInternal;
1515
import io.vertx.core.json.JsonArray;
16+
import io.vertx.oracleclient.OracleConnectOptions;
1617
import io.vertx.oracleclient.OraclePrepareOptions;
1718
import io.vertx.sqlclient.impl.PreparedStatement;
1819
import io.vertx.sqlclient.impl.command.PrepareStatementCommand;
@@ -25,11 +26,13 @@ public class OraclePrepareStatementCommand extends OracleCommand<PreparedStateme
2526

2627
private final OraclePrepareOptions options;
2728
private final String sql;
29+
private final OracleConnectOptions connectOptions;
2830

29-
public OraclePrepareStatementCommand(OracleConnection oracleConnection, ContextInternal connectionContext, PrepareStatementCommand cmd) {
31+
public OraclePrepareStatementCommand(OracleConnection oracleConnection, ContextInternal connectionContext, PrepareStatementCommand cmd, OracleConnectOptions connectOptions) {
3032
super(oracleConnection, connectionContext);
3133
this.options = OraclePrepareOptions.createFrom(cmd.options());
3234
this.sql = cmd.sql();
35+
this.connectOptions = connectOptions;
3336
}
3437

3538
@Override
@@ -56,6 +59,7 @@ private Future<PreparedStatement> prepareWithAutoGeneratedIndexes() {
5659
keys[i] = indexes.getInteger(i);
5760
}
5861
try (java.sql.PreparedStatement statement = oracleConnection.prepareStatement(sql, keys)) {
62+
applyStatementOptions(statement, connectOptions);
5963
return new OraclePreparedStatement(sql, statement);
6064
}
6165
}
@@ -65,6 +69,7 @@ private Future<PreparedStatement> prepareWithAutoGeneratedIndexes() {
6569
keys[i] = indexes.getString(i);
6670
}
6771
try (java.sql.PreparedStatement statement = oracleConnection.prepareStatement(sql, keys)) {
72+
applyStatementOptions(statement, connectOptions);
6873
return new OraclePreparedStatement(sql, statement);
6974
}
7075
}

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQuery.java renamed to vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQueryCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -33,14 +33,14 @@
3333

3434
import static io.vertx.oracleclient.impl.FailureUtil.sanitize;
3535

36-
public class OraclePreparedBatchQuery<C, R> extends OracleQueryCommand<C, R> {
36+
public class OraclePreparedBatchQueryCommand<C, R> extends OracleQueryCommand<C, R> {
3737

3838
private final String sql;
3939
private final List<TupleInternal> listParams;
4040
private final QueryResultHandler<R> resultHandler;
4141

42-
public OraclePreparedBatchQuery(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<R> cmd, Collector<Row, C, R> collector) {
43-
super(oracleConnection, connectionContext, collector);
42+
public OraclePreparedBatchQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<R> cmd, Collector<Row, C, R> collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
43+
super(oracleConnection, connectionContext, collector, connectOptions);
4444
sql = cmd.sql();
4545
listParams = cmd.paramsList();
4646
resultHandler = cmd.resultHandler();

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedQueryCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -33,8 +33,8 @@ public class OraclePreparedQueryCommand<C, R> extends OracleQueryCommand<C, R> {
3333
private final PrepareOptions prepareOptions;
3434
private final QueryResultHandler<R> resultHandler;
3535

36-
public OraclePreparedQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<R> cmd, Collector<Row, C, R> collector) {
37-
super(oracleConnection, connectionContext, collector);
36+
public OraclePreparedQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand<R> cmd, Collector<Row, C, R> collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
37+
super(oracleConnection, connectionContext, collector, connectOptions);
3838
sql = cmd.sql();
3939
params = cmd.params();
4040
prepareOptions = cmd.options();

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleQueryCommand.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -15,6 +15,7 @@
1515
import io.vertx.core.buffer.Buffer;
1616
import io.vertx.core.impl.ContextInternal;
1717
import io.vertx.core.json.JsonArray;
18+
import io.vertx.oracleclient.OracleConnectOptions;
1819
import io.vertx.oracleclient.OraclePrepareOptions;
1920
import io.vertx.oracleclient.data.Blob;
2021
import io.vertx.oracleclient.impl.Helper;
@@ -39,10 +40,12 @@
3940
public abstract class OracleQueryCommand<C, R> extends OracleCommand<Boolean> {
4041

4142
private final Collector<Row, C, R> collector;
43+
private final OracleConnectOptions connectOptions;
4244

43-
protected OracleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, Collector<Row, C, R> collector) {
45+
protected OracleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, Collector<Row, C, R> collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
4446
super(oracleConnection, connectionContext);
4547
this.collector = collector;
48+
this.connectOptions = connectOptions;
4649
}
4750

4851
@Override
@@ -126,6 +129,7 @@ private Future<OraclePreparedStatement> prepare(Connection conn, OraclePrepareOp
126129
ps = conn.prepareStatement(query());
127130
}
128131

132+
applyStatementOptions(ps, connectOptions);
129133
fillStatement(ps, conn);
130134

131135
prom.complete(ps.unwrap(OraclePreparedStatement.class));

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleSimpleQueryCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -29,14 +29,14 @@ public class OracleSimpleQueryCommand<C, R> extends OracleQueryCommand<C, R> {
2929
private final String sql;
3030
private final QueryResultHandler<R> resultHandler;
3131

32-
private OracleSimpleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand<R> cmd, Collector<Row, C, R> collector) {
33-
super(oracleConnection, connectionContext, collector);
32+
private OracleSimpleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand<R> cmd, Collector<Row, C, R> collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
33+
super(oracleConnection, connectionContext, collector, connectOptions);
3434
sql = cmd.sql();
3535
resultHandler = cmd.resultHandler();
3636
}
3737

38-
public static <U> OracleSimpleQueryCommand<?, U> create(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand<U> cmd) {
39-
return new OracleSimpleQueryCommand<>(oracleConnection, connectionContext, cmd, cmd.collector());
38+
public static <U> OracleSimpleQueryCommand<?, U> create(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand<U> cmd, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
39+
return new OracleSimpleQueryCommand<>(oracleConnection, connectionContext, cmd, cmd.collector(), connectOptions);
4040
}
4141

4242
@Override

0 commit comments

Comments
 (0)