diff --git a/jOOQ/src/main/java/org/jooq/ResultOrRows.java b/jOOQ/src/main/java/org/jooq/ResultOrRows.java
index a1905ff3aa..050999f1ee 100644
--- a/jOOQ/src/main/java/org/jooq/ResultOrRows.java
+++ b/jOOQ/src/main/java/org/jooq/ResultOrRows.java
@@ -36,8 +36,13 @@ package org.jooq;
import java.sql.Statement;
+import org.jooq.conf.Settings;
+import org.jooq.conf.ThrowExceptions;
+import org.jooq.exception.DataAccessException;
+
/**
- * A type that contains either a {@link Result} or an update count.
+ * A type that contains either a {@link Result}, an update count, or an
+ * exception.
*
* @author Lukas Eder
*/
@@ -57,4 +62,15 @@ public interface ResultOrRows {
* @see Statement#getUpdateCount()
*/
int rows();
+
+ /**
+ * The exception if applicable or null if there was no
+ * exception.
+ *
+ * Exceptions are made available through this API only if + * {@link Settings#getThrowExceptions()} is set to + * {@link ThrowExceptions#THROW_NONE}. In all other cases, a batch execution + * is aborted and exceptions are thrown as ordinary Java exceptions. + */ + DataAccessException exception(); } diff --git a/jOOQ/src/main/java/org/jooq/Results.java b/jOOQ/src/main/java/org/jooq/Results.java index 11f34c6141..c98b2132b8 100644 --- a/jOOQ/src/main/java/org/jooq/Results.java +++ b/jOOQ/src/main/java/org/jooq/Results.java @@ -34,17 +34,54 @@ */ package org.jooq; +import java.sql.SQLException; import java.util.List; +import org.jooq.conf.Settings; +import org.jooq.conf.ThrowExceptions; + /** * A list of {@link Result} and update counts that can be returned by * {@link ResultQuery#fetchMany()} calls and other calls that produce multiple * cursors and update counts. *
* For backwards-compatibility (e.g. with {@link ResultQuery#fetchMany()}), this - * type extends {@link List} containing only the {@link Result}, not the rows / - * update counts of interleaved updates. In order to get both, call - * {@link #resultsOrRows()}. + * type extends {@link List} containing only the {@link Result}, not the rows, + * update counts, exceptions of interleaved updates. In order to get them all, + * call {@link #resultsOrRows()} upon the results. + *
+ *
+ * Some databases support raising several errors or exceptions per statement + * batch (e.g. {@link SQLDialect#SQLSERVER}): + *
+ *
+ *
+ * INSERT INTO t VALUES (1),(2),(3);
+ * RAISERROR('message 1', 16, 2, 3);
+ * RAISERROR('message 2', 16, 2, 3);
+ * SELECT * FROM t;
+ * RAISERROR('message 3', 16, 2, 3);
+ *
+ * The above batch will produce: + *
+ * By default (or when explicitly specifying {@link ThrowExceptions#THROW_ALL}
+ * in {@link Settings#getThrowExceptions()}), this particular batch will produce
+ * a single exception corresponding to "message 1", with additional
+ * exceptions for "message 2" and "message 3" attached
+ * to {@link SQLException#getNextException()}, recursively.
+ *
+ * When specifying {@link ThrowExceptions#THROW_FIRST}, only
+ * "message 1" is propagated. When specifying
+ * {@link ThrowExceptions#THROW_NONE}, then all exceptions are collected as
+ * results and are made available through {@link #resultsOrRows()} in
+ * {@link ResultOrRows#exception()}.
*
* @author Lukas Eder
*/
diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java
index 7207648818..4fd17ecaa4 100644
--- a/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java
+++ b/jOOQ/src/main/java/org/jooq/impl/ResultsImpl.java
@@ -43,6 +43,7 @@ import org.jooq.Record;
import org.jooq.Result;
import org.jooq.ResultOrRows;
import org.jooq.Results;
+import org.jooq.exception.DataAccessException;
/**
* @author Lukas Eder
@@ -189,20 +190,22 @@ final class ResultsImpl extends AbstractList