Author: remm
Date: Fri Mar 30 14:15:56 2018
New Revision: 1828065

URL: http://svn.apache.org/viewvc?rev=1828065&view=rev
Log:
Add missing managed package to DBCP, so that it is possible to use it with a 
transaction manager. The removal was not actually documented, it simply stated 
DBCP2 was included so no change in the docs.
The transaction manager or user code will have to provide the object factory to 
create the BasicManagedDataSource instance and call setTransactionManager on it.

Added:
    tomcat/trunk/java/javax/transaction/
    tomcat/trunk/java/javax/transaction/HeuristicCommitException.java   (with 
props)
    tomcat/trunk/java/javax/transaction/HeuristicMixedException.java   (with 
props)
    tomcat/trunk/java/javax/transaction/HeuristicRollbackException.java   (with 
props)
    tomcat/trunk/java/javax/transaction/InvalidTransactionException.java   
(with props)
    tomcat/trunk/java/javax/transaction/NotSupportedException.java   (with 
props)
    tomcat/trunk/java/javax/transaction/RollbackException.java   (with props)
    tomcat/trunk/java/javax/transaction/Status.java   (with props)
    tomcat/trunk/java/javax/transaction/Synchronization.java   (with props)
    tomcat/trunk/java/javax/transaction/SystemException.java   (with props)
    tomcat/trunk/java/javax/transaction/Transaction.java   (with props)
    tomcat/trunk/java/javax/transaction/TransactionManager.java   (with props)
    tomcat/trunk/java/javax/transaction/TransactionRequiredException.java   
(with props)
    tomcat/trunk/java/javax/transaction/TransactionRolledbackException.java   
