diff --git a/jOOQ/src/main/java/org/jooq/conf/Settings.java b/jOOQ/src/main/java/org/jooq/conf/Settings.java index 01569e47ba..d10b5702cc 100644 --- a/jOOQ/src/main/java/org/jooq/conf/Settings.java +++ b/jOOQ/src/main/java/org/jooq/conf/Settings.java @@ -74,6 +74,9 @@ public class Settings protected Boolean updatablePrimaryKeys = false; @XmlElement(defaultValue = "true") protected Boolean reflectionCaching = true; + @XmlElement(defaultValue = "THROW_ALL") + @XmlSchemaType(name = "string") + protected ThrowExceptions throwExceptions = ThrowExceptions.THROW_ALL; @XmlElement(defaultValue = "true") protected Boolean fetchWarnings = true; @XmlElement(defaultValue = "false") @@ -534,6 +537,30 @@ public class Settings this.reflectionCaching = value; } + /** + * A strategy defining how exceptions from the database / JDBC driver should be propagated + * + * @return + * possible object is + * {@link ThrowExceptions } + * + */ + public ThrowExceptions getThrowExceptions() { + return throwExceptions; + } + + /** + * Sets the value of the throwExceptions property. + * + * @param value + * allowed object is + * {@link ThrowExceptions } + * + */ + public void setThrowExceptions(ThrowExceptions value) { + this.throwExceptions = value; + } + /** * Whether warnings should be fetched after each query execution. * @@ -867,6 +894,11 @@ public class Settings return this; } + public Settings withThrowExceptions(ThrowExceptions value) { + setThrowExceptions(value); + return this; + } + public Settings withFetchWarnings(Boolean value) { setFetchWarnings(value); return this; diff --git a/jOOQ/src/main/java/org/jooq/conf/ThrowExceptions.java b/jOOQ/src/main/java/org/jooq/conf/ThrowExceptions.java new file mode 100644 index 0000000000..401ed2d758 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/conf/ThrowExceptions.java @@ -0,0 +1,47 @@ + + + + + + + + +package org.jooq.conf; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + *
Java class for ThrowExceptions. + * + *
The following schema fragment specifies the expected content contained within this class. + *
+ *
+ * <simpleType name="ThrowExceptions">
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ * <enumeration value="THROW_ALL"/>
+ * <enumeration value="THROW_FIRST"/>
+ * <enumeration value="THROW_NONE"/>
+ * </restriction>
+ * </simpleType>
+ *
+ *
+ */
+@XmlType(name = "ThrowExceptions")
+@XmlEnum
+public enum ThrowExceptions {
+
+ THROW_ALL,
+ THROW_FIRST,
+ THROW_NONE;
+
+ public String value() {
+ return name();
+ }
+
+ public static ThrowExceptions fromValue(String v) {
+ return valueOf(v);
+ }
+
+}
diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java
index 4fd17ecaa4..67aa396d87 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java
@@ -202,6 +202,10 @@ final class ResultsImpl extends AbstractListprevious exception's
+ * [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there
+ * are any and append them to the previous exception's
* {@link SQLException#getNextException()} list.
*/
static final void consumeExceptions(Configuration configuration, PreparedStatement stmt, SQLException previous) {
+
+ // [#6413] Don't consume any additional exceptions if we're throwing only the first.
+ ThrowExceptions exceptions = configuration.settings().getThrowExceptions();
+ if (exceptions == THROW_FIRST)
+ return;
+
@@ -3196,6 +3206,7 @@ final class Tools {
boolean anyResults = false;
int i = 0;
int rows = (ctx.resultSet() == null) ? ctx.rows() : 0;
+ SQLException x = null;
for (i = 0; i < maxConsumedResults; i++) {
try {
@@ -3204,11 +3215,11 @@ final class Tools {
Field>[] fields = new MetaDataFieldProvider(ctx.configuration(), ctx.resultSet().getMetaData()).getFields();
Cursor