Permalink
Browse files

RubyJdbcException#begin/#rollback catch exceptions and wrap them in r…

…untime exceptions. Attempt to deal with timed-out connections to MySQL

Signed-off-by: Nick Sieger <nicksieger@gmail.com>
  • Loading branch information...
1 parent d0f8288 commit d27a749bc7f3d55dc110b43ca95a2252dd4fe6e0 Christian Seiler committed with nicksieger Apr 6, 2009
Showing with 18 additions and 10 deletions.
  1. +18 −10 src/java/jdbc_adapter/RubyJdbcConnection.java
View
28 src/java/jdbc_adapter/RubyJdbcConnection.java
@@ -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();
}
@@ -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)

0 comments on commit d27a749

Please sign in to comment.