aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1599114 - in /aries/trunk/transaction: transaction-itests/ transaction-jdbc/ transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/ transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/
Date Mon, 02 Jun 2014 08:14:09 GMT
Author: gnodet
Date: Mon Jun  2 08:14:08 2014
New Revision: 1599114

URL: http://svn.apache.org/r1599114
Log:
[ARIES-1150] Add support for creating non xa DataSource

Added:
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/AbstractMCFFactory.java
      - copied, changed from r1599113, aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/DataSourceMCFFactory.java
Modified:
    aries/trunk/transaction/transaction-itests/pom.xml
    aries/trunk/transaction/transaction-jdbc/pom.xml
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java

Modified: aries/trunk/transaction/transaction-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/pom.xml?rev=1599114&r1=1599113&r2=1599114&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/pom.xml (original)
+++ aries/trunk/transaction/transaction-itests/pom.xml Mon Jun  2 08:14:08 2014
@@ -78,7 +78,7 @@
             <groupId>org.apache.aries.transaction</groupId>
             <artifactId>org.apache.aries.transaction.jdbc</artifactId>
             <scope>test</scope>
-            <version>2.0.1-SNAPSHOT</version>
+            <version>2.1.0-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.aries.transaction</groupId>

Modified: aries/trunk/transaction/transaction-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/pom.xml?rev=1599114&r1=1599113&r2=1599114&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/pom.xml (original)
+++ aries/trunk/transaction/transaction-jdbc/pom.xml Mon Jun  2 08:14:08 2014
@@ -31,7 +31,7 @@
     <groupId>org.apache.aries.transaction</groupId>
     <artifactId>org.apache.aries.transaction.jdbc</artifactId>
     <name>Apache Aries Transaction Enlisting JDBC Datasource</name>
-    <version>2.0.1-SNAPSHOT</version>
+    <version>2.1.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <scm>

Modified: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java?rev=1599114&r1=1599113&r2=1599114&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
(original)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
Mon Jun  2 08:14:08 2014
@@ -19,11 +19,14 @@
 package org.apache.aries.transaction.jdbc;
 
 import org.apache.aries.transaction.AriesTransactionManager;
+import org.apache.aries.transaction.jdbc.internal.AbstractMCFFactory;
 import org.apache.aries.transaction.jdbc.internal.ConnectionManagerFactory;
+import org.apache.aries.transaction.jdbc.internal.DataSourceMCFFactory;
 import org.apache.aries.transaction.jdbc.internal.Recovery;
 import org.apache.aries.transaction.jdbc.internal.XADataSourceMCFFactory;
 import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
 
+import javax.sql.CommonDataSource;
 import javax.sql.DataSource;
 import javax.sql.XADataSource;
 import java.io.PrintWriter;
@@ -42,7 +45,7 @@ import java.sql.SQLFeatureNotSupportedEx
  */
 public class RecoverableDataSource implements DataSource {
 
-    private XADataSource dataSource;
+    private CommonDataSource dataSource;
     private AriesTransactionManager transactionManager;
     private String name;
     private String exceptionSorter = "all";
@@ -55,7 +58,7 @@ public class RecoverableDataSource imple
     private boolean pooling = true;
     private int poolMaxSize = 10;
     private int poolMinSize = 0;
-    private String transaction = "xa";
+    private String transaction;
 
     private DataSource delegate;
 
@@ -68,11 +71,11 @@ public class RecoverableDataSource imple
     }
 
     /**
-     * The XADataSource to wrap.
+     * The CommonDataSource to wrap.
      *
      * @org.apache.xbean.Property required=true
      */
