diff --git a/.gitignore b/.gitignore index 4826670..c1e802c 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,6 @@ fabric.properties ### Intellij Patch ### *.iml + +# Ignore postgresql database files +*.db \ No newline at end of file diff --git a/src/org/activeorm/database/Database.java b/src/org/activeorm/database/Database.java index 2ce17fe..afd3e93 100644 --- a/src/org/activeorm/database/Database.java +++ b/src/org/activeorm/database/Database.java @@ -121,23 +121,20 @@ protected Database(final DatabaseConfiguration configuration, final SQLProducer * set the transaction mode to explicit, requiring all transactions to * be manually committed. * - * @throws java.lang.IllegalStateException if the result from - * {@link Database#connect()} returned null. + * @throws java.lang.IllegalStateException if the result from {@link Database#connect()} returned null. */ private Connection setupConnection() { final Connection connection = connect(); - if(connection == null) { + if (connection == null) { // not sure if this is the appropriate way to handle the // case where Database#connect returns null. throw new IllegalStateException("Creation of database connection failed"); } - try { connection.setAutoCommit(false); } catch (final SQLException e) { e.printStackTrace(); } - return connection; } @@ -292,6 +289,7 @@ public synchronized int execute(final String sql, final Object[] parameters) { try { final int result = statement.executeUpdate(); statement.close(); + connection.commit(); return result; } catch (SQLException e) { e.printStackTrace(); @@ -320,12 +318,9 @@ public synchronized int execute(final String sql, final Object[] parameters, fin if (keys.next()) { primaryKey.setValue(keys.getInt(1)); } - - // be sure to unlock database tables keys.close(); statement.close(); connection.commit(); - return result; } catch (SQLException e) { e.printStackTrace(); @@ -339,8 +334,7 @@ public synchronized int execute(final String sql, final Object[] parameters, fin * Prepares a {@link PreparedStatement} with parameters. * * @param sql the prepared statement sql. - * @param parameters the parameters to prepare into the {@link - * PreparedStatement}. + * @param parameters the parameters to prepare into the {@link PreparedStatement}. * @param generateKeys if true then statement will return keys. * @return a {@link PreparedStatement}. */