From: fhanik Date: Wed, 5 Aug 2009 15:42:55 +0000 (+0000) Subject: Add in support for XA drivers and connections. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=68ff290b8a8d6b866410e6bb135ac8f8bd35da7c;p=tomcat7.0 Add in support for XA drivers and connections. Update version git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@801270 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/jdbc-pool/build.properties.default b/modules/jdbc-pool/build.properties.default index 31eda6cc9..da1cc019d 100644 --- a/modules/jdbc-pool/build.properties.default +++ b/modules/jdbc-pool/build.properties.default @@ -27,7 +27,7 @@ # ----- Vesion Control Flags ----- version.major=1 version.minor=0 -version.build=7 +version.build=8 version.patch= version.suffix= diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java index dd0ebbc37..b4332229c 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java @@ -35,6 +35,8 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import javax.sql.XAConnection; + import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -275,7 +277,7 @@ public class ConnectionPool { } try { - getProxyConstructor(); + getProxyConstructor(con.getConnection() instanceof XAConnection); //create the proxy //TODO possible optimization, keep track if this connection was returned properly, and don't generate a new facade Connection connection = (Connection)proxyClassConstructor.newInstance(new Object[] { handler }); @@ -295,10 +297,12 @@ public class ConnectionPool { * @return constructor used to instantiate the wrapper object * @throws NoSuchMethodException */ - public Constructor getProxyConstructor() throws NoSuchMethodException { + public Constructor getProxyConstructor(boolean xa) throws NoSuchMethodException { //cache the constructor if (proxyClassConstructor == null ) { - Class proxyClass = Proxy.getProxyClass(ConnectionPool.class.getClassLoader(), new Class[] {java.sql.Connection.class,javax.sql.PooledConnection.class}); + Class proxyClass = xa ? + Proxy.getProxyClass(ConnectionPool.class.getClassLoader(), new Class[] {java.sql.Connection.class,javax.sql.PooledConnection.class, javax.sql.XAConnection.class}) : + Proxy.getProxyClass(ConnectionPool.class.getClassLoader(), new Class[] {java.sql.Connection.class,javax.sql.PooledConnection.class}); proxyClassConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); } return proxyClassConstructor; 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 490654e87..ad5df2825 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 @@ -24,6 +24,7 @@ import javax.management.MBeanRegistration; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import javax.sql.XADataSource; /** @@ -33,7 +34,7 @@ import javax.management.ObjectName; * @author Filip Hanik * @version 1.0 */ -public class DataSource extends DataSourceProxy implements MBeanRegistration,javax.sql.DataSource, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean { +public class DataSource extends DataSourceProxy implements MBeanRegistration,javax.sql.DataSource,XADataSource, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean { /** * Constructor for reflection only. A default set of pool properties will be created. diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java index 11924d770..ff291aab0 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java @@ -19,10 +19,13 @@ package org.apache.tomcat.jdbc.pool; import java.io.PrintWriter; import java.sql.Connection; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.util.Iterator; import java.util.Properties; import java.util.concurrent.Future; +import javax.sql.XAConnection; + import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition; @@ -114,6 +117,33 @@ public class DataSourceProxy implements PoolConfiguration { return createPool().getConnectionAsync(); return pool.getConnectionAsync(); } + + /** + * {@link javax.sql.XADataSource#getXAConnection()} + */ + public XAConnection getXAConnection() throws SQLException { + Connection con = getConnection(); + if (con instanceof XAConnection) { + return (XAConnection)con; + } else { + try {con.close();} catch (Exception ignore){} + throw new SQLException("Connection from pool does not implement javax.sql.XAConnection"); + } + } + + /** + * {@link javax.sql.XADataSource#getXAConnection(String, String)} + */ + public XAConnection getXAConnection(String username, String password) throws SQLException { + Connection con = getConnection(username, password); + if (con instanceof XAConnection) { + return (XAConnection)con; + } else { + try {con.close();} catch (Exception ignore){} + throw new SQLException("Connection from pool does not implement javax.sql.XAConnection"); + } + } + /** * {@link javax.sql.DataSource#getConnection()} diff --git a/modules/jdbc-pool/sign.sh b/modules/jdbc-pool/sign.sh index c35d320f1..182851479 100755 --- a/modules/jdbc-pool/sign.sh +++ b/modules/jdbc-pool/sign.sh @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION=v1.0.7 +VERSION=v1.0.8 for i in $(find output/release/$VERSION -name "*.zip" -o -name "*.tar.gz"); do echo Signing $i echo $1|gpg --passphrase-fd 0 -a -b $i