Skip to content
This repository
Browse code

Don't assume ActiveRecord implies ActiveRecord-JDBC (TORQUE-781)

commit 4b61e69034a7dac68af2f949916935645f0bd7f3 1 parent 1a7f110
Ben Browning authored April 20, 2012
39  gems/transactions/lib/torquebox/active_record_adapters.rb
@@ -15,7 +15,12 @@
15 15
 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16 16
 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17 17
 
18  
-require 'arjdbc'
  18
+begin
  19
+  require 'arjdbc'
  20
+  TORQUEBOX_XA_JDBC = true
  21
+rescue LoadError
  22
+  TORQUEBOX_XA_JDBC = false
  23
+end
19 24
 require 'set'
20 25
 
21 26
 module TorqueBox
@@ -27,15 +32,17 @@ module ActiveRecordAdapters
27 32
 
28 33
       module Connection
29 34
 
30  
-        def transaction(*)
31  
-          super
32  
-        rescue ActiveRecord::JDBCError => e
33  
-          unless self.is_a?(XAResource)
34  
-            puts "Creating an XAResource; exception=#{e}"
35  
-            self.extend(XAResource)
36  
-            retry
37  
-          else
38  
-            raise
  35
+        if TORQUEBOX_XA_JDBC
  36
+          def transaction(*)
  37
+            super
  38
+          rescue ActiveRecord::JDBCError => e
  39
+            unless self.is_a?(XAResource)
  40
+              puts "Creating an XAResource; exception=#{e}"
  41
+              self.extend(XAResource)
  42
+              retry
  43
+            else
  44
+              raise
  45
+            end
39 46
           end
40 47
         end
41 48
 
@@ -114,14 +121,16 @@ def connections
114 121
   end
115 122
 end
116 123
 
117  
-module ActiveRecord
118  
-  module ConnectionAdapters
119  
-    class JdbcAdapter 
120  
-      include TorqueBox::Transactions::ActiveRecordAdapters::Connection
  124
+if TORQUEBOX_XA_JDBC
  125
+  module ActiveRecord
  126
+    module ConnectionAdapters
  127
+      class JdbcAdapter
  128
+        include TorqueBox::Transactions::ActiveRecordAdapters::Connection
  129
+      end
121 130
     end
122 131
   end
123 132
 end
124  
-  
  133
+
125 134
 module TorqueBox
126 135
   module Transactions
127 136
     class Manager

0 notes on commit 4b61e69

Please sign in to comment.
Something went wrong with that request. Please try again.