(with props)
    tomcat/trunk/java/javax/transaction/TransactionSynchronizationRegistry.java 
  (with props)
    tomcat/trunk/java/javax/transaction/UserTransaction.java   (with props)
    tomcat/trunk/java/javax/transaction/xa/
    tomcat/trunk/java/javax/transaction/xa/XAException.java   (with props)
    tomcat/trunk/java/javax/transaction/xa/XAResource.java   (with props)
    tomcat/trunk/java/javax/transaction/xa/Xid.java   (with props)
    tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/BasicManagedDataSource.java
   (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/DataSourceXAConnectionFactory.java
   (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/LocalXAConnectionFactory.java
   (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java   
(with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedDataSource.java   
(with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnection.java
   (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/PoolableManagedConnectionFactory.java
   (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContext.java  
 (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionContextListener.java
   (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/TransactionRegistry.java 
  (with props)
    
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/XAConnectionFactory.java 
  (with props)
    tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/package-info.java   
(with props)
Modified:
    tomcat/trunk/res/checkstyle/javax-import-control.xml
    tomcat/trunk/res/checkstyle/org-import-control.xml
    tomcat/trunk/webapps/docs/changelog.xml

Added: tomcat/trunk/java/javax/transaction/HeuristicCommitException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/HeuristicCommitException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/HeuristicCommitException.java (added)
+++ tomcat/trunk/java/javax/transaction/HeuristicCommitException.java Fri Mar 
30 14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class HeuristicCommitException extends java.lang.Exception {
+    public HeuristicCommitException() {
+        super();
+    }
+
+    public HeuristicCommitException(String msg) {
+        super(msg);
+    }
+}

Propchange: tomcat/trunk/java/javax/transaction/HeuristicCommitException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/HeuristicMixedException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/HeuristicMixedException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/HeuristicMixedException.java (added)
+++ tomcat/trunk/java/javax/transaction/HeuristicMixedException.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class HeuristicMixedException extends java.lang.Exception {
+    public HeuristicMixedException() {
+        super();
+    }
+
+    public HeuristicMixedException(String msg) {
+        super(msg);
+    }
+}

Propchange: tomcat/trunk/java/javax/transaction/HeuristicMixedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/HeuristicRollbackException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/HeuristicRollbackException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/HeuristicRollbackException.java (added)
+++ tomcat/trunk/java/javax/transaction/HeuristicRollbackException.java Fri Mar 
30 14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class HeuristicRollbackException extends java.lang.Exception {
+    public HeuristicRollbackException() {
+        super();
+    }
+
+    public HeuristicRollbackException(String msg) {
+        super(msg);
+    }
+}

Propchange: tomcat/trunk/java/javax/transaction/HeuristicRollbackException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/InvalidTransactionException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/InvalidTransactionException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/InvalidTransactionException.java (added)
+++ tomcat/trunk/java/javax/transaction/InvalidTransactionException.java Fri 
Mar 30 14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class InvalidTransactionException extends java.rmi.RemoteException {
+    public InvalidTransactionException() {
+        super();
+    }
+
+    public InvalidTransactionException(String msg) {
+        super(msg);
+    }
+}

Propchange: tomcat/trunk/java/javax/transaction/InvalidTransactionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/NotSupportedException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/NotSupportedException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/NotSupportedException.java (added)
+++ tomcat/trunk/java/javax/transaction/NotSupportedException.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class NotSupportedException extends java.lang.Exception {
+    public NotSupportedException() {
+        super();
+    }
+
+    public NotSupportedException(String msg) {
+        super(msg);
+    }
+}

Propchange: tomcat/trunk/java/javax/transaction/NotSupportedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/RollbackException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/RollbackException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/RollbackException.java (added)
+++ tomcat/trunk/java/javax/transaction/RollbackException.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class RollbackException extends java.lang.Exception {
+    public RollbackException() {
+        super();
+    }
+
+    public RollbackException(String msg) {
+        super(msg);
+    }
+}

Propchange: tomcat/trunk/java/javax/transaction/RollbackException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/Status.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/Status.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/Status.java (added)
+++ tomcat/trunk/java/javax/transaction/Status.java Fri Mar 30 14:15:56 2018
@@ -0,0 +1,30 @@
+/*
+ * 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 javax.transaction;
+
+public interface Status {
+    public static final int STATUS_ACTIVE = 0;
+    public static final int STATUS_MARKED_ROLLBACK = 1;
+    public static final int STATUS_PREPARED = 2;
+    public static final int STATUS_COMMITTED = 3;
+    public static final int STATUS_ROLLEDBACK = 4;
+    public static final int STATUS_UNKNOWN = 5;
+    public static final int STATUS_NO_TRANSACTION = 6;
+    public static final int STATUS_PREPARING = 7;
+    public static final int STATUS_COMMITTING = 8;
+    public static final int STATUS_ROLLING_BACK = 9;
+}

Propchange: tomcat/trunk/java/javax/transaction/Status.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/Synchronization.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/Synchronization.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/Synchronization.java (added)
+++ tomcat/trunk/java/javax/transaction/Synchronization.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,22 @@
+/*
+ * 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 javax.transaction;
+
+public interface Synchronization {
+    public void beforeCompletion();
+    public void afterCompletion(int status);
+}

Propchange: tomcat/trunk/java/javax/transaction/Synchronization.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/SystemException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/SystemException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/SystemException.java (added)
+++ tomcat/trunk/java/javax/transaction/SystemException.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,36 @@
+/*
+ * 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 javax.transaction;
+
+public class SystemException extends java.lang.Exception {
+
+    public int errorCode;
+
+    public SystemException() {
+        super();
+    }
+
+    public SystemException(String s) {
+        super(s);
+    }
+
+    public SystemException(int errcode) {
+        super();
+        errorCode = errcode;
+    }
+
+}

Propchange: tomcat/trunk/java/javax/transaction/SystemException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/Transaction.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/Transaction.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/Transaction.java (added)
+++ tomcat/trunk/java/javax/transaction/Transaction.java Fri Mar 30 14:15:56 
2018
@@ -0,0 +1,42 @@
+/*
+ * 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 javax.transaction;
+
+import javax.transaction.xa.XAResource;
+
+public interface Transaction {
+
+    public void commit() throws RollbackException, HeuristicMixedException,
+            HeuristicRollbackException, SecurityException,
+            IllegalStateException, SystemException;
+
+    public boolean delistResource(XAResource xaRes, int flag)
+            throws IllegalStateException, SystemException;
+
+    public boolean enlistResource(XAResource xaRes)
+            throws RollbackException, IllegalStateException, SystemException;
+
+    public int getStatus() throws SystemException;
+
+    public void registerSynchronization(Synchronization sync)
+            throws RollbackException, IllegalStateException, SystemException;
+
+    public void rollback() throws IllegalStateException, SystemException;
+
+    public void setRollbackOnly() throws IllegalStateException, 
SystemException;
+
+}

Propchange: tomcat/trunk/java/javax/transaction/Transaction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/TransactionManager.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/TransactionManager.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/TransactionManager.java (added)
+++ tomcat/trunk/java/javax/transaction/TransactionManager.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,41 @@
+/*
+ * 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 javax.transaction;
+
+public interface TransactionManager {
+    public void begin() throws NotSupportedException, SystemException;
+
+    public void commit() throws RollbackException, HeuristicMixedException,
+            HeuristicRollbackException, SecurityException,
+            IllegalStateException, SystemException;
+
+    public int getStatus() throws SystemException;
+
+    public Transaction getTransaction() throws SystemException;
+
+    public void resume(Transaction tobj) throws InvalidTransactionException,
+            IllegalStateException, SystemException;
+
+    public void rollback()
+            throws IllegalStateException, SecurityException, SystemException;
+
+    public void setRollbackOnly() throws IllegalStateException, 
SystemException;
+
+    public void setTransactionTimeout(int seconds) throws SystemException;
+
+    public Transaction suspend() throws SystemException;
+}

Propchange: tomcat/trunk/java/javax/transaction/TransactionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/TransactionRequiredException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/TransactionRequiredException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/TransactionRequiredException.java 
(added)
+++ tomcat/trunk/java/javax/transaction/TransactionRequiredException.java Fri 
Mar 30 14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class TransactionRequiredException extends java.rmi.RemoteException {
+    public TransactionRequiredException() {
+        super();
+    }
+
+    public TransactionRequiredException(String msg) {
+        super(msg);
+    }
+}

Propchange: 
tomcat/trunk/java/javax/transaction/TransactionRequiredException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/TransactionRolledbackException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/TransactionRolledbackException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/TransactionRolledbackException.java 
(added)
+++ tomcat/trunk/java/javax/transaction/TransactionRolledbackException.java Fri 
Mar 30 14:15:56 2018
@@ -0,0 +1,27 @@
+/*
+ * 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 javax.transaction;
+
+public class TransactionRolledbackException extends java.rmi.RemoteException {
+    public TransactionRolledbackException() {
+        super();
+    }
+
+    public TransactionRolledbackException(String msg) {
+        super(msg);
+    }
+}

Propchange: 
tomcat/trunk/java/javax/transaction/TransactionRolledbackException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/java/javax/transaction/TransactionSynchronizationRegistry.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/TransactionSynchronizationRegistry.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/TransactionSynchronizationRegistry.java 
(added)
+++ tomcat/trunk/java/javax/transaction/TransactionSynchronizationRegistry.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 javax.transaction;
+
+public interface TransactionSynchronizationRegistry {
+    Object getTransactionKey();
+
+    void putResource(Object key, Object value);
+
+    Object getResource(Object key);
+
+    void registerInterposedSynchronization(Synchronization sync);
+
+    int getTransactionStatus();
+
+    void setRollbackOnly();
+
+    boolean getRollbackOnly();
+}

Propchange: 
tomcat/trunk/java/javax/transaction/TransactionSynchronizationRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/UserTransaction.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/UserTransaction.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/UserTransaction.java (added)
+++ tomcat/trunk/java/javax/transaction/UserTransaction.java Fri Mar 30 
14:15:56 2018
@@ -0,0 +1,34 @@
+/*
+ * 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 javax.transaction;
+
+public interface UserTransaction {
+    void begin() throws NotSupportedException, SystemException;
+
+    void commit() throws RollbackException, HeuristicMixedException,
+            HeuristicRollbackException, SecurityException,
+            IllegalStateException, SystemException;
+
+    void rollback()
+            throws IllegalStateException, SecurityException, SystemException;
+
+    void setRollbackOnly() throws IllegalStateException, SystemException;
+
+    int getStatus() throws SystemException;
+
+    void setTransactionTimeout(int seconds) throws SystemException;
+}

Propchange: tomcat/trunk/java/javax/transaction/UserTransaction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/xa/XAException.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/xa/XAException.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/xa/XAException.java (added)
+++ tomcat/trunk/java/javax/transaction/xa/XAException.java Fri Mar 30 14:15:56 
2018
@@ -0,0 +1,62 @@
+/*
+ * 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 javax.transaction.xa;
+
+public class XAException extends java.lang.Exception {
+
+    public int errorCode;
+
+    public XAException() {
+        super();
+    }
+
+    public XAException(String s) {
+        super(s);
+    }
+
+    public XAException(int errcode) {
+        super();
+        errorCode = errcode;
+    }
+
+    public static final int XA_RBBASE = 100;
+    public static final int XA_RBROLLBACK = XA_RBBASE;
+    public static final int XA_RBCOMMFAIL = XA_RBBASE + 1;
+    public static final int XA_RBDEADLOCK = XA_RBBASE + 2;
+    public static final int XA_RBINTEGRITY = XA_RBBASE + 3;
+    public static final int XA_RBOTHER = XA_RBBASE + 4;
+    public static final int XA_RBPROTO = XA_RBBASE + 5;
+    public static final int XA_RBTIMEOUT = XA_RBBASE + 6;
+    public static final int XA_RBTRANSIENT = XA_RBBASE + 7;
+    public static final int XA_RBEND = XA_RBTRANSIENT;
+    public static final int XA_NOMIGRATE = 9;
+    public static final int XA_HEURHAZ = 8;
+    public static final int XA_HEURCOM = 7;
+    public static final int XA_HEURRB = 6;
+    public static final int XA_HEURMIX = 5;
+    public static final int XA_RETRY = 4;
+    public static final int XA_RDONLY = 3;
+    public static final int XAER_ASYNC = -2;
+    public static final int XAER_RMERR = -3;
+    public static final int XAER_NOTA = -4;
+    public static final int XAER_INVAL = -5;
+    public static final int XAER_PROTO = -6;
+    public static final int XAER_RMFAIL = -7;
+    public static final int XAER_DUPID = -8;
+    public static final int XAER_OUTSIDE = -9;
+
+}

Propchange: tomcat/trunk/java/javax/transaction/xa/XAException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/xa/XAResource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/xa/XAResource.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/xa/XAResource.java (added)
+++ tomcat/trunk/java/javax/transaction/xa/XAResource.java Fri Mar 30 14:15:56 
2018
@@ -0,0 +1,52 @@
+/*
+ * 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 javax.transaction.xa;
+
+public interface XAResource {
+    void commit(Xid xid, boolean onePhase) throws XAException;
+
+    void end(Xid xid, int flags) throws XAException;
+
+    void forget(Xid xid) throws XAException;
+
+    int getTransactionTimeout() throws XAException;
+
+    boolean isSameRM(XAResource xares) throws XAException;
+
+    int prepare(Xid xid) throws XAException;
+
+    Xid[] recover(int flag) throws XAException;
+
+    void rollback(Xid xid) throws XAException;
+
+    boolean setTransactionTimeout(int seconds) throws XAException;
+
+    void start(Xid xid, int flags) throws XAException;
+
+    public static final int TMENDRSCAN = 0x00800000;
+    public static final int TMFAIL = 0x20000000;
+    public static final int TMJOIN = 0x00200000;
+    public static final int TMNOFLAGS = 0x00000000;
+    public static final int TMONEPHASE = 0x40000000;
+    public static final int TMRESUME = 0x08000000;
+    public static final int TMSTARTRSCAN = 0x01000000;
+    public static final int TMSUCCESS = 0x04000000;
+    public static final int TMSUSPEND = 0x02000000;
+    public static final int XA_RDONLY = 0x00000003;
+    public static final int XA_OK = 0;
+
+}

Propchange: tomcat/trunk/java/javax/transaction/xa/XAResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/java/javax/transaction/xa/Xid.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/transaction/xa/Xid.java?rev=1828065&view=auto
==============================================================================
--- tomcat/trunk/java/javax/transaction/xa/Xid.java (added)
+++ tomcat/trunk/java/javax/transaction/xa/Xid.java Fri Mar 30 14:15:56 2018
@@ -0,0 +1,28 @@
+/*
+ * 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 javax.transaction.xa;
+
+public interface Xid {
+    static final int MAXGTRIDSIZE = 64;
+    static final int MAXBQUALSIZE = 64;
+
+    int getFormatId();
+
+    byte[] getGlobalTransactionId();
+
+    byte[] getBranchQualifier();
+}

Propchange: tomcat/trunk/java/javax/transaction/xa/Xid.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/BasicManagedDataSource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/BasicManagedDataSource.java?rev=1828065&view=auto
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/BasicManagedDataSource.java
 (added)
+++ 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/BasicManagedDataSource.java
 Fri Mar 30 14:15:56 2018
@@ -0,0 +1,213 @@
+/**
+ *
+ * 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.SQLException;
+
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+import javax.transaction.TransactionManager;
+
+import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
+import org.apache.tomcat.dbcp.dbcp2.ConnectionFactory;
+import org.apache.tomcat.dbcp.dbcp2.PoolableConnection;
+import org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory;
+import org.apache.tomcat.dbcp.dbcp2.PoolingDataSource;
+
+/**
+ * <p>BasicManagedDataSource is an extension of BasicDataSource which
+ * creates ManagedConnections.  This data source can create either
+ * full two-phase-commit XA connections or one-phase-commit
+ * local connections.  Both types of connections are committed or
+ * rolled back as part of the global transaction (a.k.a. XA
+ * transaction or JTA Transaction), but only XA connections can be
+ * recovered in the case of a system crash.
+ * </p>
+ * <p>BasicManagedDataSource adds the TransactionManager and XADataSource
+ * properties.  The TransactionManager property is required and is
+ * used to enlist connections in global transactions.  The XADataSource
+ * is optional and if set is the class name of the XADataSource class
+ * for a two-phase-commit JDBC driver.  If the XADataSource property
+ * is set, the driverClassName is ignored and a DataSourceXAConnectionFactory
+ * is created. Otherwise, a standard DriverConnectionFactory is created
+ * and wrapped with a LocalXAConnectionFactory.
+ * </p>
+ *
+ * @see BasicDataSource
+ * @see ManagedConnection
+ * @since 2.0
+ */
+public class BasicManagedDataSource extends BasicDataSource {
+    /** Transaction Registry */
+    private TransactionRegistry transactionRegistry;
+    /** Transaction Manager */
+    private transient TransactionManager transactionManager;
+    /** XA datasource class name */
+    private String xaDataSource;
+    /** XA datasource instance */
+    private XADataSource xaDataSourceInstance;
+
+    /**
+     * Gets the XADataSource instance used by the XAConnectionFactory.
+     *
+     * @return the XADataSource
+     */
+    public synchronized XADataSource getXaDataSourceInstance() {
+        return xaDataSourceInstance;
+    }
+
+    /**
+     * <p>Sets the XADataSource instance used by the XAConnectionFactory.</p>
+     * <p>
+     * Note: this method currently has no effect once the pool has been
+     * initialized.  The pool is initialized the first time one of the
+     * following methods is invoked: <code>getConnection, setLogwriter,
+     * setLoginTimeout, getLoginTimeout, getLogWriter.</code></p>
+     *
+     * @param xaDataSourceInstance XADataSource instance
+     */
+    public synchronized void setXaDataSourceInstance(final XADataSource 
xaDataSourceInstance) {
+        this.xaDataSourceInstance = xaDataSourceInstance;
+        xaDataSource = xaDataSourceInstance == null ? null : 
xaDataSourceInstance.getClass().getName();
+    }
+
+    /**
+     * Gets the required transaction manager property.
+     * @return the transaction manager used to enlist connections
+     */
+    public TransactionManager getTransactionManager() {
+        return transactionManager;
+    }
+
+    /**
+     * Gets the transaction registry.
+     * @return the transaction registry associating XAResources with managed 
connections
+     */
+    protected synchronized TransactionRegistry getTransactionRegistry() {
+        return transactionRegistry;
+    }
+
+    /**
+     * Sets the required transaction manager property.
+     * @param transactionManager the transaction manager used to enlist 
connections
+     */
+    public void setTransactionManager(final TransactionManager 
transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    /**
+     * Gets the optional XADataSource class name.
+     * @return the optional XADataSource class name
+     */
+    public synchronized String getXADataSource() {
+        return xaDataSource;
+    }
+
+    /**
+     * Sets the optional XADataSource class name.
+     * @param xaDataSource the optional XADataSource class name
+     */
+    public synchronized void setXADataSource(final String xaDataSource) {
+        this.xaDataSource = xaDataSource;
+    }
+
+    @Override
+    protected ConnectionFactory createConnectionFactory() throws SQLException {
+        if (transactionManager == null) {
+            throw new SQLException("Transaction manager must be set before a 
connection can be created");
+        }
+
+        // If xa data source is not specified a DriverConnectionFactory is 
created and wrapped with a LocalXAConnectionFactory
+        if (xaDataSource == null) {
+            final ConnectionFactory connectionFactory = 
super.createConnectionFactory();
+            final XAConnectionFactory xaConnectionFactory = new 
LocalXAConnectionFactory(getTransactionManager(), connectionFactory);
+            transactionRegistry = xaConnectionFactory.getTransactionRegistry();
+            return xaConnectionFactory;
+        }
+
+        // Create the XADataSource instance using the configured class name if 
it has not been set
+        if (xaDataSourceInstance == null) {
+            Class<?> xaDataSourceClass = null;
+            try {
+                xaDataSourceClass = Class.forName(xaDataSource);
+            } catch (final Exception t) {
+                final String message = "Cannot load XA data source class '" + 
xaDataSource + "'";
+                throw new SQLException(message, t);
+            }
+
+            try {
+                xaDataSourceInstance = (XADataSource) 
xaDataSourceClass.newInstance();
+            } catch (final Exception t) {
+                final String message = "Cannot create XA data source of class 
'" + xaDataSource + "'";
+                throw new SQLException(message, t);
+            }
+        }
+
+        // finally, create the XAConnectionFactory using the XA data source
+        final XAConnectionFactory xaConnectionFactory = new 
DataSourceXAConnectionFactory(getTransactionManager(), xaDataSourceInstance, 
getUsername(), getPassword());
+        transactionRegistry = xaConnectionFactory.getTransactionRegistry();
+        return xaConnectionFactory;
+    }
+
+    @Override
+    protected DataSource createDataSourceInstance() throws SQLException {
+        final PoolingDataSource<PoolableConnection> pds =
+                new ManagedDataSource<>(getConnectionPool(), 
transactionRegistry);
+        
pds.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
+        return pds;
+    }
+
+    /**
+     * Creates the PoolableConnectionFactory and attaches it to the connection 
pool.
+     *
+     * @param driverConnectionFactory JDBC connection factory created by 
{@link #createConnectionFactory()}
+     * @throws SQLException if an error occurs creating the 
PoolableConnectionFactory
+     */
+    @Override
+    protected PoolableConnectionFactory createPoolableConnectionFactory(
+            final ConnectionFactory driverConnectionFactory) throws 
SQLException {
+        PoolableConnectionFactory connectionFactory = null;
+        try {
+            connectionFactory = new PoolableManagedConnectionFactory(
+                    (XAConnectionFactory) driverConnectionFactory, 
getRegisteredJmxName());
+            connectionFactory.setValidationQuery(getValidationQuery());
+            
connectionFactory.setValidationQueryTimeout(getValidationQueryTimeout());
+            connectionFactory.setConnectionInitSql(getConnectionInitSqls());
+            connectionFactory.setDefaultReadOnly(getDefaultReadOnly());
+            connectionFactory.setDefaultAutoCommit(getDefaultAutoCommit());
+            
connectionFactory.setDefaultTransactionIsolation(getDefaultTransactionIsolation());
+            connectionFactory.setDefaultCatalog(getDefaultCatalog());
+            connectionFactory.setCacheState(getCacheState());
+            connectionFactory.setPoolStatements(isPoolPreparedStatements());
+            connectionFactory.setMaxOpenPreparedStatements(
+                    getMaxOpenPreparedStatements());
+            
connectionFactory.setMaxConnLifetimeMillis(getMaxConnLifetimeMillis());
+            connectionFactory.setRollbackOnReturn(getRollbackOnReturn());
+            
connectionFactory.setEnableAutoCommitOnReturn(getEnableAutoCommitOnReturn());
+            connectionFactory.setDefaultQueryTimeout(getDefaultQueryTimeout());
+            connectionFactory.setFastFailValidation(getFastFailValidation());
+            
connectionFactory.setDisconnectionSqlCodes(getDisconnectionSqlCodes());
+            validateConnectionFactory(connectionFactory);
+        } catch (final RuntimeException e) {
+            throw e;
+        } catch (final Exception e) {
+            throw new SQLException("Cannot create PoolableConnectionFactory (" 
+ e.getMessage() + ")", e);
+        }
+        return connectionFactory;
+    }
+}

Propchange: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/BasicManagedDataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/DataSourceXAConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/DataSourceXAConnectionFactory.java?rev=1828065&view=auto
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/DataSourceXAConnectionFactory.java
 (added)
+++ 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/DataSourceXAConnectionFactory.java
 Fri Mar 30 14:15:56 2018
@@ -0,0 +1,149 @@
+/**
+ *
+ * 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 javax.sql.ConnectionEvent;
+import javax.sql.ConnectionEventListener;
+import javax.sql.PooledConnection;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+
+/**
+ * An implementation of XAConnectionFactory which uses a real XADataSource to 
obtain connections and XAResources.
+ *
+ * @author Dain Sundstrom
+ * @since 2.0
+ */
+public class DataSourceXAConnectionFactory implements XAConnectionFactory {
+    private final TransactionRegistry transactionRegistry;
+    private final XADataSource xaDataSource;
+    private String username;
+    private String password;
+
+    /**
+     * Creates an DataSourceXAConnectionFactory which uses the specified 
XADataSource to create database
+     * connections.  The connections are enlisted into transactions using the 
specified transaction manager.
+     *
+     * @param transactionManager the transaction manager in which connections 
will be enlisted
+     * @param xaDataSource the data source from which connections will be 
retrieved
+     */
+    public DataSourceXAConnectionFactory(final TransactionManager 
transactionManager, final XADataSource xaDataSource) {
+        this(transactionManager, xaDataSource, null, null);
+    }
+
+    /**
+     * Creates an DataSourceXAConnectionFactory which uses the specified 
XADataSource to create database
+     * connections.  The connections are enlisted into transactions using the 
specified transaction manager.
+     *
+     * @param transactionManager the transaction manager in which connections 
will be enlisted
+     * @param xaDataSource the data source from which connections will be 
retrieved
+     * @param username the username used for authenticating new connections or 
null for unauthenticated
+     * @param password the password used for authenticating new connections
+     */
+    public DataSourceXAConnectionFactory(final TransactionManager 
transactionManager, final XADataSource xaDataSource, final String username, 
final String password) {
+        if (transactionManager == null) {
+            throw new NullPointerException("transactionManager is null");
+        }
+        if (xaDataSource == null) {
+            throw new NullPointerException("xaDataSource is null");
+        }
+
+        this.transactionRegistry = new TransactionRegistry(transactionManager);
+        this.xaDataSource = xaDataSource;
+        this.username = username;
+        this.password = password;
+    }
+
+    /**
+     * Gets the username used to authenticate new connections.
+     * @return the user name or null if unauthenticated connections are used
+     */
+    public String getUsername() {
+        return username;
+    }
+
+    /**
+     * Sets the username used to authenticate new connections.
+     * @param username the username used for authenticating the connection or 
null for unauthenticated
+     */
+    public void setUsername(final String username) {
+        this.username = username;
+    }
+
+    /**
+     * Sets the password used to authenticate new connections.
+     * @param password the password used for authenticating the connection or 
null for unauthenticated
+     */
+    public void setPassword(final String password) {
+        this.password = password;
+    }
+
+    @Override
+    public TransactionRegistry getTransactionRegistry() {
+        return transactionRegistry;
+    }
+
+    @Override
+    public Connection createConnection() throws SQLException {
+        // create a new XAConnection
+        XAConnection xaConnection;
+        if (username == null) {
+            xaConnection = xaDataSource.getXAConnection();
+        } else {
+            xaConnection = xaDataSource.getXAConnection(username, password);
+        }
+
+        // get the real connection and XAResource from the connection
+        final Connection connection = xaConnection.getConnection();
+        final XAResource xaResource = xaConnection.getXAResource();
+
+        // register the xa resource for the connection
+        transactionRegistry.registerConnection(connection, xaResource);
+
+        // The Connection we're returning is a handle on the XAConnection.
+        // When the pool calling us closes the Connection, we need to
+        // also close the XAConnection that holds the physical connection.
+        xaConnection.addConnectionEventListener(new ConnectionEventListener() {
+
+            @Override
+            public void connectionClosed(final ConnectionEvent event) {
+                final PooledConnection pc = (PooledConnection) 
event.getSource();
+                pc.removeConnectionEventListener(this);
+                try {
+                    pc.close();
+                } catch (final SQLException e) {
+                    System.err.println("Failed to close XAConnection");
+                    e.printStackTrace();
+                }
+            }
+
+            @Override
+            public void connectionErrorOccurred(final ConnectionEvent event) {
+                connectionClosed(event);
+            }
+        });
+
+
+        return connection;
+    }
+}

Propchange: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/DataSourceXAConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/LocalXAConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/LocalXAConnectionFactory.java?rev=1828065&view=auto
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/LocalXAConnectionFactory.java
 (added)
+++ 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/LocalXAConnectionFactory.java
 Fri Mar 30 14:15:56 2018
@@ -0,0 +1,332 @@
+/**
+ *
+ * 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 javax.transaction.TransactionManager;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.apache.tomcat.dbcp.dbcp2.ConnectionFactory;
+
+/**
+ * An implementation of XAConnectionFactory which manages non-XA connections 
in XA transactions.  A non-XA connection
+ * commits and rolls back as part of the XA transaction, but is not 
recoverable since the connection does not implement
+ * the 2-phase protocol.
+ *
+ * @author Dain Sundstrom
+ * @since 2.0
+ */
+public class LocalXAConnectionFactory implements XAConnectionFactory {
+    private final TransactionRegistry transactionRegistry;
+    private final ConnectionFactory connectionFactory;
+
+    /**
+     * Creates an LocalXAConnectionFactory which uses the specified connection 
factory to create database
+     * connections.  The connections are enlisted into transactions using the 
specified transaction manager.
+     *
+     * @param transactionManager the transaction manager in which connections 
will be enlisted
+     * @param connectionFactory  the connection factory from which connections 
will be retrieved
+     */
+    public LocalXAConnectionFactory(final TransactionManager 
transactionManager, final ConnectionFactory connectionFactory) {
+        if (transactionManager == null) {
+            throw new NullPointerException("transactionManager is null");
+        }
+        if (connectionFactory == null) {
+            throw new NullPointerException("connectionFactory is null");
+        }
+
+        this.transactionRegistry = new TransactionRegistry(transactionManager);
+        this.connectionFactory = connectionFactory;
+    }
+
+    @Override
+    public TransactionRegistry getTransactionRegistry() {
+        return transactionRegistry;
+    }
+
+    @Override
+    public Connection createConnection() throws SQLException {
+        // create a new connection
+        final Connection connection = connectionFactory.createConnection();
+
+        // create a XAResource to manage the connection during XA transactions
+        final XAResource xaResource = new LocalXAResource(connection);
+
+        // register the xa resource for the connection
+        transactionRegistry.registerConnection(connection, xaResource);
+
+        return connection;
+    }
+
+    /**
+     * LocalXAResource is a fake XAResource for non-XA connections.  When a 
transaction is started
+     * the connection auto-commit is turned off.  When the connection is 
committed or rolled back,
+     * the commit or rollback method is called on the connection and then the 
original auto-commit
+     * value is restored.
+     * <p>
+     * The LocalXAResource also respects the connection read-only setting.  If 
the connection is
+     * read-only the commit method will not be called, and the prepare method 
returns the XA_RDONLY.
+     * </p>
+     * It is assumed that the wrapper around a managed connection disables the 
setAutoCommit(),
+     * commit(), rollback() and setReadOnly() methods while a transaction is 
in progress.
+     * @since 2.0
+     */
+    protected static class LocalXAResource implements XAResource {
+        private final Connection connection;
+        private Xid currentXid; // @GuardedBy("this")
+        private boolean originalAutoCommit; // @GuardedBy("this")
+
+        public LocalXAResource(final Connection localTransaction) {
+            this.connection = localTransaction;
+        }
+
+        /**
+         * Gets the current xid of the transaction branch associated with this 
XAResource.
+         *
+         * @return the current xid of the transaction branch associated with 
this XAResource.
+         */
+        public synchronized Xid getXid() {
+            return currentXid;
+        }
+
+        /**
+         * Signals that a the connection has been enrolled in a transaction.  
This method saves off the
+         * current auto commit flag, and then disables auto commit.  The 
original auto commit setting is
+         * restored when the transaction completes.
+         *
+         * @param xid  the id of the transaction branch for this connection
+         * @param flag either XAResource.TMNOFLAGS or XAResource.TMRESUME
+         * @throws XAException if the connection is already enlisted in 
another transaction, or if auto-commit
+         *                     could not be disabled
+         */
+        @Override
+        public synchronized void start(final Xid xid, final int flag) throws 
XAException {
+            if (flag == XAResource.TMNOFLAGS) {
+                // first time in this transaction
+
+                // make sure we aren't already in another tx
+                if (this.currentXid != null) {
+                    throw new XAException("Already enlisted in another 
transaction with xid " + xid);
+                }
+
+                // save off the current auto commit flag so it can be restored 
after the transaction completes
+                try {
+                    originalAutoCommit = connection.getAutoCommit();
+                } catch (final SQLException ignored) {
+                    // no big deal, just assume it was off
+                    originalAutoCommit = true;
+                }
+
+                // update the auto commit flag
+                try {
+                    connection.setAutoCommit(false);
+                } catch (final SQLException e) {
+                    throw (XAException) new XAException("Count not turn off 
auto commit for a XA transaction").initCause(e);
+                }
+
+                this.currentXid = xid;
+            } else if (flag == XAResource.TMRESUME) {
+                if (!xid.equals(this.currentXid)) {
+                    throw new XAException("Attempting to resume in different 
transaction: expected " + this.currentXid + ", but was " + xid);
+                }
+            } else {
+                throw new XAException("Unknown start flag " + flag);
+            }
+        }
+
+        /**
+         * This method does nothing.
+         *
+         * @param xid  the id of the transaction branch for this connection
+         * @param flag ignored
+         * @throws XAException if the connection is already enlisted in 
another transaction
+         */
+        @Override
+        public synchronized void end(final Xid xid, final int flag) throws 
XAException {
+            if (xid == null) {
+                throw new NullPointerException("xid is null");
+            }
+            if (!this.currentXid.equals(xid)) {
+                throw new XAException("Invalid Xid: expected " + 
this.currentXid + ", but was " + xid);
+            }
+
+            // This notification tells us that the application server is done 
using this
+            // connection for the time being.  The connection is still 
associated with an
+            // open transaction, so we must still wait for the commit or 
rollback method
+        }
+
+        /**
+         * This method does nothing since the LocalXAConnection does not 
support two-phase-commit.  This method
+         * will return XAResource.XA_RDONLY if the connection isReadOnly().  
This assumes that the physical
+         * connection is wrapped with a proxy that prevents an application 
from changing the read-only flag
+         * while enrolled in a transaction.
+         *
+         * @param xid the id of the transaction branch for this connection
+         * @return XAResource.XA_RDONLY if the connection.isReadOnly(); 
XAResource.XA_OK otherwise
+         */
+        @Override
+        public synchronized int prepare(final Xid xid) {
+            // if the connection is read-only, then the resource is read-only
+            // NOTE: this assumes that the outer proxy throws an exception 
when application code
+            // attempts to set this in a transaction
+            try {
+                if (connection.isReadOnly()) {
+                    // update the auto commit flag
+                    connection.setAutoCommit(originalAutoCommit);
+
+                    // tell the transaction manager we are read only
+                    return XAResource.XA_RDONLY;
+                }
+            } catch (final SQLException ignored) {
+                // no big deal
+            }
+
+            // this is a local (one phase) only connection, so we can't prepare
+            return XAResource.XA_OK;
+        }
+
+        /**
+         * Commits the transaction and restores the original auto commit 
setting.
+         *
+         * @param xid  the id of the transaction branch for this connection
+         * @param flag ignored
+         * @throws XAException if connection.commit() throws a SQLException
+         */
+        @Override
+        public synchronized void commit(final Xid xid, final boolean flag) 
throws XAException {
+            if (xid == null) {
+                throw new NullPointerException("xid is null");
+            }
+            if (this.currentXid == null) {
+                throw new XAException("There is no current transaction");
+            }
+            if (!this.currentXid.equals(xid)) {
+                throw new XAException("Invalid Xid: expected " +
+                        this.currentXid + ", but was " + xid);
+            }
+
+            try {
+                // make sure the connection isn't already closed
+                if (connection.isClosed()) {
+                    throw new XAException("Connection is closed");
+                }
+
+                // A read only connection should not be committed
+                if (!connection.isReadOnly()) {
+                    connection.commit();
+                }
+            } catch (final SQLException e) {
+                throw (XAException) new XAException().initCause(e);
+            } finally {
+                try {
+                    connection.setAutoCommit(originalAutoCommit);
+                } catch (final SQLException e) {
+                }
+                this.currentXid = null;
+            }
+        }
+
+        /**
+         * Rolls back the transaction and restores the original auto commit 
setting.
+         *
+         * @param xid the id of the transaction branch for this connection
+         * @throws XAException if connection.rollback() throws a SQLException
+         */
+        @Override
+        public synchronized void rollback(final Xid xid) throws XAException {
+            if (xid == null) {
+                throw new NullPointerException("xid is null");
+            }
+            if (!this.currentXid.equals(xid)) {
+                throw new XAException("Invalid Xid: expected " + 
this.currentXid + ", but was " + xid);
+            }
+
+            try {
+                connection.rollback();
+            } catch (final SQLException e) {
+                throw (XAException) new XAException().initCause(e);
+            } finally {
+                try {
+                    connection.setAutoCommit(originalAutoCommit);
+                } catch (final SQLException e) {
+                }
+                this.currentXid = null;
+            }
+        }
+
+        /**
+         * Returns true if the specified XAResource == this XAResource.
+         *
+         * @param xaResource the XAResource to test
+         * @return true if the specified XAResource == this XAResource; false 
otherwise
+         */
+        @Override
+        public boolean isSameRM(final XAResource xaResource) {
+            return this == xaResource;
+        }
+
+        /**
+         * Clears the currently associated transaction if it is the specified 
xid.
+         *
+         * @param xid the id of the transaction to forget
+         */
+        @Override
+        public synchronized void forget(final Xid xid) {
+            if (xid != null && xid.equals(currentXid)) {
+                currentXid = null;
+            }
+        }
+
+        /**
+         * Always returns a zero length Xid array.  The 
LocalXAConnectionFactory can not support recovery, so no xids will ever be 
found.
+         *
+         * @param flag ignored since recovery is not supported
+         * @return always a zero length Xid array.
+         */
+        @Override
+        public Xid[] recover(final int flag) {
+            return new Xid[0];
+        }
+
+        /**
+         * Always returns 0 since we have no way to set a transaction timeout 
on a JDBC connection.
+         *
+         * @return always 0
+         */
+        @Override
+        public int getTransactionTimeout() {
+            return 0;
+        }
+
+        /**
+         * Always returns false since we have no way to set a transaction 
timeout on a JDBC connection.
+         *
+         * @param transactionTimeout ignored since we have no way to set a 
transaction timeout on a JDBC connection
+         * @return always false
+         */
+        @Override
+        public boolean setTransactionTimeout(final int transactionTimeout) {
+            return false;
+        }
+    }
+
+}

Propchange: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/LocalXAConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java?rev=1828065&view=auto
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java 
(added)
+++ 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java 
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,281 @@
+/**
+ *
+ * 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.DelegatingConnection;
+import org.apache.tomcat.dbcp.pool2.ObjectPool;
+
+/**
+ * ManagedConnection is responsible for managing a database connection in a 
transactional environment
+ * (typically called "Container Managed").  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.  Typically upon
+ * transaction completion, a connection returns to the auto commit setting in 
effect before being
+ * enlisted in the transaction, but some vendors do not properly implement 
this.
+ *
+ * When enlisted in a transaction the setAutoCommit(), commit(), rollback(), 
and setReadOnly() methods
+ * throw a SQLException.  This is necessary to assure that the transaction 
completes as a single unit.
+ *
+ * @param <C> the Connection type
+ *
+ * @author Dain Sundstrom
+ * @since 2.0
+ */
+public class ManagedConnection<C extends Connection> extends 
DelegatingConnection<C> {
+    private final ObjectPool<C> pool;
+    private final TransactionRegistry transactionRegistry;
+    private final boolean accessToUnderlyingConnectionAllowed;
+    private TransactionContext transactionContext;
+    private boolean isSharedConnection;
+
+    public ManagedConnection(final ObjectPool<C> pool,
+            final TransactionRegistry transactionRegistry,
+            final boolean accessToUnderlyingConnectionAllowed) throws 
SQLException {
+        super(null);
+        this.pool = pool;
+        this.transactionRegistry = transactionRegistry;
+        this.accessToUnderlyingConnectionAllowed = 
accessToUnderlyingConnectionAllowed;
+        updateTransactionStatus();
+    }
+
+    @Override
+    protected void checkOpen() throws SQLException {
+        super.checkOpen();
+        updateTransactionStatus();
+    }
+
+    private void updateTransactionStatus() throws SQLException {
+        // if there is a is an active transaction context, assure the 
transaction context hasn't changed
+        if (transactionContext != null) {
+            if (transactionContext.isActive()) {
+                if (transactionContext != 
transactionRegistry.getActiveTransactionContext()) {
+                    throw new SQLException("Connection can not be used while 
enlisted in another transaction");
+                }
+                return;
+            }
+            // transaction should have been cleared up by 
TransactionContextListener, but in
+            // rare cases another lister could have registered which uses the 
connection before
+            // our listener is called.  In that rare case, trigger the 
transaction complete call now
+            transactionComplete();
+        }
+
+        // the existing transaction context ended (or we didn't have one), get 
the active transaction context
+        transactionContext = transactionRegistry.getActiveTransactionContext();
+
+        // if there is an active transaction context and it already has a 
shared connection, use it
+        if (transactionContext != null && 
transactionContext.getSharedConnection() != null) {
+            // A connection for the connection factory has already been 
enrolled
+            // in the transaction, replace our delegate with the enrolled 
connection
+
+            // return current connection to the pool
+            final C connection = getDelegateInternal();
+            setDelegate(null);
+            if (connection != null) {
+                try {
+                    pool.returnObject(connection);
+                } catch (final Exception ignored) {
+                    // whatever... try to invalidate the connection
+                    try {
+                        pool.invalidateObject(connection);
+                    } catch (final Exception ignore) {
+                        // no big deal
+                    }
+                }
+            }
+
+            // add a listener to the transaction context
+            transactionContext.addTransactionContextListener(new 
CompletionListener());
+
+            // Set our delegate to the shared connection. Note that this will
+            // always be of type C since it has been shared by another
+            // connection from the same pool.
+            @SuppressWarnings("unchecked")
+            final
+            C shared = (C) transactionContext.getSharedConnection();
+            setDelegate(shared);
+
+            // remember that we are using a shared connection so it can be 
cleared after the
+            // transaction completes
+            isSharedConnection = true;
+        } else {
+            C connection = getDelegateInternal();
+            // if our delegate is null, create one
+            if (connection == null) {
+                try {
+                    // borrow a new connection from the pool
+                    connection = pool.borrowObject();
+                    setDelegate(connection);
+                } catch (final Exception e) {
+                    throw new SQLException("Unable to acquire a new connection 
from the pool", e);
+                }
+            }
+
+            // if we have a transaction, out delegate becomes the shared 
delegate
+            if (transactionContext != null) {
+                // add a listener to the transaction context
+                transactionContext.addTransactionContextListener(new 
CompletionListener());
+
+                // register our connection as the shared connection
+                try {
+                    transactionContext.setSharedConnection(connection);
+                } catch (final SQLException e) {
+                    // transaction is hosed
+                    transactionContext = null;
+                    try {
+                        pool.invalidateObject(connection);
+                    } catch (final Exception e1) {
+                        // we are try but no luck
+                    }
+                    throw e;
+                }
+            }
+        }
+        // autoCommit may have been changed directly on the underlying
+        // connection
+        clearCachedState();
+    }
+
+    @Override
+    public void close() throws SQLException {
+        if (!isClosedInternal()) {
+            try {
+                // Don't actually close the connection if in a transaction. The
+                // connection will be closed by the transactionComplete method.
+                if (transactionContext == null) {
+                    super.close();
+                }
+            } finally {
+                setClosedInternal(true);
+            }
+        }
+    }
+
+    /**
+     * Delegates to {@link ManagedConnection#transactionComplete()}
+     * for transaction completion events.
+     * @since 2.0
+     */
+    protected class CompletionListener implements TransactionContextListener {
+        @Override
+        public void afterCompletion(final TransactionContext completedContext, 
final boolean commited) {
+            if (completedContext == transactionContext) {
+                transactionComplete();
+            }
+        }
+    }
+
+    protected void transactionComplete() {
+        transactionContext = null;
+
+        // If we were using a shared connection, clear the reference now that
+        // the transaction has completed
+        if (isSharedConnection) {
+            setDelegate(null);
+            isSharedConnection = false;
+        }
+
+        // If this connection was closed during the transaction and there is
+        // still a delegate present close it
+        final Connection delegate = getDelegateInternal();
+        if (isClosedInternal() && delegate != null) {
+            try {
+                setDelegate(null);
+
+                if (!delegate.isClosed()) {
+                    delegate.close();
+                }
+            } catch (final SQLException ignored) {
+                // Not a whole lot we can do here as connection is closed
+                // and this is a transaction callback so there is no
+                // way to report the error.
+            }
+        }
+    }
+
+    //
+    // The following methods can't be used while enlisted in a transaction
+    //
+
+    @Override
+    public void setAutoCommit(final boolean autoCommit) throws SQLException {
+        if (transactionContext != null) {
+            throw new SQLException("Auto-commit can not be set while enrolled 
in a transaction");
+        }
+        super.setAutoCommit(autoCommit);
+    }
+
+
+    @Override
+    public void commit() throws SQLException {
+        if (transactionContext != null) {
+            throw new SQLException("Commit can not be set while enrolled in a 
transaction");
+        }
+        super.commit();
+    }
+
+    @Override
+    public void rollback() throws SQLException {
+        if (transactionContext != null) {
+            throw new SQLException("Commit can not be set while enrolled in a 
transaction");
+        }
+        super.rollback();
+    }
+
+
+    @Override
+    public void setReadOnly(final boolean readOnly) throws SQLException {
+        if (transactionContext != null) {
+            throw new SQLException("Read-only can not be set while enrolled in 
a transaction");
+        }
+        super.setReadOnly(readOnly);
+    }
+
+    //
+    // Methods for accessing the delegate connection
+    //
+
+    /**
+     * If false, getDelegate() and getInnermostDelegate() will return null.
+     * @return if false, getDelegate() and getInnermostDelegate() will return 
null
+     */
+    public boolean isAccessToUnderlyingConnectionAllowed() {
+        return accessToUnderlyingConnectionAllowed;
+    }
+
+    @Override
+    public C getDelegate() {
+        if (isAccessToUnderlyingConnectionAllowed()) {
+            return getDelegateInternal();
+        }
+        return null;
+    }
+
+    @Override
+    public Connection getInnermostDelegate() {
+        if (isAccessToUnderlyingConnectionAllowed()) {
+            return super.getInnermostDelegateInternal();
+        }
+        return null;
+    }
+}

Propchange: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedDataSource.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedDataSource.java?rev=1828065&view=auto
==============================================================================
--- 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedDataSource.java 
(added)
+++ 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedDataSource.java 
Fri Mar 30 14:15:56 2018
@@ -0,0 +1,84 @@
+/**
+ *
+ * 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.PoolingDataSource;
+import org.apache.tomcat.dbcp.pool2.ObjectPool;
+
+/**
+ * The ManagedDataSource is a PoolingDataSource that creates 
ManagedConnections.
+ *
+ * @author Dain Sundstrom
+ * @param <C> The kind of {@link Connection} to manage.
+ * @since 2.0
+ */
+public class ManagedDataSource<C extends Connection> extends 
PoolingDataSource<C> {
+    private TransactionRegistry transactionRegistry;
+
+    /**
+     * Creates a ManagedDataSource which obtains connections from the 
specified pool and
+     * manages them using the specified transaction registry.  The 
TransactionRegistry must
+     * be the transaction registry obtained from the XAConnectionFactory used 
to create
+     * the connection pool.  If not, an error will occur when attempting to 
use the connection
+     * in a global transaction because the XAResource object associated with 
the connection
+     * will be unavailable.
+     *
+     * @param pool the connection pool
+     * @param transactionRegistry the transaction registry obtained from the
+     * XAConnectionFactory used to create the connection pool object factory
+     */
+    public ManagedDataSource(final ObjectPool<C> pool,
+            final TransactionRegistry transactionRegistry) {
+        super(pool);
+        this.transactionRegistry = transactionRegistry;
+    }
+
+    /**
+     * Sets the transaction registry from the XAConnectionFactory used to 
create the pool.
+     * The transaction registry can only be set once using either a connector 
or this setter
+     * method.
+     * @param transactionRegistry the transaction registry acquired from the 
XAConnectionFactory
+     * used to create the pool
+     */
+    public void setTransactionRegistry(final TransactionRegistry 
transactionRegistry) {
+        if(this.transactionRegistry != null) {
+            throw new IllegalStateException("TransactionRegistry already set");
+        }
+        if(transactionRegistry == null) {
+            throw new NullPointerException("TransactionRegistry is null");
+        }
+
+        this.transactionRegistry = transactionRegistry;
+    }
+
+    @Override
+    public Connection getConnection() throws SQLException {
+        if (getPool() == null) {
+            throw new IllegalStateException("Pool has not been set");
+        }
+        if (transactionRegistry == null) {
+            throw new IllegalStateException("TransactionRegistry has not been 
set");
+        }
+
+        final Connection connection = new ManagedConnection<>(getPool(), 
transactionRegistry, isAccessToUnderlyingConnectionAllowed());
+        return connection;
+    }
+}

Propchange: 
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedDataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native



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

Reply via email to