diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/FetchDirection.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/FetchDirection.java new file mode 100644 index 000000000..f2fc0c14d --- /dev/null +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/FetchDirection.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package io.vertx.oracleclient; + +import java.sql.ResultSet; + +/** + * Represents the fetch direction hint + */ +public enum FetchDirection { + + FORWARD(ResultSet.FETCH_FORWARD), + REVERSE(ResultSet.FETCH_REVERSE), + UNKNOWN(ResultSet.FETCH_UNKNOWN); + + private final int type; + + FetchDirection(int type) { + this.type = type; + } + + public int getType() { + return type; + } +} diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/OracleConnectOptions.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/OracleConnectOptions.java index df223ce4b..ebb161c9b 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/OracleConnectOptions.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/OracleConnectOptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2022 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -50,6 +50,12 @@ public static OracleConnectOptions wrap(SqlConnectOptions options) { private String tnsAlias; private String tnsAdmin; + private int queryTimeout; + private int maxRows; + private FetchDirection fetchDirection; + private int fetchSize; + + public OracleConnectOptions() { super(); } @@ -66,6 +72,10 @@ private void copyFields(OracleConnectOptions other) { this.instanceName = other.instanceName; this.tnsAlias = other.tnsAlias; this.tnsAdmin = other.tnsAdmin; + this.queryTimeout = other.queryTimeout; + this.maxRows = other.maxRows; + this.fetchDirection = other.fetchDirection; + this.fetchSize = other.fetchSize; } public OracleConnectOptions(SqlConnectOptions options) { @@ -205,6 +215,54 @@ public OracleConnectOptions setTnsAdmin(String tnsAdmin) { return this; } + public int getQueryTimeout() { + return queryTimeout; + } + + /** + * @see java.sql.PreparedStatement#setQueryTimeout(int) + */ + public OracleConnectOptions setQueryTimeout(int queryTimeout) { + this.queryTimeout = queryTimeout; + return this; + } + + public int getMaxRows() { + return maxRows; + } + + /** + * @see java.sql.PreparedStatement#setMaxRows(int) + */ + public OracleConnectOptions setMaxRows(int maxRows) { + this.maxRows = maxRows; + return this; + } + + public FetchDirection getFetchDirection() { + return fetchDirection; + } + + /** + * @see java.sql.PreparedStatement#setFetchDirection(int) + */ + public OracleConnectOptions setFetchDirection(FetchDirection fetchDirection) { + this.fetchDirection = fetchDirection; + return this; + } + + public int getFetchSize() { + return fetchSize; + } + + /** + * @see java.sql.PreparedStatement#setFetchSize(int) + */ + public OracleConnectOptions setFetchSize(int fetchSize) { + this.fetchSize = fetchSize; + return this; + } + // Non-specific options @Override diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/OracleJdbcConnection.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/OracleJdbcConnection.java index f55d0928e..36edd9c21 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/OracleJdbcConnection.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/OracleJdbcConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -219,9 +219,9 @@ private void checkPending() { private OracleCommand wrap(CommandBase cmd) { OracleCommand action; if (cmd instanceof SimpleQueryCommand) { - action = OracleSimpleQueryCommand.create(connection, context, (SimpleQueryCommand) cmd); + action = OracleSimpleQueryCommand.create(connection, context, (SimpleQueryCommand) cmd, options); } else if (cmd instanceof PrepareStatementCommand) { - action = new OraclePrepareStatementCommand(connection, context, (PrepareStatementCommand) cmd); + action = new OraclePrepareStatementCommand(connection, context, (PrepareStatementCommand) cmd, options); } else if (cmd instanceof ExtendedQueryCommand) { action = forExtendedQuery((ExtendedQueryCommand) cmd); } else if (cmd instanceof TxCommand) { @@ -249,12 +249,12 @@ private OracleCommand forExtendedQuery(ExtendedQueryCommand cmd) { if (rowReader != null) { action = OracleCursorFetchCommand.create(connection, context, cmd, rowReader); } else { - action = OracleCursorQueryCommand.create(connection, context, cmd, cmd.collector(), rr -> cursors.put(cursorId, rr)); + action = OracleCursorQueryCommand.create(connection, context, cmd, cmd.collector(), rr -> cursors.put(cursorId, rr), options); } } else if (cmd.isBatch()) { - action = new OraclePreparedBatchQuery(connection, context, cmd, cmd.collector()); + action = new OraclePreparedBatchQueryCommand(connection, context, cmd, cmd.collector(), options); } else { - action = new OraclePreparedQueryCommand(connection, context, cmd, cmd.collector()); + action = new OraclePreparedQueryCommand(connection, context, cmd, cmd.collector(), options); } return action; } diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCommand.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCommand.java index d129cdff9..08921bfad 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCommand.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -13,11 +13,14 @@ import io.vertx.core.Future; import io.vertx.core.Promise; import io.vertx.core.impl.ContextInternal; +import io.vertx.oracleclient.OracleConnectOptions; import io.vertx.oracleclient.impl.Helper.SQLBlockingCodeHandler; import io.vertx.sqlclient.impl.command.CommandBase; import io.vertx.sqlclient.impl.command.CommandResponse; import oracle.jdbc.OracleConnection; +import java.sql.SQLException; +import java.sql.Statement; import java.util.concurrent.Flow; import static io.vertx.oracleclient.impl.FailureUtil.sanitize; @@ -89,4 +92,21 @@ public void onComplete() { public final void fireResponse() { response.fire(); } + + protected void applyStatementOptions(Statement stmt, OracleConnectOptions connectOptions) throws SQLException { + if (connectOptions != null) { + if (connectOptions.getQueryTimeout() > 0) { + stmt.setQueryTimeout(connectOptions.getQueryTimeout()); + } + if (connectOptions.getMaxRows() > 0) { + stmt.setMaxRows(connectOptions.getMaxRows()); + } + if (connectOptions.getFetchDirection() != null) { + stmt.setFetchDirection(connectOptions.getFetchDirection().getType()); + } + if (connectOptions.getFetchSize() > 0) { + stmt.setFetchSize(connectOptions.getFetchSize()); + } + } + } } diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCursorQueryCommand.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCursorQueryCommand.java index a40a9905d..1ef64642f 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCursorQueryCommand.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleCursorQueryCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -38,8 +38,8 @@ public class OracleCursorQueryCommand extends OracleQueryCommand { private final Collector collector; private final QueryResultHandler resultHandler; - private OracleCursorQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector, Consumer> store) { - super(oracleConnection, connectionContext, collector); + private OracleCursorQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector, Consumer> store, io.vertx.oracleclient.OracleConnectOptions connectOptions) { + super(oracleConnection, connectionContext, collector, connectOptions); sql = cmd.sql(); fetch = cmd.fetch(); params = cmd.params(); @@ -49,8 +49,8 @@ private OracleCursorQueryCommand(OracleConnection oracleConnection, ContextInter this.store = store; } - public static OracleCursorQueryCommand create(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector, Consumer> store) { - return new OracleCursorQueryCommand<>(oracleConnection, connectionContext, cmd, collector, store); + public static OracleCursorQueryCommand create(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector, Consumer> store, io.vertx.oracleclient.OracleConnectOptions connectOptions) { + return new OracleCursorQueryCommand<>(oracleConnection, connectionContext, cmd, collector, store, connectOptions); } @Override diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePrepareStatementCommand.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePrepareStatementCommand.java index 432df4c2f..b26a7fabd 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePrepareStatementCommand.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePrepareStatementCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -13,6 +13,7 @@ import io.vertx.core.Future; import io.vertx.core.impl.ContextInternal; import io.vertx.core.json.JsonArray; +import io.vertx.oracleclient.OracleConnectOptions; import io.vertx.oracleclient.OraclePrepareOptions; import io.vertx.sqlclient.impl.PreparedStatement; import io.vertx.sqlclient.impl.command.PrepareStatementCommand; @@ -25,11 +26,13 @@ public class OraclePrepareStatementCommand extends OracleCommand prepareWithAutoGeneratedIndexes() { keys[i] = indexes.getInteger(i); } try (java.sql.PreparedStatement statement = oracleConnection.prepareStatement(sql, keys)) { + applyStatementOptions(statement, connectOptions); return new OraclePreparedStatement(sql, statement); } } @@ -65,6 +69,7 @@ private Future prepareWithAutoGeneratedIndexes() { keys[i] = indexes.getString(i); } try (java.sql.PreparedStatement statement = oracleConnection.prepareStatement(sql, keys)) { + applyStatementOptions(statement, connectOptions); return new OraclePreparedStatement(sql, statement); } } diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQuery.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQueryCommand.java similarity index 88% rename from vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQuery.java rename to vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQueryCommand.java index ae574481b..fb8dca7a1 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQuery.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedBatchQueryCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -33,14 +33,14 @@ import static io.vertx.oracleclient.impl.FailureUtil.sanitize; -public class OraclePreparedBatchQuery extends OracleQueryCommand { +public class OraclePreparedBatchQueryCommand extends OracleQueryCommand { private final String sql; private final List listParams; private final QueryResultHandler resultHandler; - public OraclePreparedBatchQuery(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector) { - super(oracleConnection, connectionContext, collector); + public OraclePreparedBatchQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) { + super(oracleConnection, connectionContext, collector, connectOptions); sql = cmd.sql(); listParams = cmd.paramsList(); resultHandler = cmd.resultHandler(); diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedQueryCommand.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedQueryCommand.java index 4428a5d7e..7ee5e9a35 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedQueryCommand.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OraclePreparedQueryCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -33,8 +33,8 @@ public class OraclePreparedQueryCommand extends OracleQueryCommand { private final PrepareOptions prepareOptions; private final QueryResultHandler resultHandler; - public OraclePreparedQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector) { - super(oracleConnection, connectionContext, collector); + public OraclePreparedQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, ExtendedQueryCommand cmd, Collector collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) { + super(oracleConnection, connectionContext, collector, connectOptions); sql = cmd.sql(); params = cmd.params(); prepareOptions = cmd.options(); diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleQueryCommand.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleQueryCommand.java index 8c0a5ab15..7504f7e59 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleQueryCommand.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleQueryCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -15,6 +15,7 @@ import io.vertx.core.buffer.Buffer; import io.vertx.core.impl.ContextInternal; import io.vertx.core.json.JsonArray; +import io.vertx.oracleclient.OracleConnectOptions; import io.vertx.oracleclient.OraclePrepareOptions; import io.vertx.oracleclient.data.Blob; import io.vertx.oracleclient.impl.Helper; @@ -39,10 +40,12 @@ public abstract class OracleQueryCommand extends OracleCommand { private final Collector collector; + private final OracleConnectOptions connectOptions; - protected OracleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, Collector collector) { + protected OracleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, Collector collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) { super(oracleConnection, connectionContext); this.collector = collector; + this.connectOptions = connectOptions; } @Override @@ -126,6 +129,7 @@ private Future prepare(Connection conn, OraclePrepareOp ps = conn.prepareStatement(query()); } + applyStatementOptions(ps, connectOptions); fillStatement(ps, conn); prom.complete(ps.unwrap(OraclePreparedStatement.class)); diff --git a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleSimpleQueryCommand.java b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleSimpleQueryCommand.java index 9e5939bec..b5d364fa6 100644 --- a/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleSimpleQueryCommand.java +++ b/vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/commands/OracleSimpleQueryCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2023 Contributors to the Eclipse Foundation + * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -29,14 +29,14 @@ public class OracleSimpleQueryCommand extends OracleQueryCommand { private final String sql; private final QueryResultHandler resultHandler; - private OracleSimpleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand cmd, Collector collector) { - super(oracleConnection, connectionContext, collector); + private OracleSimpleQueryCommand(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand cmd, Collector collector, io.vertx.oracleclient.OracleConnectOptions connectOptions) { + super(oracleConnection, connectionContext, collector, connectOptions); sql = cmd.sql(); resultHandler = cmd.resultHandler(); } - public static OracleSimpleQueryCommand create(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand cmd) { - return new OracleSimpleQueryCommand<>(oracleConnection, connectionContext, cmd, cmd.collector()); + public static OracleSimpleQueryCommand create(OracleConnection oracleConnection, ContextInternal connectionContext, SimpleQueryCommand cmd, io.vertx.oracleclient.OracleConnectOptions connectOptions) { + return new OracleSimpleQueryCommand<>(oracleConnection, connectionContext, cmd, cmd.collector(), connectOptions); } @Override