[#6580] Add Settings.fetchServerOutputSize to fetch server output
This commit is contained in:
parent
47e97c840d
commit
e3a923d3e3
@ -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.
|
||||
* <p>
|
||||
@ -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;
|
||||
|
||||
@ -264,4 +264,16 @@ public final class SettingsTools {
|
||||
? settings.getFetchSize()
|
||||
: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>fetchServerOutputSize</code> if it is not <code>0</code>, 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
157
jOOQ/src/main/java/org/jooq/impl/FetchServerOutputListener.java
Normal file
157
jOOQ/src/main/java/org/jooq/impl/FetchServerOutputListener.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
@ -127,6 +127,10 @@ UpdatableRecord.store() and UpdatableRecord.update().]]></jxb:javadoc></jxb:prop
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether warnings should be fetched after each query execution.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="fetchServerOutputSize" type="int" minOccurs="0" maxOccurs="1" default="0">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether server output should be fetched after each query execution.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="returnAllOnUpdatableRecord" type="boolean" minOccurs="0" maxOccurs="1" default="false">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether calls to store(), insert() and update() should return all columns, not just identity columns.
|
||||
<p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user