From e3a923d3e375ea009d207aebe00ccad78fb32ecc Mon Sep 17 00:00:00 2001 From: lukaseder Date: Fri, 15 Dec 2017 14:51:10 +0100 Subject: [PATCH] [#6580] Add Settings.fetchServerOutputSize to fetch server output --- .../src/main/java/org/jooq/conf/Settings.java | 31 ++++ .../java/org/jooq/conf/SettingsTools.java | 12 ++ .../java/org/jooq/impl/ExecuteListeners.java | 5 + .../jooq/impl/FetchServerOutputListener.java | 157 ++++++++++++++++++ .../resources/xsd/jooq-runtime-3.11.0.xsd | 4 + 5 files changed, 209 insertions(+) create mode 100644 jOOQ/src/main/java/org/jooq/impl/FetchServerOutputListener.java diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index de5c314d62..1eabad0380 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -82,6 +82,8 @@ public class Settings protected ThrowExceptions throwExceptions = ThrowExceptions.THROW_ALL; @XmlElement(defaultValue = "true") protected Boolean fetchWarnings = true; + @XmlElement(defaultValue = "0") + protected Integer fetchServerOutputSize = 0; @XmlElement(defaultValue = "false") protected Boolean returnAllOnUpdatableRecord = false; @XmlElement(defaultValue = "true") @@ -644,6 +646,30 @@ public class Settings this.fetchWarnings = value; } + /** + * Whether server output should be fetched after each query execution. + * + * @return + * possible object is + * {@link Integer } + * + */ + public Integer getFetchServerOutputSize() { + return fetchServerOutputSize; + } + + /** + * Sets the value of the fetchServerOutputSize property. + * + * @param value + * allowed object is + * {@link Integer } + * + */ + public void setFetchServerOutputSize(Integer value) { + this.fetchServerOutputSize = value; + } + /** * Whether calls to store(), insert() and update() should return all columns, not just identity columns. *

@@ -1045,6 +1071,11 @@ public class Settings return this; } + public Settings withFetchServerOutputSize(Integer value) { + setFetchServerOutputSize(value); + return this; + } + public Settings withReturnAllOnUpdatableRecord(Boolean value) { setReturnAllOnUpdatableRecord(value); return this; diff --git a/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java b/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java index c0baf45ab7..b35149eb33 100644 --- a/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java +++ b/jOOQ/src/main/java/org/jooq/conf/SettingsTools.java @@ -264,4 +264,16 @@ public final class SettingsTools { ? settings.getFetchSize() : 0; } + + /** + * Return fetchServerOutputSize if it is not 0, or + * the specified {@link Settings#getFetchServerOutputSize()}. + */ + public static final int getFetchServerOutputSize(int fetchServerOutputSize, Settings settings) { + return fetchServerOutputSize != 0 + ? fetchServerOutputSize + : settings.getFetchServerOutputSize() != null + ? settings.getFetchServerOutputSize() + : 0; + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/ExecuteListeners.java b/jOOQ/src/main/java/org/jooq/impl/ExecuteListeners.java index 65fd599583..41229ca412 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ExecuteListeners.java +++ b/jOOQ/src/main/java/org/jooq/impl/ExecuteListeners.java @@ -47,6 +47,7 @@ import org.jooq.ExecuteContext; import org.jooq.ExecuteListener; import org.jooq.ExecuteListenerProvider; import org.jooq.conf.Settings; +import org.jooq.conf.SettingsTools; import org.jooq.tools.JooqLogger; import org.jooq.tools.LoggerListener; @@ -103,6 +104,10 @@ final class ExecuteListeners implements ExecuteListener { (result = init(result)).add(new LoggerListener()); } + // [#6580] Fetching server output may require some pre / post actions around the actual statement + if (SettingsTools.getFetchServerOutputSize(0, ctx.settings()) > 0) + (result = init(result)).add(new FetchServerOutputListener()); + return result == null ? null : result.toArray(EMPTY_EXECUTE_LISTENER); } diff --git a/jOOQ/src/main/java/org/jooq/impl/FetchServerOutputListener.java b/jOOQ/src/main/java/org/jooq/impl/FetchServerOutputListener.java new file mode 100644 index 0000000000..1de1e029d7 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/FetchServerOutputListener.java @@ -0,0 +1,157 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.Tools.EMPTY_STRING; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.List; + +import org.jooq.ExecuteContext; +import org.jooq.ExecuteListener; +import org.jooq.conf.SettingsTools; +import org.jooq.exception.DataAccessException; +import org.jooq.tools.JooqLogger; +import org.jooq.tools.jdbc.JDBCUtils; + +/** + * An {@link ExecuteListener} that runs pre / post statements required to fetch + * server output, including the actual fetching of server output. + * + * @author Lukas Eder + */ +final class FetchServerOutputListener extends DefaultExecuteListener { + + /** + * Generated UID + */ + private static final long serialVersionUID = 2256982126025931878L; + private static final JooqLogger log = JooqLogger.getLogger(FetchServerOutputListener.class); + + @Override + public final void executeStart(ExecuteContext ctx) { + super.executeStart(ctx); + + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + default: + break; + } + } + + @Override + public final void executeEnd(ExecuteContext ctx) { + switch (ctx.family()) { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + default: + break; + } + + super.executeEnd(ctx); + } +} diff --git a/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd b/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd index 20cbdc26e8..8dd27eb069 100644 --- a/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd +++ b/jOOQ/src/main/resources/xsd/jooq-runtime-3.11.0.xsd @@ -127,6 +127,10 @@ UpdatableRecord.store() and UpdatableRecord.update().]]> + + + +