From d4c4f1c62aa858d3dc716f5ae1c6f3bbb0312efe Mon Sep 17 00:00:00 2001 From: Yehor Lashkul Date: Sat, 12 Dec 2020 10:49:51 +0200 Subject: [PATCH] Don't throw exception if transaction is empty --- .../internal/query/TransactionInternal.java | 5 +++-- .../query/FluentJdbcTransactionTest.groovy | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/internal/query/TransactionInternal.java b/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/internal/query/TransactionInternal.java index 3d12cfc..1377598 100644 --- a/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/internal/query/TransactionInternal.java +++ b/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/internal/query/TransactionInternal.java @@ -1,6 +1,5 @@ package org.codejargon.fluentjdbc.internal.query; -import org.codejargon.fluentjdbc.api.FluentJdbcException; import org.codejargon.fluentjdbc.api.FluentJdbcSqlException; import org.codejargon.fluentjdbc.api.integration.ConnectionProvider; import org.codejargon.fluentjdbc.api.query.Transaction; @@ -63,7 +62,9 @@ private T inNewTransaction(Supplier operation, Map> expectedUpdatedRows.intValue() + when: + query.transaction().in( + { -> + // no queries + } + ) + then: + // checking original state, then check before commit + connection.getAutoCommit() >> true >> true + + _ * connection.getAutoCommit() + 0 * connection.setAutoCommit(false) + 0 * preparedStatement.close() + 0 * connection.rollback() + 0 * connection.commit() + 1 * connection.setAutoCommit(true) + } + def throwException() { throw new MyRuntimeException() }