Make a distinction based on type=javax.sql.DataSource or type=javax.sql.XADataSource...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 15 Jan 2010 20:02:36 +0000 (20:02 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 15 Jan 2010 20:02:36 +0000 (20:02 +0000)
Make static methods non static for easier extendability

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@899796 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/build.properties.default
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java [new file with mode: 0644]

index e935fc7..f2986a4 100644 (file)
@@ -28,7 +28,7 @@
 version.major=1
 version.minor=0
 version.build=8
-version.patch=4
+version.patch=5
 version.suffix=
 
 # ----- Default Base Path for Dependent Packages -----
index 0deda0e..356556d 100644 (file)
@@ -37,7 +37,7 @@ import org.apache.juli.logging.LogFactory;
  * @author Filip Hanik
  * @version 1.0
  */
-public class DataSource extends DataSourceProxy implements MBeanRegistration,javax.sql.DataSource,XADataSource, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean {
+public class DataSource extends DataSourceProxy implements javax.sql.DataSource,MBeanRegistration, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean {
     private static final Log log = LogFactory.getLog(DataSource.class);
 
     /**
index fb36681..3a431da 100644 (file)
@@ -184,11 +184,15 @@ public class DataSourceFactory implements ObjectFactory {
             return null;
         }
         Reference ref = (Reference) obj;
-        
+        boolean XA = false;
         boolean ok = false;
         if ("javax.sql.DataSource".equals(ref.getClassName())) {
             ok = true;
         }
+        if ("javax.sql.XADataSource".equals(ref.getClassName())) {
+            ok = true;
+            XA = true;
+        }
         if (org.apache.tomcat.jdbc.pool.DataSource.class.getName().equals(ref.getClassName())) {
             ok = true;
         }
@@ -209,7 +213,7 @@ public class DataSourceFactory implements ObjectFactory {
             }
         }
 
-        return createDataSource(properties,nameCtx);
+        return createDataSource(properties,nameCtx,XA);
     }
     
     public static PoolConfiguration parsePoolProperties(Properties properties) throws IOException{
@@ -458,40 +462,46 @@ public class DataSourceFactory implements ObjectFactory {
      * @param properties the datasource configuration properties
      * @throws Exception if an error occurs creating the data source
      */
-    public static DataSource createDataSource(Properties properties) throws Exception {
-        return createDataSource(properties,null);
+    public DataSource createDataSource(Properties properties) throws Exception {
+        return createDataSource(properties,null,false);
     }
-    public static DataSource createDataSource(Properties properties,Context context) throws Exception {
+    public DataSource createDataSource(Properties properties,Context context, boolean XA) throws Exception {
         PoolConfiguration poolProperties = DataSourceFactory.parsePoolProperties(properties);
         if (poolProperties.getDataSourceJNDI()!=null && poolProperties.getDataSource()==null) {
-            Object jndiDS = null;
-            try {
-                if (context!=null) {
-                    jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
-                } else {
-                    log.warn("dataSourceJNDI property is configued, but local JNDI context is null.");
-                }
-            } catch (NamingException e) {
-                log.debug("The name \""+poolProperties.getDataSourceJNDI()+"\" can not be found in the local context.");
-            }
-            if (jndiDS==null) {
-                try {
-                    context = (Context) (new InitialContext());
-                    jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
-                } catch (NamingException e) {
-                    log.warn("The name \""+poolProperties.getDataSourceJNDI()+"\" can not be found in the InitialContext.");
-                }
-            }
-            if (jndiDS!=null) {
-                poolProperties.setDataSource(jndiDS);
-            }
+            performJNDILookup(context, poolProperties);
         }
-        org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
+        org.apache.tomcat.jdbc.pool.DataSource dataSource = XA?
+                new org.apache.tomcat.jdbc.pool.XADataSource(poolProperties) :
+                new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
         //initialise the pool itself
         dataSource.createPool();
         // Return the configured DataSource instance
         return dataSource;
     }
+
+    public void performJNDILookup(Context context, PoolConfiguration poolProperties) {
+        Object jndiDS = null;
+        try {
+            if (context!=null) {
+                jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
+            } else {
+                log.warn("dataSourceJNDI property is configued, but local JNDI context is null.");
+            }
+        } catch (NamingException e) {
+            log.debug("The name \""+poolProperties.getDataSourceJNDI()+"\" can not be found in the local context.");
+        }
+        if (jndiDS==null) {
+            try {
+                context = (Context) (new InitialContext());
+                jndiDS = context.lookup(poolProperties.getDataSourceJNDI());
+            } catch (NamingException e) {
+                log.warn("The name \""+poolProperties.getDataSourceJNDI()+"\" can not be found in the InitialContext.");
+            }
+        }
+        if (jndiDS!=null) {
+            poolProperties.setDataSource(jndiDS);
+        }
+    }
     
     /**
      * <p>Parse properties from the string. Format of the string must be [propertyName=property;]*<p>
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java
new file mode 100644 (file)
index 0000000..ba1e685
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.tomcat.jdbc.pool;
+
+public class XADataSource extends DataSource implements javax.sql.XADataSource {
+
+    public XADataSource() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    public XADataSource(PoolConfiguration poolProperties) {
+        super(poolProperties);
+        // TODO Auto-generated constructor stub
+    }
+
+}