Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java Tue Jun 19 09:04:08 2018 @@ -20,9 +20,9 @@ package org.apache.tomcat.dbcp.dbcp2.man import java.sql.Connection; import java.sql.SQLException; import java.util.Map; +import java.util.Objects; import java.util.WeakHashMap; -import javax.transaction.Status; import javax.transaction.SystemException; import javax.transaction.Transaction; import javax.transaction.TransactionManager; @@ -30,58 +30,56 @@ import javax.transaction.xa.XAResource; import org.apache.tomcat.dbcp.dbcp2.DelegatingConnection; - /** * TransactionRegistry tracks Connections and XAResources in a transacted environment for a single XAConnectionFactory. * <p> * The TransactionRegistry hides the details of transaction processing from the existing DBCP pooling code, and gives * the ManagedConnection a way to enlist connections in a transaction, allowing for the maximal rescue of DBCP. * </p> - * @author Dain Sundstrom + * * @since 2.0 */ public class TransactionRegistry { private final TransactionManager transactionManager; - private final Map<Transaction, TransactionContext> caches = - new WeakHashMap<>(); + private final Map<Transaction, TransactionContext> caches = new WeakHashMap<>(); private final Map<Connection, XAResource> xaResources = new WeakHashMap<>(); /** * Creates a TransactionRegistry for the specified transaction manager. - * @param transactionManager the transaction manager used to enlist connections + * + * @param transactionManager + * the transaction manager used to enlist connections. */ public TransactionRegistry(final TransactionManager transactionManager) { this.transactionManager = transactionManager; } /** - * Registers the association between a Connection and a XAResource. When a connection - * is enlisted in a transaction, it is actually the XAResource that is given to the transaction - * manager. + * Registers the association between a Connection and a XAResource. When a connection is enlisted in a transaction, + * it is actually the XAResource that is given to the transaction manager. * - * @param connection the JDBC connection - * @param xaResource the XAResource which managed the connection within a transaction + * @param connection + * The JDBC connection. + * @param xaResource + * The XAResource which managed the connection within a transaction. */ public synchronized void registerConnection(final Connection connection, final XAResource xaResource) { - if (connection == null) { - throw new NullPointerException("connection is null"); - } - if (xaResource == null) { - throw new NullPointerException("xaResource is null"); - } + Objects.requireNonNull(connection, "connection is null"); + Objects.requireNonNull(xaResource, "xaResource is null"); xaResources.put(connection, xaResource); } /** * Gets the XAResource registered for the connection. - * @param connection the connection - * @return the XAResource registered for the connection; never null - * @throws SQLException if the connection does not have a registered XAResource + * + * @param connection + * the connection + * @return The XAResource registered for the connection; never null. + * @throws SQLException + * Thrown when the connection does not have a registered XAResource. */ public synchronized XAResource getXAResource(final Connection connection) throws SQLException { - if (connection == null) { - throw new NullPointerException("connection is null"); - } + Objects.requireNonNull(connection, "connection is null"); final Connection key = getConnectionKey(connection); final XAResource xaResource = xaResources.get(key); if (xaResource == null) { @@ -92,8 +90,10 @@ public class TransactionRegistry { /** * Gets the active TransactionContext or null if not Transaction is active. - * @return the active TransactionContext or null if no Transaction is active - * @throws SQLException if an error occurs while fetching the transaction + * + * @return The active TransactionContext or null if no Transaction is active. + * @throws SQLException + * Thrown when an error occurs while fetching the transaction. */ public TransactionContext getActiveTransactionContext() throws SQLException { Transaction transaction = null; @@ -105,11 +105,8 @@ public class TransactionRegistry { return null; } - // is it active - final int status = transaction.getStatus(); - if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) { - return null; - } + // This is the transaction on the thread so no need to check it's status - we should try to use it and + // fail later based on the subsequent status } catch (final SystemException e) { throw new SQLException("Unable to determine current transaction ", e); } @@ -126,15 +123,16 @@ public class TransactionRegistry { } /** - * Unregisters a destroyed connection from {@link TransactionRegistry} - * @param connection The connection + * Unregisters a destroyed connection from {@link TransactionRegistry}. + * + * @param connection + * A destroyed connection from {@link TransactionRegistry}. */ public synchronized void unregisterConnection(final Connection connection) { final Connection key = getConnectionKey(connection); xaResources.remove(key); } - private Connection getConnectionKey(final Connection connection) { Connection result; if (connection instanceof DelegatingConnection) { @@ -145,4 +143,3 @@ public class TransactionRegistry { return result; } } -
Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java Tue Jun 19 09:04:08 2018 @@ -23,21 +23,17 @@ import java.sql.SQLException; import org.apache.tomcat.dbcp.dbcp2.ConnectionFactory; /** - * XAConnectionFactory is an extension of ConnectionFactory used to create connections - * in a transaction managed environment. The XAConnectionFactory operates like a normal - * ConnectionFactory except a TransactionRegistry is provided from which the XAResource - * for a connection can be obtained. This allows the existing DBCP pool code to work with - * XAConnections and gives a the ManagedConnection a way to enlist a connection in the - * the transaction. + * XAConnectionFactory is an extension of ConnectionFactory used to create connections in a transaction managed + * environment. The XAConnectionFactory operates like a normal ConnectionFactory except a TransactionRegistry is + * provided from which the XAResource for a connection can be obtained. This allows the existing DBCP pool code to work + * with XAConnections and gives a the ManagedConnection a way to enlist a connection in the the transaction. * - * @author Dain Sundstrom - * @author Rodney Waldhoff * @since 2.0 */ public interface XAConnectionFactory extends ConnectionFactory { /** - * Gets the TransactionRegistry for this connection factory which contains a the - * XAResource for every connection created by this factory. + * Gets the TransactionRegistry for this connection factory which contains a the XAResource for every connection + * created by this factory. * * @return the transaction registry for this connection factory */ @@ -46,13 +42,13 @@ public interface XAConnectionFactory ext /** * Create a new {@link java.sql.Connection} in an implementation specific fashion. * <p> - * An implementation can assume that the caller of this will wrap the connection in - * a proxy that protects access to the setAutoCommit, commit and rollback when - * enrolled in a XA transaction. + * An implementation can assume that the caller of this will wrap the connection in a proxy that protects access to + * the setAutoCommit, commit and rollback when enrolled in a XA transaction. * </p> * * @return a new {@link java.sql.Connection} - * @throws java.sql.SQLException if a database error occurs creating the connection + * @throws java.sql.SQLException + * if a database error occurs creating the connection */ @Override Connection createConnection() throws SQLException; Modified: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/package-info.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/package-info.java?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/package-info.java (original) +++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/package-info.java Tue Jun 19 09:04:08 2018 @@ -17,114 +17,115 @@ /** * <p> - * Database Connection Pool API. + * Database Connection Pool API. * </p> * * <b>Overview in Dialog Form</b> * <p> - * Q: How do I use the DBCP package? - * </p><p> - * A: There are two primary ways to access the DBCP pool, as a - * {@link java.sql.Driver Driver}, or as a {@link javax.sql.DataSource DataSource}. - * You'll want to create an instance of {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver} or - * {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource}. When using one of these - * interfaces, you can just use your JDBC objects the way you normally would. - * Closing a {@link java.sql.Connection} will simply return it to its pool. - * </p> - * <p> - * Q: But {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver PoolingDriver} and - * {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource PoolingDataSource} both expect an - * {@link org.apache.tomcat.dbcp.pool2.ObjectPool ObjectPool} as an input. Where do I - * get one of those? - * </p><p> - * A: The {@link org.apache.tomcat.dbcp.pool2.ObjectPool ObjectPool} interface is defined - * in Commons Pool. You can use one of the provided implementations such as - * {@link org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool GenericObjectPool} or - * {@link org.apache.tomcat.dbcp.pool2.impl.SoftReferenceObjectPool SoftReferenceObjectPool} - * or you can create your own. - * </p> - * <p> - * Q: Ok, I've found an {@link org.apache.tomcat.dbcp.pool2.ObjectPool ObjectPool} - * implementation that I think suits my connection pooling needs. But it wants - * a {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory PooledObjectFactory}. - * What should I use for that? - * </p><p> - * A: The DBCP package provides a class for this purpose. It's called - * {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory}. - * It implements the factory and lifecycle methods of - * {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory} - * for {@link java.sql.Connection}s. But it doesn't create the actual database - * {@link java.sql.Connection}s itself, it uses a - * {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} for that. - * The {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory} will take - * {@link java.sql.Connection}s created by the {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} - * and wrap them with classes that implement the pooling behaviour. - * </p><p> - * Several implementations of {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} are - * provided--one that uses {@link java.sql.DriverManager} to create connections - * ({@link org.apache.tomcat.dbcp.dbcp2.DriverManagerConnectionFactory}), - * one that uses a {@link java.sql.Driver} to create connections - * ({@link org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory}), - * one that uses a {@link javax.sql.DataSource} to create connections - * ({@link org.apache.tomcat.dbcp.dbcp2.DataSourceConnectionFactory}). - * </p> - * <p> - * Q: I think I'm starting to get it, but can you walk me though it again? - * </p><p> - * A: Sure. Let's assume you want to create a {@link javax.sql.DataSource} - * that pools {@link java.sql.Connection}s. Let's also assume that - * those pooled {@link java.sql.Connection}s should be obtained from - * the {@link java.sql.DriverManager}. - * You'll want to create a {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource}. - * </p><p> - * The {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource} uses an underlying - * {@link org.apache.tomcat.dbcp.pool2.ObjectPool} to create and store its - * {@link java.sql.Connection}. - * </p><p> - * To create a {@link org.apache.tomcat.dbcp.pool2.ObjectPool}, you'll need - * a {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory} that creates - * the actual {@link java.sql.Connection}s. That's what - * {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory} is for. - * </p><p> - * To create the {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory}, - * you'll need at least two things:</p> - * <ol> - * <li> - * A {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} from which - * the actual database {@link java.sql.Connection}s will be obtained. - * </li> - * <li> - * An empty and factory-less {@link org.apache.tomcat.dbcp.pool2.ObjectPool} - * in which the {@link java.sql.Connection}s will be stored. - * <br> + * Q: How do I use the DBCP package? + * </p> + * <p> + * A: There are two primary ways to access the DBCP pool, as a {@link java.sql.Driver Driver}, or as a + * {@link javax.sql.DataSource DataSource}. You'll want to create an instance of + * {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver} or {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource}. When using one + * of these interfaces, you can just use your JDBC objects the way you normally would. Closing a + * {@link java.sql.Connection} will simply return it to its pool. + * </p> + * <p> + * Q: But {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver PoolingDriver} and + * {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource PoolingDataSource} both expect an + * {@link org.apache.tomcat.dbcp.pool2.ObjectPool ObjectPool} as an input. Where do I get one of those? + * </p> + * <p> + * A: The {@link org.apache.tomcat.dbcp.pool2.ObjectPool ObjectPool} interface is defined in Commons Pool. You can use one + * of the provided implementations such as {@link org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool GenericObjectPool} or + * {@link org.apache.tomcat.dbcp.pool2.impl.SoftReferenceObjectPool SoftReferenceObjectPool} or you can create your own. + * </p> + * <p> + * Q: Ok, I've found an {@link org.apache.tomcat.dbcp.pool2.ObjectPool ObjectPool} implementation that I think suits my + * connection pooling needs. But it wants a {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory PooledObjectFactory}. + * What should I use for that? + * </p> + * <p> + * A: The DBCP package provides a class for this purpose. It's called + * {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory}. It implements the factory and lifecycle methods of + * {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory} for {@link java.sql.Connection}s. But it doesn't create the + * actual database {@link java.sql.Connection}s itself, it uses a {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} for + * that. The {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory} will take {@link java.sql.Connection}s created + * by the {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} and wrap them with classes that implement the pooling + * behaviour. + * </p> + * <p> + * Several implementations of {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} are provided--one that uses + * {@link java.sql.DriverManager} to create connections + * ({@link org.apache.tomcat.dbcp.dbcp2.DriverManagerConnectionFactory}), one that uses a {@link java.sql.Driver} to create + * connections ({@link org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory}), one that uses a {@link javax.sql.DataSource} + * to create connections ({@link org.apache.tomcat.dbcp.dbcp2.DataSourceConnectionFactory}). + * </p> + * <p> + * Q: I think I'm starting to get it, but can you walk me though it again? + * </p> + * <p> + * A: Sure. Let's assume you want to create a {@link javax.sql.DataSource} that pools {@link java.sql.Connection}s. + * Let's also assume that those pooled {@link java.sql.Connection}s should be obtained from the + * {@link java.sql.DriverManager}. You'll want to create a {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource}. + * </p> + * <p> + * The {@link org.apache.tomcat.dbcp.dbcp2.PoolingDataSource} uses an underlying {@link org.apache.tomcat.dbcp.pool2.ObjectPool} + * to create and store its {@link java.sql.Connection}. + * </p> + * <p> + * To create a {@link org.apache.tomcat.dbcp.pool2.ObjectPool}, you'll need a + * {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory} that creates the actual {@link java.sql.Connection}s. That's + * what {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory} is for. + * </p> + * <p> + * To create the {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory}, you'll need at least two things: + * </p> + * <ol> + * <li>A {@link org.apache.tomcat.dbcp.dbcp2.ConnectionFactory} from which the actual database {@link java.sql.Connection}s + * will be obtained.</li> + * <li>An empty and factory-less {@link org.apache.tomcat.dbcp.pool2.ObjectPool} in which the {@link java.sql.Connection}s + * will be stored. <br> * When you pass an {@link org.apache.tomcat.dbcp.pool2.ObjectPool} into the - * {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory}, it will - * automatically register itself as the {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory} - * for that pool. - * </li> - * </ol> - * <p> - * In code, that might look like this: - * </p> - * <pre>GenericObjectPool connectionPool = new GenericObjectPool(null); - * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "username", "password"); - * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true); - * PoolingDataSource dataSource = new PoolingDataSource(connectionPool);</pre> - * <p> - * To create a {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver}, we do the same thing, - * except that instead of creating a {@link javax.sql.DataSource} on the last line, - * we create a {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver}, and register the - * {@code connectionPool} with it. E.g.,:</p> - * <pre>GenericObjectPool connectionPool = new GenericObjectPool(null); - * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "username", "password"); - * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true); + * {@link org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory}, it will automatically register itself as the + * {@link org.apache.tomcat.dbcp.pool2.PooledObjectFactory} for that pool.</li> + * </ol> + * <p> + * In code, that might look like this: + * </p> + * + * <pre> + * GenericObjectPool connectionPool = new GenericObjectPool(null); + * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "userName", + * "password"); + * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, + * connectionPool, null, null, false, true); + * PoolingDataSource dataSource = new PoolingDataSource(connectionPool); + * </pre> + * <p> + * To create a {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver}, we do the same thing, except that instead of creating a + * {@link javax.sql.DataSource} on the last line, we create a {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver}, and + * register the {@code connectionPool} with it. E.g.,: + * </p> + * + * <pre> + * GenericObjectPool connectionPool = new GenericObjectPool(null); + * ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string", "userName", + * "password"); + * PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, + * connectionPool, null, null, false, true); * PoolingDriver driver = new PoolingDriver(); - * driver.registerPool("example",connectionPool);</pre> + * driver.registerPool("example", connectionPool); + * </pre> * <p> - * Since the {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver} registers itself - * with the {@link java.sql.DriverManager} when it is created, now you can just - * go to the {@link java.sql.DriverManager} to create your {@link java.sql.Connection}s, - * like you normally would:</p> - * <pre>Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");</pre> + * Since the {@link org.apache.tomcat.dbcp.dbcp2.PoolingDriver} registers itself with the {@link java.sql.DriverManager} + * when it is created, now you can just go to the {@link java.sql.DriverManager} to create your + * {@link java.sql.Connection}s, like you normally would: + * </p> + * + * <pre> + * Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example"); + * </pre> */ package org.apache.tomcat.dbcp.dbcp2; Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1833794&r1=1833793&r2=1833794&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Jun 19 09:04:08 2018 @@ -335,9 +335,12 @@ 1.0.2o. (markt) </update> <update> - <bug>62458</bug>: Update the internal fork of Commons Pool to dfef97b + <bug>62458</bug>: Update the internal fork of Commons Pool 2 to dfef97b (2018-06-18) to pick up some bug fixes and enhancements. (markt) </update> + <update> + Update the internal fork of Commons DBCP 2 to 2.4.0. (markt) + </update> </changelog> </subsection> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org