Skip to content

Commit

Permalink
RubyJdbcException#begin/#rollback catch exceptions and wrap them in r…
Browse files Browse the repository at this point in the history
…untime exceptions. Attempt to deal with timed-out connections to MySQL

Signed-off-by: Nick Sieger <nicksieger@gmail.com>
  • Loading branch information
Christian Seiler authored and nicksieger committed May 6, 2009
1 parent d0f8288 commit d27a749
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/java/jdbc_adapter/RubyJdbcConnection.java
Expand Up @@ -103,7 +103,11 @@ protected static RubyModule getConnectionAdapters(Ruby runtime) {

@JRubyMethod(name = "begin")
public IRubyObject begin(ThreadContext context) throws SQLException {
getConnection(true).setAutoCommit(false);
try {
getConnection(true).setAutoCommit(false);
} catch (Exception e) {
throw wrap(context, e);
}

return context.getRuntime().getNil();
}
Expand Down Expand Up @@ -421,17 +425,21 @@ public IRubyObject reconnect() {

@JRubyMethod(name = "rollback")
public IRubyObject rollback(ThreadContext context) throws SQLException {
Connection connection = getConnection(true);

if (!connection.getAutoCommit()) {
try {
connection.rollback();
} finally {
connection.setAutoCommit(true);
try {
Connection connection = getConnection(true);

if (!connection.getAutoCommit()) {
try {
connection.rollback();
} finally {
connection.setAutoCommit(true);
}
}

return context.getRuntime().getNil();
} catch (Exception e) {
throw wrap(context, e);
}

return context.getRuntime().getNil();
}

@JRubyMethod(name = "select?", required = 1, meta = true, frame = false)
Expand Down

0 comments on commit d27a749

Please sign in to comment.