You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DB.openTransaction() (and Base.openTransaction() ) method sets Connectionauto-commit flag to false.
While this behavior is exactly complies JDBC requirement to begin transaction, there is no way to return auto-commit to true using DB or Base classes.
Also, it worth noticing that Connection is not returned to previous state after commitTransaction/rollbackTransaction operations.
Assuming that Base/DB are the abstractions that are hiding Connection from developer, it becomes non-obvious that something is irreversibly changed inside after commit/rollback.
IMHO, most perfect solution would be remembering and restoring auto-commit flag after commitTransaction/rollbackTransaction.
The definitely must-do is to add setAutoCommit method, something like :
public void setAutoCommit() {
try {
Connection c = ConnectionsAccess.getConnection(name);
if (c == null) {
throw new DBException("Cannot setAutoCommit, connection '" + name + "' not available");
}
c.setAutoCommit(true);
} catch (SQLException ex) {
throw new DBException(ex.getMessage(), ex);
}
}
The text was updated successfully, but these errors were encountered:
ipolevoy
changed the title
openTransaction + commitTransaction changes connection auto-commit flag
Add ability to restore the auto-commit mode after using DB.open/commit/rollbackTransaction
Dec 7, 2022
DB.openTransaction() (and Base.openTransaction() ) method sets Connection
auto-commit
flag tofalse
.While this behavior is exactly complies JDBC requirement to begin transaction, there is no way to return
auto-commit
totrue
usingDB
orBase
classes.Also, it worth noticing that
Connection
is not returned to previous state aftercommitTransaction
/rollbackTransaction
operations.Assuming that
Base
/DB
are the abstractions that are hidingConnection
from developer, it becomes non-obvious that something is irreversibly changed inside after commit/rollback.IMHO, most perfect solution would be remembering and restoring
auto-commit
flag aftercommitTransaction
/rollbackTransaction
.The definitely must-do is to add
setAutoCommit
method, something like :The text was updated successfully, but these errors were encountered: