Skip to content

Commit 66dffa8

Browse files
authored
Configurable statement options for Oracle Client (#1616)
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 6fa6a56 commit 66dffa8

10 files changed

Lines changed: 151 additions & 38 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
@@ -52,6 +52,12 @@ public static OracleConnectOptions wrap(SqlConnectOptions options) {
5252
private String tnsAdmin;
5353
private boolean ssl;
5454

55+
private int queryTimeout;
56+
private int maxRows;
57+
private FetchDirection fetchDirection;
58+
private int fetchSize;
59+
60+
5561
public OracleConnectOptions() {
5662
super();
5763
}
@@ -69,6 +75,10 @@ private void copyFields(OracleConnectOptions other) {
6975
this.tnsAlias = other.tnsAlias;
7076
this.tnsAdmin = other.tnsAdmin;
7177
this.ssl = other.ssl;
78+
this.queryTimeout = other.queryTimeout;
79+
this.maxRows = other.maxRows;
80+
this.fetchDirection = other.fetchDirection;
81+
this.fetchSize = other.fetchSize;
7282
}
7383

7484
public OracleConnectOptions(SqlConnectOptions options) {
@@ -208,6 +218,54 @@ public OracleConnectOptions setTnsAdmin(String tnsAdmin) {
208218
return this;
209219
}
210220

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

213271
@Override

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

Lines changed: 8 additions & 15 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
@@ -20,17 +20,10 @@
2020
import io.vertx.core.tracing.TracingPolicy;
2121
import io.vertx.oracleclient.OracleConnectOptions;
2222
import io.vertx.oracleclient.impl.commands.*;
23-
import io.vertx.sqlclient.spi.connection.Connection;
2423
import io.vertx.sqlclient.spi.DatabaseMetadata;
24+
import io.vertx.sqlclient.spi.connection.Connection;
2525
import io.vertx.sqlclient.spi.connection.ConnectionContext;
26-
import io.vertx.sqlclient.spi.protocol.CloseConnectionCommand;
27-
import io.vertx.sqlclient.spi.protocol.CloseCursorCommand;
28-
import io.vertx.sqlclient.spi.protocol.CloseStatementCommand;
29-
import io.vertx.sqlclient.spi.protocol.CommandBase;
30-
import io.vertx.sqlclient.spi.protocol.ExtendedQueryCommand;
31-
import io.vertx.sqlclient.spi.protocol.PrepareStatementCommand;
32-
import io.vertx.sqlclient.spi.protocol.SimpleQueryCommand;
33-
import io.vertx.sqlclient.spi.protocol.TxCommand;
26+
import io.vertx.sqlclient.spi.protocol.*;
3427
import oracle.jdbc.OracleConnection;
3528

3629
import java.sql.SQLException;
@@ -206,9 +199,9 @@ private void checkPending() {
206199
private OracleCommand wrap(CommandBase cmd) {
207200
OracleCommand action;
208201
if (cmd instanceof SimpleQueryCommand) {
209-
action = OracleSimpleQueryCommand.create(connection, context, (SimpleQueryCommand) cmd);
202+
action = OracleSimpleQueryCommand.create(connection, context, (SimpleQueryCommand) cmd, options);
210203
} else if (cmd instanceof PrepareStatementCommand) {
211-
action = new OraclePrepareStatementCommand(connection, context, (PrepareStatementCommand) cmd);
204+
action = new OraclePrepareStatementCommand(connection, context, (PrepareStatementCommand) cmd, options);
212205
} else if (cmd instanceof ExtendedQueryCommand) {
213206
action = forExtendedQuery((ExtendedQueryCommand) cmd);
214207
} else if (cmd instanceof TxCommand) {
@@ -236,12 +229,12 @@ private OracleCommand forExtendedQuery(ExtendedQueryCommand cmd) {
236229
if (rowReader != null) {
237230
action = OracleCursorFetchCommand.create(connection, context, cmd, rowReader);
238231
} else {
239-
action = OracleCursorQueryCommand.create(connection, context, cmd, cmd.collector(), rr -> cursors.put(cursorId, rr));
232+
action = OracleCursorQueryCommand.create(connection, context, cmd, cmd.collector(), rr -> cursors.put(cursorId, rr), options);
240233
}
241234
} else if (cmd.isBatch()) {
242-
action = new OraclePreparedBatchQuery(connection, context, cmd, cmd.collector());
235+
action = new OraclePreparedBatchQueryCommand(connection, context, cmd, cmd.collector(), options);
243236
} else {
244-
action = new OraclePreparedQueryCommand(connection, context, cmd, cmd.collector());
237+
action = new OraclePreparedQueryCommand(connection, context, cmd, cmd.collector(), options);
245238
}
246239
return action;
247240
}

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
@@ -15,9 +15,12 @@
1515
import io.vertx.core.Future;
1616
import io.vertx.core.Promise;
1717
import io.vertx.core.internal.ContextInternal;
18+
import io.vertx.oracleclient.OracleConnectOptions;
1819
import io.vertx.oracleclient.impl.Helper.SQLBlockingCodeHandler;
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;
@@ -86,4 +89,21 @@ public void onComplete() {
8689
public final void fireResponse() {
8790
handler.complete(result.result(), result.cause());
8891
}
92+
93+
protected void applyStatementOptions(Statement stmt, OracleConnectOptions connectOptions) throws SQLException {
94+
if (connectOptions != null) {
95+
if (connectOptions.getQueryTimeout() > 0) {
96+
stmt.setQueryTimeout(connectOptions.getQueryTimeout());
97+
}
98+
if (connectOptions.getMaxRows() > 0) {
99+
stmt.setMaxRows(connectOptions.getMaxRows());
100+
}
101+
if (connectOptions.getFetchDirection() != null) {
102+
stmt.setFetchDirection(connectOptions.getFetchDirection().getType());
103+
}
104+
if (connectOptions.getFetchSize() > 0) {
105+
stmt.setFetchSize(connectOptions.getFetchSize());
106+
}
107+
}
108+
}
89109
}

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.internal.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.internal.PreparedStatement;
1819
import io.vertx.sqlclient.spi.protocol.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<TupleBase> 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
@@ -16,6 +16,7 @@
1616
import io.vertx.core.buffer.Buffer;
1717
import io.vertx.core.internal.ContextInternal;
1818
import io.vertx.core.json.JsonArray;
19+
import io.vertx.oracleclient.OracleConnectOptions;
1920
import io.vertx.oracleclient.OraclePrepareOptions;
2021
import io.vertx.oracleclient.data.Blob;
2122
import io.vertx.oracleclient.impl.Helper;
@@ -40,10 +41,12 @@
4041
public abstract class OracleQueryCommand<C, R> extends OracleCommand<Boolean> {
4142

4243
private final Collector<Row, C, R> collector;
44+
private final OracleConnectOptions connectOptions;
4345

44-
protected OracleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, Collector<Row, C, R> collector) {
46+
protected OracleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, Collector<Row, C, R> collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) {
4547
super(oracleConnection, connectionContext);
4648
this.collector = collector;
49+
this.connectOptions = connectOptions;
4750
}
4851

4952
@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
return 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)