Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,7 +62,9 @@ private <T> T inNewTransaction(Supplier<T> operation, Map<ConnectionProvider, Co
}
throw e;
}
con.commit();
if (!con.getAutoCommit()) {
con.commit();
}
} catch(SQLException e) {
throw new FluentJdbcSqlException("Error executing transaction", e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ class FluentJdbcTransactionTest extends UpdateTestBase {
1 * connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE)
}

def "Empty transaction doesn't throw exception"() {
given:
preparedStatement.executeUpdate() >> 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()
}
Expand Down