diff --git a/jOOQ/src/main/java/org/jooq/tools/jdbc/MockFileDatabase.java b/jOOQ/src/main/java/org/jooq/tools/jdbc/MockFileDatabase.java index 8b3abd76f6..3202d23f2f 100644 --- a/jOOQ/src/main/java/org/jooq/tools/jdbc/MockFileDatabase.java +++ b/jOOQ/src/main/java/org/jooq/tools/jdbc/MockFileDatabase.java @@ -300,13 +300,19 @@ public class MockFileDatabase implements MockDataProvider { private MockResult parse(String rowString) { int rows = 0; + SQLException exception = null; + if (rowString.startsWith("@ rows:")) rows = Integer.parseInt(rowString.substring(7).trim()); + if (rowString.startsWith("@ exception:")) + exception = new SQLException(rowString.substring(12).trim()); String resultText = currentResult.toString(); String trimmed = resultText.trim(); MockResult result = - resultText.isEmpty() + exception != null + ? new MockResult(exception) + : resultText.isEmpty() ? new MockResult(rows) : trimmed.startsWith("<") ? new MockResult(rows, create.fetchFromXML(resultText)) diff --git a/jOOQ/src/main/java/org/jooq/tools/jdbc/MockResult.java b/jOOQ/src/main/java/org/jooq/tools/jdbc/MockResult.java index 3dd0bbc650..e786bcd1f2 100644 --- a/jOOQ/src/main/java/org/jooq/tools/jdbc/MockResult.java +++ b/jOOQ/src/main/java/org/jooq/tools/jdbc/MockResult.java @@ -37,6 +37,7 @@ */ package org.jooq.tools.jdbc; +import java.sql.SQLException; import java.sql.Statement; import org.jooq.DSLContext; @@ -72,7 +73,7 @@ public class MockResult { *
  • -1: the row count is not applicable
  • * */ - public final int rows; + public final int rows; /** * The result data associated with this execution result. @@ -88,7 +89,14 @@ public class MockResult { * Note, that this can also be used to provide a result for * {@link Statement#getGeneratedKeys()} */ - public final Result data; + public final Result data; + + /** + * The exception associated with this execution result. + *

    + * If present, the current result produces an exception. + */ + public final SQLException exception; /** * Create a new MockResult. @@ -144,10 +152,21 @@ public class MockResult { public MockResult(int rows, Result data) { this.rows = rows; this.data = data; + this.exception = null; + } + + public MockResult(SQLException exception) { + this.rows = -1; + this.data = null; + this.exception = exception; } @Override public String toString() { - return (data != null) ? data.toString() : ("" + rows); + return (exception != null) + ? "Exception : " + exception.getMessage() + : (data != null) + ? data.toString() + : ("" + rows); } } diff --git a/jOOQ/src/main/java/org/jooq/tools/jdbc/MockStatement.java b/jOOQ/src/main/java/org/jooq/tools/jdbc/MockStatement.java index b64ab8f15b..97ff60197f 100644 --- a/jOOQ/src/main/java/org/jooq/tools/jdbc/MockStatement.java +++ b/jOOQ/src/main/java/org/jooq/tools/jdbc/MockStatement.java @@ -151,6 +151,13 @@ public class MockStatement extends JDBC41Statement implements CallableStatement throw new SQLException("Connection is already closed"); } + private boolean checkException() throws SQLException { + if (result[resultIndex].exception != null) + throw result[resultIndex].exception; + else + return true; + } + @Override public Connection getConnection() throws SQLException { return connection; @@ -184,6 +191,7 @@ public class MockStatement extends JDBC41Statement implements CallableStatement result = data.execute(context); return result != null && result.length > 0 + && checkException() && result[resultIndex].data != null // [#8113] The first result may be the generated keys @@ -213,7 +221,7 @@ public class MockStatement extends JDBC41Statement implements CallableStatement @Override public boolean getMoreResults(int current) throws SQLException { - return (result != null && ++resultIndex < result.length); + return (result != null && ++resultIndex < result.length) && checkException(); } @Override