Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get XA working on Oracle with activerecord-jdbc-adapter (TORQUE-567)

The rails_transaction_spec passes for Rails 3.0 and 3.1 when tested
against Oracle databases. There are a couple of caveats:

* Only ojdbc6.jar is supported right now, not ojdbc5.jar

* This has only been tested with activerecord-jdbc-adapter and not
  activerecord-oracle_enhanced-adapter
  • Loading branch information...
commit 39e15fadbbb991f31ef6ffb74cb18cc7c40c6444 1 parent 41abf7f
@bbrowning bbrowning authored
View
6 modules/core/src/main/java/org/torquebox/core/datasource/DataSourceXAVerifierService.java
@@ -101,7 +101,11 @@ protected boolean testSupportsXa() {
Transaction tx = tm.getTransaction();
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
- statement.execute( "SELECT 1;" );
+ String sql = "SELECT 1;";
+ if (getAdapterId().equals( "oracle" )) {
+ sql = "SELECT 1 FROM DUAL";
+ }
+ statement.execute( sql );
statement.close();
tx.enlistResource( new DummyXAResource() );
tm.commit();
View
18 modules/core/src/main/java/org/torquebox/core/datasource/db/OracleAdapter.java
@@ -27,7 +27,7 @@
public class OracleAdapter extends AbstractAdapter {
public OracleAdapter() {
- super( "oracle", "jdbc/oracle", "oracle.jdbc.driver.OracleDriver", "oracle.jdbc.xa.client.OracleXADataSource" );
+ super( "oracle", "ojdbc6.jar", "oracle.jdbc.OracleDriver", "oracle.jdbc.xa.client.OracleXADataSource" );
}
@Override
@@ -41,10 +41,18 @@ public OracleAdapter() {
public Map<String, String> getPropertiesFor(DatabaseMetaData dbMeta) {
Map<String, Object> config = dbMeta.getConfiguration();
Map<String, String> properties = new HashMap<String, String>();
-
- properties.put( "URL" , ""+config.get("url"));
- properties.put( "User" , ""+config.get("username") );
- properties.put( "Password" , ""+config.get("password") );
+
+ String url = (String) config.get( "url" );
+ if (url == null) {
+ String host = config.get( "host" ) == null ? "localhost" : (String) config.get( "host" );
+ int port = config.get( "port" ) == null ? 1521 : (Integer) config.get( "port" );
+ String database = (String) config.get( "database" );
+ url = "jdbc:oracle:thin:@" + host + ":" + port + ":" + database;
+ }
+
+ properties.put( "URL" , url );
+ properties.put( "User" , ""+config.get("username") );
+ properties.put( "Password", ""+config.get("password") );
return properties;
}
View
2  modules/core/src/main/java/org/torquebox/core/datasource/processors/DatabaseProcessor.java
@@ -77,6 +77,7 @@
import org.torquebox.core.datasource.db.Adapter;
import org.torquebox.core.datasource.db.H2Adapter;
import org.torquebox.core.datasource.db.MySQLAdapter;
+import org.torquebox.core.datasource.db.OracleAdapter;
import org.torquebox.core.datasource.db.PostgresAdapter;
import org.torquebox.core.runtime.RubyRuntimeFactory;
@@ -86,6 +87,7 @@ public DatabaseProcessor() {
addAdapter( new H2Adapter() );
addAdapter( new PostgresAdapter() );
addAdapter( new MySQLAdapter() );
+ addAdapter( new OracleAdapter() );
// DriverManager.setLogWriter( new PrintWriter( System.err ) );
}
Please sign in to comment.
Something went wrong with that request. Please try again.