[jOOQ/jOOQ#18669] Work around Informix JDBC driver

java.lang.IllegalMonitorStateException bug when reading UDT out
parameters
This commit is contained in:
Lukas Eder 2025-06-25 12:38:45 +02:00
parent 9fc42e9123
commit bb14aa72ee
3 changed files with 48 additions and 22 deletions

View File

@ -47,6 +47,7 @@ import static org.jooq.Clause.FIELD_FUNCTION;
// ...
import static org.jooq.SQLDialect.FIREBIRD;
// ...
// ...
import static org.jooq.SQLDialect.POSTGRES;
// ...
// ...
@ -100,6 +101,7 @@ import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.EMPTY_NAME;
import static org.jooq.impl.Tools.configurationOrThrow;
// ...
import static org.jooq.impl.Tools.executeUpdateAndConsumeExceptions;
import static org.jooq.impl.Tools.executeStatementAndGetFirstResultSet;
import static org.jooq.impl.Tools.getRecordQualifier;
import static org.jooq.impl.Tools.toSQLDDLTypeDeclaration;
@ -682,9 +684,10 @@ implements
// [#2925] Jaybird currently doesn't like fetching OUT parameters and consuming ResultSets
// http://tracker.firebirdsql.org/browse/JDBC-350
if (ctx.family() != FIREBIRD)
// [#2925] Jaybird currently doesn't like fetching OUT parameters and consuming ResultSets
// http://tracker.firebirdsql.org/browse/JDBC-350
if (!asList(FIREBIRD).contains(ctx.family()))
Tools.consumeResultSets(ctx, listener, results, e);
listener.outStart(ctx);
@ -715,7 +718,15 @@ implements
private final SQLException execute0(ExecuteContext ctx, ExecuteListener listener) throws SQLException {
listener.executeStart(ctx);
SQLException e = executeStatementAndGetFirstResultSet(ctx, 0);
SQLException e;
e = executeStatementAndGetFirstResultSet(ctx, 0);
listener.executeEnd(ctx);
if (e != null)

View File

@ -4463,6 +4463,9 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
super.register0(ctx);
}

View File

@ -4743,14 +4743,38 @@ final class Tools {
listener.warning(ctx);
}
static final SQLException consumeExceptions(ExecuteContext ctx, ThrowingRunnable<SQLException> runnable) throws SQLException {
try {
runnable.run();
return null;
}
// [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any
catch (SQLException e) {
if (ctx.settings().getThrowExceptions() != THROW_NONE) {
consumeExceptions(ctx.configuration(), ctx.statement(), e);
throw e;
}
else {
return e;
}
}
}
static final SQLException executeUpdateAndConsumeExceptions(ExecuteContext ctx) throws SQLException {
return consumeExceptions(ctx, () -> {
ctx.resultSet(null);
ctx.rows(ctx.statement().executeUpdate());
});
}
/**
* [#5666] Handle the complexity of each dialect's understanding of
* correctly calling {@link PreparedStatement#execute()}}.
*/
static final SQLException executeStatementAndGetFirstResultSet(ExecuteContext ctx, int skipUpdateCounts) throws SQLException {
PreparedStatement stmt = ctx.statement();
try {
return consumeExceptions(ctx, () -> {
PreparedStatement stmt = ctx.statement();
@ -4802,6 +4826,7 @@ final class Tools {
// first ResultSet. Unexpected result sets could be produced as
// well, but it's much harder to skip them.
if (skipUpdateCounts > 0) {
int skipUpdateCounts0 = skipUpdateCounts;
fetchLoop:
for (int i = 0; i < maxConsumedResults; i++) {
@ -4825,7 +4850,7 @@ final class Tools {
ctx.rows(updateCount);
}
if (updateCount == -1 || skipUpdateCounts-- == 0)
if (updateCount == -1 || skipUpdateCounts0-- == 0)
break fetchLoop;
}
}
@ -4841,20 +4866,7 @@ final class Tools {
ctx.resultSet(null);
ctx.rows(stmt.getUpdateCount());
}
return null;
}
// [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any
catch (SQLException e) {
if (ctx.settings().getThrowExceptions() != THROW_NONE) {
consumeExceptions(ctx.configuration(), ctx.statement(), e);
throw e;
}
else {
return e;
}
}
});
}