From 70c37f75cac47ba115aa5e03d11261d2cd8f3614 Mon Sep 17 00:00:00 2001 From: fhanik Date: Fri, 15 Jan 2010 20:02:36 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@899796 13f79535-47bb-0310-9956-ffa450edef68 --- modules/jdbc-pool/build.properties.default | 2 +- .../org/apache/tomcat/jdbc/pool/DataSource.java | 2 +- .../apache/tomcat/jdbc/pool/DataSourceFactory.java | 64 +++++++++++++--------- .../org/apache/tomcat/jdbc/pool/XADataSource.java | 32 +++++++++++ 4 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java diff --git a/modules/jdbc-pool/build.properties.default b/modules/jdbc-pool/build.properties.default index e935fc7f3..f2986a48b 100644 --- a/modules/jdbc-pool/build.properties.default +++ b/modules/jdbc-pool/build.properties.default @@ -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 ----- diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java index 0deda0ea0..356556d5a 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java @@ -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); /** diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java index fb36681ba..3a431dac8 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java @@ -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); + } + } /** *

Parse properties from the string. Format of the string must be [propertyName=property;]*

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 index 000000000..ba1e685e5 --- /dev/null +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/XADataSource.java @@ -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 + } + +} -- 2.11.0