Added:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnection.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnection.java?rev=1828065&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnection.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnection.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,80 @@
+/*
+ * 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.dbcp.dbcp2.managed;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collection;
+
+import org.apache.tomcat.dbcp.dbcp2.PoolableConnection;
+import org.apache.tomcat.dbcp.pool2.ObjectPool;
+
+/**
+ * PoolableConnection that unregisters from TransactionRegistry on Connection
real destroy.
+ *
+ * @see PoolableConnection
+ * @since 2.0
+ */
+public class PoolableManagedConnection extends PoolableConnection {
+ private final TransactionRegistry transactionRegistry;
+
+
+ /**
+ * Create a PoolableManagedConnection.
+ *
+ * @param transactionRegistry transaction registry
+ * @param conn underlying connection
+ * @param pool connection pool
+ */
+ public PoolableManagedConnection(final TransactionRegistry
transactionRegistry,
+ final Connection conn, final ObjectPool<PoolableConnection> pool) {
+ this(transactionRegistry, conn, pool, null, false);
+ }
+
+
+ /**
+ * Create a PoolableManagedConnection.
+ *
+ * @param transactionRegistry transaction registry
+ * @param conn underlying connection
+ * @param pool connection pool
+ * @param disconnectSqlCodes SQL_STATE codes considered fatal
disconnection errors
+ * @param fastFailValidation true means fatal disconnection errors cause
subsequent
+ * validations to fail immediately (no attempt to run query or
isValid)
+ */
+ public PoolableManagedConnection(final TransactionRegistry
transactionRegistry,
+ final Connection conn, final ObjectPool<PoolableConnection> pool,
+ final Collection<String> disconnectSqlCodes,
+ final boolean fastFailValidation) {
+ super(conn, pool, null, disconnectSqlCodes, fastFailValidation);
+ this.transactionRegistry = transactionRegistry;
+ }
+
+
+ /**
+ * Actually close the underlying connection.
+ */
+ @Override
+ public void reallyClose() throws SQLException {
+ try {
+ super.reallyClose();
+ } finally {
+ transactionRegistry.unregisterConnection(this);
+ }
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnectionFactory.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnectionFactory.java?rev=1828065&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnectionFactory.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnectionFactory.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,101 @@
+/*
+ * 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.dbcp.dbcp2.managed;
+
+import java.sql.Connection;
+
+import javax.management.ObjectName;
+
+import org.apache.tomcat.dbcp.dbcp2.Constants;
+import org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement;
+import org.apache.tomcat.dbcp.dbcp2.PStmtKey;
+import org.apache.tomcat.dbcp.dbcp2.PoolableConnection;
+import org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory;
+import org.apache.tomcat.dbcp.dbcp2.PoolingConnection;
+import org.apache.tomcat.dbcp.pool2.KeyedObjectPool;
+import org.apache.tomcat.dbcp.pool2.PooledObject;
+import org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject;
+import org.apache.tomcat.dbcp.pool2.impl.GenericKeyedObjectPool;
+import org.apache.tomcat.dbcp.pool2.impl.GenericKeyedObjectPoolConfig;
+
+/**
+ * A {@link PoolableConnectionFactory} that creates {@link
PoolableManagedConnection}s.
+ *
+ * @since 2.0
+ */
+public class PoolableManagedConnectionFactory extends
PoolableConnectionFactory {
+
+ /** Transaction registry associated with connections created by this
factory */
+ private final TransactionRegistry transactionRegistry;
+
+ /**
+ * Create a PoolableManagedConnectionFactory and attach it to a connection
pool.
+ *
+ * @param connFactory XAConnectionFactory
+ */
+ public PoolableManagedConnectionFactory(final XAConnectionFactory
connFactory,
+ final ObjectName dataSourceJmxName) {
+ super(connFactory, dataSourceJmxName);
+ this.transactionRegistry = connFactory.getTransactionRegistry();
+ }
+
+ /**
+ * Uses the configured XAConnectionFactory to create a {@link
PoolableManagedConnection}.
+ * Throws <code>IllegalStateException</code> if the connection factory
returns null.
+ * Also initializes the connection using configured initialization sql (if
provided)
+ * and sets up a prepared statement pool associated with the
PoolableManagedConnection
+ * if statement pooling is enabled.
+ */
+ @Override
+ public synchronized PooledObject<PoolableConnection> makeObject() throws
Exception {
+ Connection conn = getConnectionFactory().createConnection();
+ if (conn == null) {
+ throw new IllegalStateException("Connection factory returned null
from createConnection");
+ }
+ initializeConnection(conn);
+ if (getPoolStatements()) {
+ conn = new PoolingConnection(conn);
+ final GenericKeyedObjectPoolConfig config = new
GenericKeyedObjectPoolConfig();
+ config.setMaxTotalPerKey(-1);
+ config.setBlockWhenExhausted(false);
+ config.setMaxWaitMillis(0);
+ config.setMaxIdlePerKey(1);
+ config.setMaxTotal(getMaxOpenPreparedStatements());
+ final ObjectName dataSourceJmxName = getDataSourceJmxName();
+ final long connIndex = getConnectionIndex().getAndIncrement();
+ if (dataSourceJmxName != null) {
+ final StringBuilder base = new
StringBuilder(dataSourceJmxName.toString());
+ base.append(Constants.JMX_CONNECTION_BASE_EXT);
+ base.append(Long.toString(connIndex));
+ config.setJmxNameBase(base.toString());
+ config.setJmxNamePrefix(Constants.JMX_STATEMENT_POOL_PREFIX);
+ } else {
+ config.setJmxEnabled(false);
+ }
+ final KeyedObjectPool<PStmtKey,DelegatingPreparedStatement>
stmtPool =
+ new GenericKeyedObjectPool<>((PoolingConnection)conn, config);
+ ((PoolingConnection)conn).setStatementPool(stmtPool);
+ ((PoolingConnection) conn).setCacheState(getCacheState());
+ }
+ final PoolableManagedConnection pmc =
+ new PoolableManagedConnection(transactionRegistry, conn,
getPool(),
+ getDisconnectionSqlCodes(), isFastFailValidation());
+ pmc.setCacheState(getCacheState());
+ return new DefaultPooledObject<PoolableConnection>(pmc);
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnectionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContext.java?rev=1828065&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContext.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContext.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,157 @@
+/**
+ *
+ * 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.dbcp.dbcp2.managed;
+
+import java.lang.ref.WeakReference;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.xa.XAResource;
+
+/**
+ * TransactionContext represents the association between a single
XAConnectionFactory and a Transaction.
+ * This context contains a single shared connection which should be used by
all ManagedConnections for
+ * the XAConnectionFactory, the ability to listen for the transaction
completion event, and a method
+ * to check the status of the transaction.
+ *
+ * @author Dain Sundstrom
+ * @since 2.0
+ */
+public class TransactionContext {
+ private final TransactionRegistry transactionRegistry;
+ private final WeakReference<Transaction> transactionRef;
+ private Connection sharedConnection;
+
+ /**
+ * Creates a TransactionContext for the specified Transaction and
TransactionRegistry. The
+ * TransactionRegistry is used to obtain the XAResource for the shared
connection when it is
+ * enlisted in the transaction.
+ *
+ * @param transactionRegistry the TransactionRegistry used to obtain the
XAResource for the
+ * shared connection
+ * @param transaction the transaction
+ */
+ public TransactionContext(final TransactionRegistry transactionRegistry,
final Transaction transaction) {
+ if (transactionRegistry == null) {
+ throw new NullPointerException("transactionRegistry is null");
+ }
+ if (transaction == null) {
+ throw new NullPointerException("transaction is null");
+ }
+ this.transactionRegistry = transactionRegistry;
+ this.transactionRef = new WeakReference<>(transaction);
+ }
+
+ /**
+ * Gets the connection shared by all ManagedConnections in the
transaction. Specifically,
+ * connection using the same XAConnectionFactory from which the
TransactionRegistry was
+ * obtained.
+ * @return the shared connection for this transaction
+ */
+ public Connection getSharedConnection() {
+ return sharedConnection;
+ }
+
+ /**
+ * Sets the shared connection for this transaction. The shared connection
is enlisted
+ * in the transaction.
+ *
+ * @param sharedConnection the shared connection
+ * @throws SQLException if a shared connection is already set, if
XAResource for the connection
+ * could not be found in the transaction registry, or if there was a
problem enlisting the
+ * connection in the transaction
+ */
+ public void setSharedConnection(final Connection sharedConnection) throws
SQLException {
+ if (this.sharedConnection != null) {
+ throw new IllegalStateException("A shared connection is already
set");
+ }
+
+ // This is the first use of the connection in this transaction, so we
must
+ // enlist it in the transaction
+ final Transaction transaction = getTransaction();
+ try {
+ final XAResource xaResource =
transactionRegistry.getXAResource(sharedConnection);
+ if ( !transaction.enlistResource(xaResource) ) {
+ throw new SQLException("Unable to enlist connection in
transaction: enlistResource returns 'false'.");
+ }
+ } catch (final RollbackException e) {
+ // transaction was rolled back... proceed as if there never was a
transaction
+ } catch (final SystemException e) {
+ throw new SQLException("Unable to enlist connection the
transaction", e);
+ }
+
+ this.sharedConnection = sharedConnection;
+ }
+
+ /**
+ * Adds a listener for transaction completion events.
+ *
+ * @param listener the listener to add
+ * @throws SQLException if a problem occurs adding the listener to the
transaction
+ */
+ public void addTransactionContextListener(final TransactionContextListener
listener) throws SQLException {
+ try {
+ getTransaction().registerSynchronization(new Synchronization() {
+ @Override
+ public void beforeCompletion() {
+ }
+
+ @Override
+ public void afterCompletion(final int status) {
+ listener.afterCompletion(TransactionContext.this, status
== Status.STATUS_COMMITTED);
+ }
+ });
+ } catch (final RollbackException e) {
+ // JTA spec doesn't let us register with a transaction marked
rollback only
+ // just ignore this and the tx state will be cleared another way.
+ } catch (final Exception e) {
+ throw new SQLException("Unable to register transaction context
listener", e);
+ }
+ }
+
+ /**
+ * True if the transaction is active or marked for rollback only.
+ * @return true if the transaction is active or marked for rollback only;
false otherwise
+ * @throws SQLException if a problem occurs obtaining the transaction
status
+ */
+ public boolean isActive() throws SQLException {
+ try {
+ final Transaction transaction = this.transactionRef.get();
+ if (transaction == null) {
+ return false;
+ }
+ final int status = transaction.getStatus();
+ return status == Status.STATUS_ACTIVE || status ==
Status.STATUS_MARKED_ROLLBACK;
+ } catch (final SystemException e) {
+ throw new SQLException("Unable to get transaction status", e);
+ }
+ }
+
+ private Transaction getTransaction() throws SQLException {
+ final Transaction transaction = this.transactionRef.get();
+ if (transaction == null) {
+ throw new SQLException("Unable to enlist connection because the
transaction has been garbage collected");
+ }
+ return transaction;
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContextListener.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContextListener.java?rev=1828065&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContextListener.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContextListener.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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.dbcp.dbcp2.managed;
+
+/**
+ * A listener for transaction completion events.
+ *
+ * @author Dain Sundstrom
+ * @since 2.0
+ */
+public interface TransactionContextListener {
+ /**
+ * Occurs after the transaction commits or rolls back.
+ * @param transactionContext the transaction context that completed
+ * @param commited true if the transaction committed; false otherwise
+ */
+ void afterCompletion(TransactionContext transactionContext, boolean
commited);
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContextListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
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=1828065&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,148 @@
+/**
+ *
+ * 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.dbcp.dbcp2.managed;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+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<Connection, XAResource> xaResources = new
WeakHashMap<>();
+
+ /**
+ * Creates a TransactionRegistry for the specified transaction manager.
+ * @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.
+ *
+ * @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");
+ }
+ 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
+ */
+ public synchronized XAResource getXAResource(final Connection connection)
throws SQLException {
+ if (connection == null) {
+ throw new NullPointerException("connection is null");
+ }
+ final Connection key = getConnectionKey(connection);
+ final XAResource xaResource = xaResources.get(key);
+ if (xaResource == null) {
+ throw new SQLException("Connection does not have a registered
XAResource " + connection);
+ }
+ return xaResource;
+ }
+
+ /**
+ * 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
+ */
+ public TransactionContext getActiveTransactionContext() throws
SQLException {
+ Transaction transaction = null;
+ try {
+ transaction = transactionManager.getTransaction();
+
+ // was there a transaction?
+ if (transaction == null) {
+ return null;
+ }
+
+ // is it active
+ final int status = transaction.getStatus();
+ if (status != Status.STATUS_ACTIVE && status !=
Status.STATUS_MARKED_ROLLBACK) {
+ return null;
+ }
+ } catch (final SystemException e) {
+ throw new SQLException("Unable to determine current transaction ",
e);
+ }
+
+ // register the the context (or create a new one)
+ synchronized (this) {
+ TransactionContext cache = caches.get(transaction);
+ if (cache == null) {
+ cache = new TransactionContext(this, transaction);
+ caches.put(transaction, cache);
+ }
+ return cache;
+ }
+ }
+
+ /**
+ * Unregisters a destroyed connection from {@link TransactionRegistry}
+ * @param connection
+ */
+ 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) {
+ result = ((DelegatingConnection<?>)
connection).getInnermostDelegateInternal();
+ } else {
+ result = connection;
+ }
+ return result;
+ }
+}
+
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
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=1828065&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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.dbcp.dbcp2.managed;
+
+import java.sql.Connection;
+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.
+ *
+ * @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.
+ *
+ * @return the transaction registry for this connection factory
+ */
+ TransactionRegistry getTransactionRegistry();
+
+ /**
+ * 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.
+ * </p>
+ *
+ * @return a new {@link java.sql.Connection}
+ * @throws java.sql.SQLException if a database error occurs creating the
connection
+ */
+ @Override
+ Connection createConnection() throws SQLException;
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/package-info.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/package-info.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/package-info.java
(added)
+++ tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/package-info.java
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+/**
+ * <p>
+ * This package provides support for pooling of ManagedConnections. A managed
+ * connection is responsible for managing a database connection in a
+ * transactional environment (typically called <i>Container Managed</i>).
+ * A managed connection operates like any other connection when no global
+ * transaction (a.k.a. XA transaction or JTA Transaction) is in progress.
+ * When a global transaction is active a single physical connection to the
+ * database is used by all ManagedConnections accessed in the scope of the
+ * transaction. Connection sharing means that all data access during a
+ * transaction has a consistent view of the database. When the global
+ * transaction is committed or rolled back the enlisted connections are
+ * committed or rolled back.
+ * </p>
+
+ * <p>
+ * This package supports full XADataSources and non-XA data sources using
+ * local transaction semantics. non-XA data sources commit and rollback as
+ * part of the transaction but are not recoverable in the case of an error
+ * because they do not implement the two-phase commit protocol.
+ * </p>
+ */
+package org.apache.tomcat.dbcp.dbcp2.managed;
Propchange:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/res/checkstyle/javax-import-control.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/res/checkstyle/javax-import-control.xml?rev=1828065&r1=1828064&r2=1828065&view=diff
==============================================================================
--- tomcat/trunk/res/checkstyle/javax-import-control.xml (original)
+++ tomcat/trunk/res/checkstyle/javax-import-control.xml Fri Mar 30 14:15:56
2018
@@ -65,6 +65,9 @@
<allow pkg="javax.servlet.jsp"/>
</subpackage>
</subpackage>
+ <subpackage name="transaction">
+ <allow pkg="javax.transaction"/>
+ </subpackage>
<subpackage name="websocket">
<allow pkg="javax.websocket"/>
</subpackage>
Modified: tomcat/trunk/res/checkstyle/org-import-control.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/res/checkstyle/org-import-control.xml?rev=1828065&r1=1828064&r2=1828065&view=diff
==============================================================================
--- tomcat/trunk/res/checkstyle/org-import-control.xml (original)
+++ tomcat/trunk/res/checkstyle/org-import-control.xml Fri Mar 30 14:15:56 2018
@@ -133,6 +133,9 @@
<subpackage name="dbcp2">
<allow pkg="org.apache.tomcat.dbcp.dbcp2"/>
<allow pkg="org.apache.tomcat.dbcp.pool2"/>
+ <subpackage name="managed">
+ <allow pkg="javax.transaction"/>
+ </subpackage>
</subpackage>
<subpackage name="pool2">
<subpackage name="impl">
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1828065&r1=1828064&r2=1828065&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Mar 30 14:15:56 2018
@@ -164,6 +164,10 @@
<add>
Always report the OS's umask when launching the JVM. (schultz)
</add>
+ <add>
+ Add managed connections package to the package renamed DBCP2 to provide
+ a complete DBCP2 in Tomcat. (remm)
+ </add>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]