cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1328132 - in /cxf/trunk/rt/ws/rm/src: main/java/org/apache/cxf/ws/rm/persistence/jdbc/ test/java/org/apache/cxf/ws/rm/persistence/jdbc/
Date Thu, 19 Apr 2012 22:16:00 GMT
Author: ay
Date: Thu Apr 19 22:16:00 2012
New Revision: 1328132

URL: http://svn.apache.org/viewvc?rev=1328132&view=rev
Log:
DataSource as config option added to CXF-4249

Added:
    cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml
  (with props)
Modified:
    cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
    cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java?rev=1328132&r1=1328131&r2=1328132&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
(original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
Thu Apr 19 22:16:00 2012
@@ -44,6 +44,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;
@@ -165,6 +166,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;
@@ -220,6 +222,14 @@ public class RMTxStore implements RMStor
         }
     }
 
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+
+    public void setDataSource(DataSource ds) {
+        dataSource = ds;
+    }
+
     public String getTableExistsState() {
         return tableExistsState;
     }
@@ -784,21 +794,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/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java?rev=1328132&r1=1328131&r2=1328132&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
(original)
+++ cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStoreConfigurationTest.java
Thu Apr 19 22:16:00 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");
+        }
+    }
 }

Added: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml?rev=1328132&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/persistence/jdbc/txstore-ds-bean.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml



Mime
View raw message