Skip to content

Commit

Permalink
Added H2 Database support and finished merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Francismb committed May 7, 2016
1 parent 867659e commit 0f03481
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ fabric.properties

### Intellij Patch ###
*.iml

# Ignore postgresql database files
*.db
14 changes: 4 additions & 10 deletions src/org/activeorm/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>null</code>.
* @throws java.lang.IllegalStateException if the result from {@link Database#connect()} returned <code>null</code>.
*/
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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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}.
*/
Expand Down

0 comments on commit 0f03481

Please sign in to comment.