tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r899796 - in /tomcat/trunk/modules/jdbc-pool: build.properties.default java/org/apache/tomcat/jdbc/pool/DataSource.java java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java java/org/apache/tomcat/jdbc/pool/XADataSource.java
Date Fri, 15 Jan 2010 20:02:36 GMT
Author: fhanik
Date: Fri Jan 15 20:02:36 2010
New Revision: 899796

URL: http://svn.apache.org/viewvc?rev=899796&view=rev
Log:
Make a distinction based on type=javax.sql.DataSource or type=javax.sql.XADataSource, some
components, like JIRA actually do an instanceof on the object to determine what it is instead
of relying on the configuration.
Make static methods non static for easier extendability


Added:
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java   (with
props)
Modified:
    tomcat/trunk/modules/jdbc-pool/build.properties.default
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java

Modified: tomcat/trunk/modules/jdbc-pool/build.properties.default
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/build.properties.default?rev=899796&r1=899795&r2=899796&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/build.properties.default (original)
+++ tomcat/trunk/modules/jdbc-pool/build.properties.default Fri Jan 15 20:02:36 2010
@@ -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 -----

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java?rev=899796&r1=899795&r2=899796&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java Fri Jan
15 20:02:36 2010
@@ -37,7 +37,7 @@
  * @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);
 
     /**

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java?rev=899796&r1=899795&r2=899796&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
Fri Jan 15 20:02:36 2010
@@ -184,11 +184,15 @@
             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 @@
             }
         }
 
-        return createDataSource(properties,nameCtx);
+        return createDataSource(properties,nameCtx,XA);
     }
     
     public static PoolConfiguration parsePoolProperties(Properties properties) throws IOException{
@@ -458,40 +462,46 @@
      * @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>

Added: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java?rev=899796&view=auto
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java (added)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java Fri
Jan 15 20:02:36 2010
@@ -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
+    }
+
+}

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message