You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/04/20 11:28:12 UTC

svn commit: r1328274 - in /cxf/branches/2.5.x-fixes: ./ rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/ rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/

Author: ay
Date: Fri Apr 20 09:28:12 2012
New Revision: 1328274

URL: http://svn.apache.org/viewvc?rev=1328274&view=rev
Log:
Merged revisions 1328132 via  svn merge from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1328132 | ay | 2012-04-20 00:16:00 +0200 (Fri, 20 Apr 2012) | 1 line
  
  DataSource as config option added to CXF-4249
........

Added:
    cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml
      - copied unchanged from r1328132, cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml
Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
    cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java?rev=1328274&r1=1328273&r2=1328274&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java (original)
+++ cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java Fri Apr 20 09:28:12 2012
@@ -40,6 +40,7 @@ import java.util.logging.Logger;
 import java.util.regex.Pattern;
 
 import javax.annotation.PostConstruct;
+import javax.sql.DataSource;
 
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
@@ -146,6 +147,7 @@ public class RMTxStore implements RMStor
     private PreparedStatement selectInboundMessagesStmt;
     private PreparedStatement selectOutboundMessagesStmt;
     
+    private DataSource dataSource;
     private String driverClassName = "org.apache.derby.jdbc.EmbeddedDriver";
     private String url = MessageFormat.format("jdbc:derby:{0};create=true", DEFAULT_DATABASE_NAME);
     private String userName;
@@ -201,6 +203,14 @@ public class RMTxStore implements RMStor
         }
     }
 
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+
+    public void setDataSource(DataSource ds) {
+        dataSource = ds;
+    }
+
     public String getTableExistsState() {
         return tableExistsState;
     }
@@ -713,21 +723,31 @@ public class RMTxStore implements RMStor
         if (null == connection) {
             LOG.log(Level.FINE, "Using derby.system.home: {0}", 
                     SystemPropertyAction.getProperty("derby.system.home"));
-            assert null != url;
-            assert null != driverClassName;
-            try {
-                Class.forName(driverClassName);
-            } catch (ClassNotFoundException ex) {
-                LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);
-                return;
-            }
+            if (null != dataSource) {
+                try {
+                    LOG.log(Level.FINE, "Using dataSource: " + dataSource);
+                    connection = dataSource.getConnection();
+                } catch (SQLException ex) {
+                    LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);
+                    return;
+                }
+            } else {
+                assert null != url;
+                assert null != driverClassName;
+                try {
+                    Class.forName(driverClassName);
+                } catch (ClassNotFoundException ex) {
+                    LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);
+                    return;
+                }
     
-            try {
-                LOG.log(Level.FINE, "Using url: " + url);
-                connection = DriverManager.getConnection(url, userName, password);
-            } catch (SQLException ex) {
-                LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);
-                return;
+                try {
+                    LOG.log(Level.FINE, "Using url: " + url);
+                    connection = DriverManager.getConnection(url, userName, password);
+                } catch (SQLException ex) {
+                    LogUtils.log(LOG, Level.SEVERE, "CONNECT_EXC", ex);
+                    return;
+                }
             }
         }
         

Modified: cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java?rev=1328274&r1=1328273&r2=1328274&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java (original)
+++ cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java Fri Apr 20 09:28:12 2012
@@ -19,8 +19,12 @@
 
 package org.apache.cxf.ws.rm.persistence.jdbc;
 
+import java.io.PrintWriter;
+import java.sql.Connection;
 import java.sql.SQLException;
 
+import javax.sql.DataSource;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.ws.rm.RMManager;
@@ -61,4 +65,51 @@ public class RMTxStoreConfigurationTest 
         
         assertFalse(store.isTableExistsError(new SQLException("Unknown error", "00000", -1)));
     }
+
+    @Test
+    public void testTxStoreWithDataSource() {
+        SpringBusFactory factory = new SpringBusFactory();
+        Bus bus = factory.createBus("org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml");
+        RMManager manager = bus.getExtension(RMManager.class);
+        assertNotNull(manager);
+        RMTxStore store = (RMTxStore)manager.getStore();
+                
+        assertNotNull(store.getDataSource());
+        
+        assertNull(store.getConnection());
+    }
+    
+    static class TestDataSource implements DataSource {
+        public PrintWriter getLogWriter() throws SQLException {
+            return null;
+        }
+
+        public void setLogWriter(PrintWriter out) throws SQLException {
+        }
+
+        public void setLoginTimeout(int seconds) throws SQLException {
+        }
+
+        public int getLoginTimeout() throws SQLException {
+            return 0;
+        }
+
+        public <T> T unwrap(Class<T> iface) throws SQLException {
+            return null;
+        }
+
+        public boolean isWrapperFor(Class<?> iface) throws SQLException {
+            return false;
+        }
+
+        public Connection getConnection() throws SQLException {
+            // avoid creating a connection and tables at RMTxStore.init()
+            throw new SQLException("test");
+        }
+
+        public Connection getConnection(String username, String password) throws SQLException {
+            // avoid creating a connection and tables at RMTxStore.init()
+            throw new SQLException("test");
+        }
+    }
 }