diff --git a/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/TransferDriver.java b/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/TransferDriver.java index 13abde372dbe27b080ec88f2c2084d09b117c7af..3e5b851175f1827ff110242da37f412c783a7734 100644 --- a/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/TransferDriver.java +++ b/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/TransferDriver.java @@ -70,7 +70,7 @@ public class TransferDriver extends Application { @Override public void start(final Stage primaryStage) throws SQLException { - dbh.connect(Connection.TRANSACTION_SERIALIZABLE); + dbh.connect(Connection.TRANSACTION_SERIALIZABLE, false); primaryStage.setTitle("Account transfer!"); diff --git a/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/sql/DbHandler.java b/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/sql/DbHandler.java index 4807fa16a0bf226578fa5343ae02bf6e758a8753..5111f6c760cb945683a38e8aa27a0b8ae7edaa42 100644 --- a/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/sql/DbHandler.java +++ b/Sda2/P/account/src/main/java/de/hdm_stuttgart/mi/sda2/account/sql/DbHandler.java @@ -15,19 +15,21 @@ public class DbHandler { static private final Logger log = Logger.getLogger(DbHandler.class); Connection conn = null; + boolean autoCommit; PreparedStatement updateAccount; private String getConnectionName() { return Conf.get("DbHandler.user") + '@' + Conf.get("DbHandler.jdbcUrl"); } - public boolean connect(final int isolationLevel) { + public boolean connect(final int isolationLevel, boolean autoCommit) { + this.autoCommit = autoCommit; try { conn = DriverManager.getConnection( Conf.get("DbHandler.jdbcUrl"), Conf.get("DbHandler.user"), Conf.get("DbHandler.password")); - conn.setAutoCommit(false); + conn.setAutoCommit(autoCommit); conn.setTransactionIsolation(isolationLevel); updateAccount = conn.prepareStatement("UPDATE Account SET balance = balance + ? WHERE number = ?"); log.info("Connection '" + getConnectionName() + "' established" ); @@ -57,11 +59,13 @@ public class DbHandler { } public void commit() { - try { - conn.commit(); - log.info("Changes successfully committed"); - } catch (SQLException e) { - ExceptionDialog.showExceptionAndExit("Committing transaction failed: ", e, 1); + if (!autoCommit) { + try { + conn.commit(); + log.info("Changes successfully committed"); + } catch (SQLException e) { + ExceptionDialog.showExceptionAndExit("Committing transaction failed: ", e, 1); + } } }