-    public void setDataSource(XADataSource dataSource) {
+    public void setDataSource(CommonDataSource dataSource) {
         this.dataSource = dataSource;
     }
 
@@ -161,7 +164,20 @@ public class RecoverableDataSource imple
      * @org.apache.xbean.InitMethod
      */
     public void start() throws Exception {
-        XADataSourceMCFFactory mcf = new XADataSourceMCFFactory();
+        AbstractMCFFactory mcf;
+        if (dataSource instanceof DataSource) {
+            mcf = new DataSourceMCFFactory();
+            if (transaction == null) {
+                transaction = "local";
+            }
+        } else if (dataSource instanceof XADataSource) {
+            mcf = new XADataSourceMCFFactory();
+            if (transaction == null) {
+                transaction = "xa";
+            }
+        } else {
+            throw new IllegalArgumentException("dataSource must be of type javax.sql.DataSource/XADataSource");
+        }
         mcf.setDataSource(dataSource);
         mcf.setExceptionSorterAsString(exceptionSorter);
         mcf.setUserName(username);
@@ -183,7 +199,9 @@ public class RecoverableDataSource imple
 
         delegate = (DataSource) mcf.getConnectionFactory().createConnectionFactory(cm.getConnectionManager());
 
-        Recovery.recover(name, dataSource, transactionManager);
+        if (dataSource instanceof XADataSource) {
+            Recovery.recover(name, (XADataSource) dataSource, transactionManager);
+        }
     }
 
     //---------------------------

Copied: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/AbstractMCFFactory.java
(from r1599113, aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java)
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/AbstractMCFFactory.java?p2=aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/AbstractMCFFactory.java&p1=aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java&r1=1599113&r2=1599114&rev=1599114&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java
(original)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/AbstractMCFFactory.java
Mon Jun  2 08:14:08 2014
@@ -18,45 +18,33 @@
  */
 package org.apache.aries.transaction.jdbc.internal;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.sql.CommonDataSource;
+import javax.sql.XADataSource;
+
 import org.tranql.connector.AllExceptionsAreFatalSorter;
-import org.tranql.connector.CredentialExtractor;
 import org.tranql.connector.ExceptionSorter;
 import org.tranql.connector.NoExceptionsAreFatalSorter;
-import org.tranql.connector.jdbc.AbstractXADataSourceMCF;
 import org.tranql.connector.jdbc.ConfigurableSQLStateExceptionSorter;
 import org.tranql.connector.jdbc.KnownSQLStateExceptionSorter;
 
-import javax.resource.ResourceException;
-import javax.resource.spi.ManagedConnectionFactory;
-import javax.resource.spi.ResourceAdapterInternalException;
-import javax.sql.XAConnection;
-import javax.sql.XADataSource;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
+public abstract class AbstractMCFFactory {
 
-public class XADataSourceMCFFactory {
-
-    private XADataSource dataSource;
+    private CommonDataSource dataSource;
     private ExceptionSorter exceptionSorter = new AllExceptionsAreFatalSorter();
     private String userName;
     private String password;
 
-    private ManagedConnectionFactory connectionFactory;
+    ManagedConnectionFactory connectionFactory;
 
     public ManagedConnectionFactory getConnectionFactory() {
         return connectionFactory;
     }
 
-    public void init() throws Exception {
-        if (dataSource == null) {
-            throw new IllegalArgumentException("dataSource must be set");
-        }
-        if (connectionFactory == null) {
-            connectionFactory = new XADataSourceMCF();
-        }
-    }
+    public abstract void init() throws Exception;
 
     public void setExceptionSorterAsString(String sorter) {
         if ("all".equalsIgnoreCase(sorter)) {
@@ -78,11 +66,11 @@ public class XADataSourceMCFFactory {
         }
     }
 
-    public XADataSource getDataSource() {
+    public CommonDataSource getDataSource() {
         return dataSource;
     }
 
-    public void setDataSource(XADataSource dataSource) {
+    public void setDataSource(CommonDataSource dataSource) {
         this.dataSource = dataSource;
     }
 
@@ -110,34 +98,4 @@ public class XADataSourceMCFFactory {
         this.password = password;
     }
 
-    public class XADataSourceMCF extends AbstractXADataSourceMCF<XADataSource> {
-
-        public XADataSourceMCF() {
-            super(XADataSourceMCFFactory.this.dataSource, XADataSourceMCFFactory.this.exceptionSorter);
-        }
-
-        public String getUserName() {
-            return userName;
-        }
-
-        public String getPassword() {
-            return password;
-        }
-
-        protected XAConnection getPhysicalConnection(CredentialExtractor credentialExtractor)
throws ResourceException {
-            try {
-                String userName = credentialExtractor.getUserName();
-                String password = credentialExtractor.getPassword();
-                if (userName != null) {
-                    return xaDataSource.getXAConnection(userName, password);
-                } else {
-                    return xaDataSource.getXAConnection();
-                }
-            } catch (SQLException e) {
-                throw new ResourceAdapterInternalException("Unable to obtain physical connection
to " + xaDataSource, e);
-            }
-        }
-
-    }
-
 }

Added: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/DataSourceMCFFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/DataSourceMCFFactory.java?rev=1599114&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/DataSourceMCFFactory.java
(added)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/DataSourceMCFFactory.java
Mon Jun  2 08:14:08 2014
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.transaction.jdbc.internal;
+
+import javax.sql.DataSource;
+
+import org.tranql.connector.jdbc.AbstractLocalDataSourceMCF;
+
+public class DataSourceMCFFactory extends AbstractMCFFactory {
+
+    @Override
+    public void init() throws Exception {
+        if (getDataSource() == null) {
+            throw new IllegalArgumentException("dataSource must be set");
+        }
+        if (connectionFactory == null) {
+            connectionFactory = new DataSourceMCF();
+        }
+    }
+
+    public class DataSourceMCF extends AbstractLocalDataSourceMCF<DataSource> {
+        public DataSourceMCF() {
+            super((DataSource) DataSourceMCFFactory.this.getDataSource(), DataSourceMCFFactory.this.getExceptionSorter(),
true);
+        }
+
+        public String getUserName() {
+            return DataSourceMCFFactory.this.getUserName();
+        }
+
+        public String getPassword() {
+            return DataSourceMCFFactory.this.getPassword();
+        }
+    }
+}

Modified: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java?rev=1599114&r1=1599113&r2=1599114&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java
(original)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/XADataSourceMCFFactory.java
Mon Jun  2 08:14:08 2014
@@ -36,21 +36,10 @@ import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 
-public class XADataSourceMCFFactory {
-
-    private XADataSource dataSource;
-    private ExceptionSorter exceptionSorter = new AllExceptionsAreFatalSorter();
-    private String userName;
-    private String password;
-
-    private ManagedConnectionFactory connectionFactory;
-
-    public ManagedConnectionFactory getConnectionFactory() {
-        return connectionFactory;
-    }
+public class XADataSourceMCFFactory extends AbstractMCFFactory {
 
     public void init() throws Exception {
-        if (dataSource == null) {
+        if (getDataSource() == null) {
             throw new IllegalArgumentException("dataSource must be set");
         }
         if (connectionFactory == null) {
@@ -58,72 +47,22 @@ public class XADataSourceMCFFactory {
         }
     }
 
-    public void setExceptionSorterAsString(String sorter) {
-        if ("all".equalsIgnoreCase(sorter)) {
-            this.exceptionSorter = new AllExceptionsAreFatalSorter();
-        } else if ("none".equalsIgnoreCase(sorter)) {
-            this.exceptionSorter = new NoExceptionsAreFatalSorter();
-        } else if ("known".equalsIgnoreCase(sorter)) {
-            this.exceptionSorter = new KnownSQLStateExceptionSorter();
-        } else if (sorter.toLowerCase().startsWith("custom(") && sorter.endsWith(")"))
{
-            List<String> states = new ArrayList<String>();
-            for (String s : sorter.substring(7, sorter.length() - 2).split(",")) {
-                if (s != null && s.length() > 0) {
-                    states.add(s);
-                }
-            }
-            this.exceptionSorter = new ConfigurableSQLStateExceptionSorter(states);
-        } else {
-            throw new IllegalArgumentException("Unknown exceptionSorter " + sorter);
-        }
-    }
-
-    public XADataSource getDataSource() {
-        return dataSource;
-    }
-
-    public void setDataSource(XADataSource dataSource) {
-        this.dataSource = dataSource;
-    }
-
-    public ExceptionSorter getExceptionSorter() {
-        return exceptionSorter;
-    }
-
-    public void setExceptionSorter(ExceptionSorter exceptionSorter) {
-        this.exceptionSorter = exceptionSorter;
-    }
-
-    public String getUserName() {
-        return userName;
-    }
-
-    public void setUserName(String userName) {
-        this.userName = userName;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public void setPassword(String password) {
-        this.password = password;
-    }
-
     public class XADataSourceMCF extends AbstractXADataSourceMCF<XADataSource> {
 
         public XADataSourceMCF() {
-            super(XADataSourceMCFFactory.this.dataSource, XADataSourceMCFFactory.this.exceptionSorter);
+            super((XADataSource) XADataSourceMCFFactory.this.getDataSource(), XADataSourceMCFFactory.this.getExceptionSorter());
         }
 
         public String getUserName() {
-            return userName;
+            return XADataSourceMCFFactory.this.getUserName();
         }
 
+        @Override
         public String getPassword() {
-            return password;
+            return XADataSourceMCFFactory.this.getPassword();
         }
 
+        @Override
         protected XAConnection getPhysicalConnection(CredentialExtractor credentialExtractor)
throws ResourceException {
             try {
                 String userName = credentialExtractor.getUserName();



Mime
View raw message