Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to restore the auto-commit mode after using DB.open/commit/rollbackTransaction #1252

Closed
eugeneRover opened this issue Dec 7, 2022 · 0 comments

Comments

@eugeneRover
Copy link

DB.openTransaction() (and Base.openTransaction() ) method sets Connection auto-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);
    }
}
@ipolevoy 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
@ipolevoy ipolevoy self-assigned this Dec 7, 2022
ipolevoy added a commit that referenced this issue Dec 8, 2022
@ipolevoy ipolevoy closed this as completed Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants