[jOOQ/jOOQ#8877] fetchSingle() failure does not trigger ExecuteListener#exception() event

This commit is contained in:
Lukas Eder 2019-07-02 14:19:57 +02:00
parent 06b3e0aecd
commit 45d22cfbed
2 changed files with 13 additions and 5 deletions

View File

@ -99,8 +99,8 @@ final class CursorImpl<R extends Record> extends AbstractCursor<R> implements Cu
private static final JooqLogger log = JooqLogger.getLogger(CursorImpl.class);
private final ExecuteContext ctx;
private final ExecuteListener listener;
final ExecuteContext ctx;
final ExecuteListener listener;
private final boolean[] intern;
private final boolean keepResultSet;
private final boolean keepStatement;

View File

@ -2058,7 +2058,7 @@ final class Tools {
else if (size == 1)
return result.get(0);
else
throw new TooManyRowsException("Cursor returned more than one result");
throw exception((CursorImpl<R>) cursor, new TooManyRowsException("Cursor returned more than one result"));
}
finally {
cursor.close();
@ -2106,17 +2106,25 @@ final class Tools {
int size = result.size();
if (size == 0)
throw new NoDataFoundException("Cursor returned no rows");
throw exception((CursorImpl<R>) cursor, new NoDataFoundException("Cursor returned no rows"));
else if (size == 1)
return result.get(0);
else
throw new TooManyRowsException("Cursor returned more than one result");
throw exception((CursorImpl<R>) cursor, new TooManyRowsException("Cursor returned more than one result"));
}
finally {
cursor.close();
}
}
private static final RuntimeException exception(CursorImpl<?> cursor, RuntimeException e) {
// [#8877] Make sure these exceptions pass through ExecuteListeners as well
cursor.ctx.exception(e);
cursor.listener.exception(cursor.ctx);
return cursor.ctx.exception();
}
/**
* Visit each query part from a collection, given a context.
*/