You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2016/02/17 16:19:33 UTC
svn commit: r1730855 - in /aries/trunk/tx-control: ./
tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/
tx-control-provider-jdbc-local/ tx-control-provider-jdbc-local/src/
tx-control-provider-jdbc-local/src/main/ tx-control-provid...
Author: timothyjward
Date: Wed Feb 17 15:19:32 2016
New Revision: 1730855
URL: http://svn.apache.org/viewvc?rev=1730855&view=rev
Log:
[tx-control] Basic local resource provider for JDBC
Added:
aries/trunk/tx-control/tx-control-provider-jdbc-local/
aries/trunk/tx-control/tx-control-provider-jdbc-local/.gitignore
aries/trunk/tx-control/tx-control-provider-jdbc-local/LICENSE
aries/trunk/tx-control/tx-control-provider-jdbc-local/NOTICE
aries/trunk/tx-control/tx-control-provider-jdbc-local/pom.xml
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ConnectionWrapper.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/DriverDataSource.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapper.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapper.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/Activator.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapperTest.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapperTest.java
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/
aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java
Modified:
aries/trunk/tx-control/pom.xml
aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java
Modified: aries/trunk/tx-control/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/pom.xml?rev=1730855&r1=1730854&r2=1730855&view=diff
==============================================================================
--- aries/trunk/tx-control/pom.xml (original)
+++ aries/trunk/tx-control/pom.xml Wed Feb 17 15:19:32 2016
@@ -36,5 +36,6 @@
<modules>
<module>tx-control-api</module>
<module>tx-control-service-local</module>
+ <module>tx-control-provider-jdbc-local</module>
</modules>
</project>
\ No newline at end of file
Modified: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java?rev=1730855&r1=1730854&r2=1730855&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java (original)
+++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/jdbc/JDBCConnectionProviderFactory.java Wed Feb 17 15:19:32 2016
@@ -119,11 +119,14 @@ public interface JDBCConnectionProviderF
* {@link Driver}.
*
* @param driver
+ * @param jdbcProperties The properties to pass to the {@link Driver} in
+ * order to create a {@link Connection}
* @param resourceProviderProperties Configuration properties to pass to the
* JDBC Resource Provider runtime
* @return A {@link JDBCConnectionProvider} that can be used in transactions
*/
JDBCConnectionProvider getProviderFor(Driver driver,
+ Properties jdbcProperties,
Map<String,Object> resourceProviderProperties);
/**
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/.gitignore
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/.gitignore?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/.gitignore (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/.gitignore Wed Feb 17 15:19:32 2016
@@ -0,0 +1 @@
+/target/
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/LICENSE
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/LICENSE?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/LICENSE (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/LICENSE Wed Feb 17 15:19:32 2016
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/NOTICE
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/NOTICE?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/NOTICE (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/NOTICE Wed Feb 17 15:19:32 2016
@@ -0,0 +1,8 @@
+
+Apache Aries
+Copyright 2009-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/pom.xml?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/pom.xml (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/pom.xml Wed Feb 17 15:19:32 2016
@@ -0,0 +1,121 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries</groupId>
+ <artifactId>parent</artifactId>
+ <version>2.0.1</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+ <groupId>org.apache.aries.tx-control</groupId>
+ <artifactId>tx-control-provider-jdbc-local</artifactId>
+ <packaging>bundle</packaging>
+ <name>OSGi Transaction Control JDBC Resource Provider - Local Transactions</name>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <description>
+ This bundle contains a JDBC resource provider for use with the OSGi Transaction Control Service that supports local transactions.
+ </description>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/aries/trunk/tx-control/tx-control-provider-jdbc-local
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/aries/trunk/tx-control/tx-control-provider-jdbc-local
+ </developerConnection>
+ <url>
+ http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local
+ </url>
+ </scm>
+
+ <properties>
+ <aries.osgi.activator>
+ org.apache.aries.tx.control.jdbc.local.impl.Activator
+ </aries.osgi.activator>
+ <aries.osgi.export.pkg>
+ org.osgi.service.transaction.control.jdbc,
+ org.osgi.service.jdbc
+ </aries.osgi.export.pkg>
+ <aries.osgi.private.pkg>
+ org.apache.aries.tx.control.jdbc.*,
+ com.zaxxer.hikari,
+ com.zaxxer.hikari.pool,
+ com.zaxxer.hikari.util
+ </aries.osgi.private.pkg>
+ <aries.osgi.import.pkg>
+ !com.codahale.*,
+ !com.zaxxer.hikari.metrics.*,
+ !javassist.*,
+ !javax.naming.*,
+ org.osgi.service.transaction.control.jdbc;version="[0.0.1,0.0.1]",
+ *
+ </aries.osgi.import.pkg>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.tx-control</groupId>
+ <artifactId>tx-control-api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.jdbc</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
+ <version>2.4.3</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.aries.versioning</groupId>
+ <artifactId>org.apache.aries.versioning.plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-verify</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>version-check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ConnectionWrapper.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ConnectionWrapper.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ConnectionWrapper.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ConnectionWrapper.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,262 @@
+package org.apache.aries.tx.control.jdbc.common.impl;
+
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.Executor;
+
+public abstract class ConnectionWrapper implements Connection {
+
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return getDelegate().unwrap(iface);
+ }
+
+ public boolean isWrapperFor(Class< ? > iface) throws SQLException {
+ return getDelegate().isWrapperFor(iface);
+ }
+
+ public Statement createStatement() throws SQLException {
+ return getDelegate().createStatement();
+ }
+
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ return getDelegate().prepareStatement(sql);
+ }
+
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ return getDelegate().prepareCall(sql);
+ }
+
+ public String nativeSQL(String sql) throws SQLException {
+ return getDelegate().nativeSQL(sql);
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ getDelegate().setAutoCommit(autoCommit);
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ return getDelegate().getAutoCommit();
+ }
+
+ public void commit() throws SQLException {
+ getDelegate().commit();
+ }
+
+ public void rollback() throws SQLException {
+ getDelegate().rollback();
+ }
+
+ public void close() throws SQLException {
+ getDelegate().close();
+ }
+
+ public boolean isClosed() throws SQLException {
+ return getDelegate().isClosed();
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ return getDelegate().getMetaData();
+ }
+
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ getDelegate().setReadOnly(readOnly);
+ }
+
+ public boolean isReadOnly() throws SQLException {
+ return getDelegate().isReadOnly();
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ getDelegate().setCatalog(catalog);
+ }
+
+ public String getCatalog() throws SQLException {
+ return getDelegate().getCatalog();
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ getDelegate().setTransactionIsolation(level);
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ return getDelegate().getTransactionIsolation();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getDelegate().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getDelegate().clearWarnings();
+ }
+
+ public Statement createStatement(int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ return getDelegate().createStatement(resultSetType, resultSetConcurrency);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ return getDelegate().prepareStatement(sql, resultSetType,
+ resultSetConcurrency);
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType,
+ int resultSetConcurrency) throws SQLException {
+ return getDelegate().prepareCall(sql, resultSetType, resultSetConcurrency);
+ }
+
+ public Map<String,Class< ? >> getTypeMap() throws SQLException {
+ return getDelegate().getTypeMap();
+ }
+
+ public void setTypeMap(Map<String,Class< ? >> map) throws SQLException {
+ getDelegate().setTypeMap(map);
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ getDelegate().setHoldability(holdability);
+ }
+
+ public int getHoldability() throws SQLException {
+ return getDelegate().getHoldability();
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ return getDelegate().setSavepoint();
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return getDelegate().setSavepoint(name);
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ getDelegate().rollback(savepoint);
+ }
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ getDelegate().releaseSavepoint(savepoint);
+ }
+
+ public Statement createStatement(int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return getDelegate().createStatement(resultSetType, resultSetConcurrency,
+ resultSetHoldability);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return getDelegate().prepareStatement(sql, resultSetType,
+ resultSetConcurrency, resultSetHoldability);
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return getDelegate().prepareCall(sql, resultSetType, resultSetConcurrency,
+ resultSetHoldability);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
+ throws SQLException {
+ return getDelegate().prepareStatement(sql, autoGeneratedKeys);
+ }
+
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
+ throws SQLException {
+ return getDelegate().prepareStatement(sql, columnIndexes);
+ }
+
+ public PreparedStatement prepareStatement(String sql, String[] columnNames)
+ throws SQLException {
+ return getDelegate().prepareStatement(sql, columnNames);
+ }
+
+ public Clob createClob() throws SQLException {
+ return getDelegate().createClob();
+ }
+
+ public Blob createBlob() throws SQLException {
+ return getDelegate().createBlob();
+ }
+
+ public NClob createNClob() throws SQLException {
+ return getDelegate().createNClob();
+ }
+
+ public SQLXML createSQLXML() throws SQLException {
+ return getDelegate().createSQLXML();
+ }
+
+ public boolean isValid(int timeout) throws SQLException {
+ return getDelegate().isValid(timeout);
+ }
+
+ public void setClientInfo(String name, String value)
+ throws SQLClientInfoException {
+ getDelegate().setClientInfo(name, value);
+ }
+
+ public void setClientInfo(Properties properties)
+ throws SQLClientInfoException {
+ getDelegate().setClientInfo(properties);
+ }
+
+ public String getClientInfo(String name) throws SQLException {
+ return getDelegate().getClientInfo(name);
+ }
+
+ public Properties getClientInfo() throws SQLException {
+ return getDelegate().getClientInfo();
+ }
+
+ public Array createArrayOf(String typeName, Object[] elements)
+ throws SQLException {
+ return getDelegate().createArrayOf(typeName, elements);
+ }
+
+ public Struct createStruct(String typeName, Object[] attributes)
+ throws SQLException {
+ return getDelegate().createStruct(typeName, attributes);
+ }
+
+ public void setSchema(String schema) throws SQLException {
+ getDelegate().setSchema(schema);
+ }
+
+ public String getSchema() throws SQLException {
+ return getDelegate().getSchema();
+ }
+
+ public void abort(Executor executor) throws SQLException {
+ getDelegate().abort(executor);
+ }
+
+ public void setNetworkTimeout(Executor executor, int milliseconds)
+ throws SQLException {
+ getDelegate().setNetworkTimeout(executor, milliseconds);
+ }
+
+ public int getNetworkTimeout() throws SQLException {
+ return getDelegate().getNetworkTimeout();
+ }
+
+ protected abstract Connection getDelegate();
+}
\ No newline at end of file
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/DriverDataSource.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/DriverDataSource.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/DriverDataSource.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/DriverDataSource.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,70 @@
+package org.apache.aries.tx.control.jdbc.common.impl;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import javax.sql.DataSource;
+
+public class DriverDataSource implements DataSource {
+
+ private final Driver driver;
+ private final String jdbcURL;
+ private final Properties properties;
+
+ public DriverDataSource(Driver driver, String jdbcURL, Properties properties) {
+ this.driver = driver;
+ this.jdbcURL = jdbcURL;
+ this.properties = properties;
+ }
+
+ @Override
+ public PrintWriter getLogWriter() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Driver based JDBC does not support log writing");
+ }
+
+ @Override
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Driver based JDBC does not support log writing");
+ }
+
+ @Override
+ public void setLoginTimeout(int seconds) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Driver based JDBC does not support login timeouts");
+ }
+
+ @Override
+ public int getLoginTimeout() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Driver based JDBC does not support login timeouts");
+ }
+
+ @Override
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ throw new SQLFeatureNotSupportedException("Driver based JDBC does not support log writing");
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Driver based JDBC does not support unwrapping");
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ return driver.connect(jdbcURL, properties);
+ }
+
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException {
+ return getConnection();
+ }
+
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapper.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapper.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapper.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapper.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,28 @@
+package org.apache.aries.tx.control.jdbc.common.impl;
+
+import java.sql.Connection;
+import java.util.concurrent.Executor;
+
+public class ScopedConnectionWrapper extends ConnectionWrapper {
+
+ private Connection delegate;
+
+ public ScopedConnectionWrapper(Connection delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ protected final Connection getDelegate() {
+ return delegate;
+ }
+
+ @Override
+ public void close() {
+ // A no-op
+ }
+
+ @Override
+ public void abort(Executor e) {
+ // A no-op
+ }
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapper.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapper.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapper.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapper.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,79 @@
+package org.apache.aries.tx.control.jdbc.common.impl;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Savepoint;
+import java.util.concurrent.Executor;
+
+import org.osgi.service.transaction.control.TransactionException;
+
+public class TxConnectionWrapper extends ConnectionWrapper {
+
+ private Connection delegate;
+
+ public TxConnectionWrapper(Connection delegate) {
+ this.delegate = delegate;
+ try {
+ delegate.setAutoCommit(false);
+ } catch (SQLException e) {
+ throw new TransactionException("Unable to disable autocommit");
+ }
+ }
+
+ @Override
+ protected final Connection getDelegate() {
+ return delegate;
+ }
+
+ @Override
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ throw new TransactionException(
+ "Auto-commit cannot be changed for a Transactional Connection");
+ }
+
+ @Override
+ public void commit() throws SQLException {
+ throw new TransactionException(
+ "Commit cannot be called for a Transactional Connection");
+ }
+
+ @Override
+ public void rollback() throws SQLException {
+ throw new TransactionException(
+ "Rollback cannot be called for a Transactional Connection");
+ }
+
+ @Override
+ public Savepoint setSavepoint() throws SQLException {
+ throw new TransactionException(
+ "Savepoints are not available for a Transactional Connection");
+ }
+
+ @Override
+ public Savepoint setSavepoint(String name) throws SQLException {
+ throw new TransactionException(
+ "Savepoints are not available for a Transactional Connection");
+ }
+
+ @Override
+ public void rollback(Savepoint savepoint) throws SQLException {
+ throw new TransactionException(
+ "Rollback cannot be called for a Transactional Connection");
+ }
+
+ @Override
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ throw new TransactionException(
+ "Savepoints are not available for a Transactional Connection");
+ }
+
+ @Override
+ public void close() {
+ // A no-op
+ }
+
+ @Override
+ public void abort(Executor e) {
+ // A no-op
+ }
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/Activator.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/Activator.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/Activator.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,32 @@
+package org.apache.aries.tx.control.jdbc.local.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration<JDBCConnectionProviderFactory> reg;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ reg = context.registerService(JDBCConnectionProviderFactory.class,
+ new JDBCConnectionProviderFactoryImpl(), getProperties());
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ reg.unregister();
+ }
+
+ private Dictionary<String, Object> getProperties() {
+ Dictionary<String, Object> props = new Hashtable<>();
+ props.put("osgi.local.enabled", Boolean.TRUE);
+ return props;
+ }
+
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderFactoryImpl.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,149 @@
+package org.apache.aries.tx.control.jdbc.local.impl;
+
+import static java.util.concurrent.TimeUnit.HOURS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.osgi.service.jdbc.DataSourceFactory.JDBC_URL;
+
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource;
+import org.osgi.service.jdbc.DataSourceFactory;
+import org.osgi.service.transaction.control.TransactionException;
+import org.osgi.service.transaction.control.jdbc.JDBCConnectionProvider;
+import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+public class JDBCConnectionProviderFactoryImpl implements JDBCConnectionProviderFactory {
+
+ @Override
+ public JDBCConnectionProvider getProviderFor(DataSourceFactory dsf, Properties jdbcProperties,
+ Map<String, Object> resourceProviderProperties) {
+
+ checkEnlistment(resourceProviderProperties);
+
+ DataSource unpooled;
+ try {
+ if (toBoolean(resourceProviderProperties.get(USE_DRIVER), false)) {
+ unpooled = new DriverDataSource(dsf.createDriver(null), jdbcProperties.getProperty(JDBC_URL),
+ jdbcProperties);
+ } else {
+ unpooled = dsf.createDataSource(jdbcProperties);
+ }
+ } catch (SQLException sqle) {
+ throw new TransactionException("Unable to create the JDBC resource provider", sqle);
+ }
+
+ DataSource toUse = poolIfNecessary(resourceProviderProperties, unpooled);
+
+ return new JDBCConnectionProviderImpl(toUse);
+ }
+
+ @Override
+ public JDBCConnectionProvider getProviderFor(DataSource ds, Map<String, Object> resourceProviderProperties) {
+ checkEnlistment(resourceProviderProperties);
+ DataSource toUse = poolIfNecessary(resourceProviderProperties, ds);
+
+ return new JDBCConnectionProviderImpl(toUse);
+ }
+
+ @Override
+ public JDBCConnectionProvider getProviderFor(Driver driver, Properties jdbcProperties,
+ Map<String, Object> resourceProviderProperties) {
+ checkEnlistment(resourceProviderProperties);
+ DataSource toUse = poolIfNecessary(resourceProviderProperties,
+ new DriverDataSource(driver, jdbcProperties.getProperty(JDBC_URL), jdbcProperties));
+
+ return new JDBCConnectionProviderImpl(toUse);
+ }
+
+ @Override
+ public JDBCConnectionProvider getProviderFor(XADataSource ds, Map<String, Object> resourceProviderProperties) {
+ checkEnlistment(resourceProviderProperties);
+
+ DataSource unpooled;
+
+ if(ds instanceof DataSource) {
+ unpooled = (DataSource) ds;
+ } else {
+ throw new TransactionException("This resource Provider does not support XA transactions, and the supplied XADataSource is not a DataSource");
+ }
+
+ return new JDBCConnectionProviderImpl(poolIfNecessary(resourceProviderProperties, unpooled));
+ }
+
+ private void checkEnlistment(Map<String, Object> resourceProviderProperties) {
+ if (toBoolean(resourceProviderProperties.get(XA_ENLISTMENT_ENABLED), false)) {
+ throw new TransactionException("This Resource Provider does not support XA transactions");
+ } else if (!toBoolean(resourceProviderProperties.get(LOCAL_ENLISTMENT_ENABLED), true)) {
+ throw new TransactionException(
+ "This Resource Provider always enlists in local transactions as it does not support XA");
+ }
+ }
+
+ private DataSource poolIfNecessary(Map<String, Object> resourceProviderProperties, DataSource unpooled) {
+ DataSource toUse;
+
+ if (toBoolean(resourceProviderProperties.get(CONNECTION_POOLING_ENABLED), true)) {
+ HikariConfig hcfg = new HikariConfig();
+ hcfg.setDataSource(unpooled);
+
+ // Sizes
+ hcfg.setMaximumPoolSize(toInt(resourceProviderProperties.get(MAX_CONNECTIONS), 10));
+ hcfg.setMinimumIdle(toInt(resourceProviderProperties.get(MIN_CONNECTIONS), 10));
+
+ // Timeouts
+ hcfg.setConnectionTimeout(toLong(resourceProviderProperties.get(CONNECTION_TIMEOUT), SECONDS.toMillis(30)));
+ hcfg.setIdleTimeout(toLong(resourceProviderProperties.get(IDLE_TIMEOUT), TimeUnit.MINUTES.toMillis(3)));
+ hcfg.setMaxLifetime(toLong(resourceProviderProperties.get(CONNECTION_LIFETIME), HOURS.toMillis(3)));
+
+ toUse = new HikariDataSource(hcfg);
+
+ } else {
+ toUse = unpooled;
+ }
+ return toUse;
+ }
+
+ private boolean toBoolean(Object o, boolean defaultValue) {
+ if (o instanceof Boolean) {
+ return ((Boolean) o).booleanValue();
+ } else if (o instanceof String) {
+ return Boolean.parseBoolean((String) o);
+ } else if (o == null) {
+ return defaultValue;
+ }
+ throw new IllegalArgumentException("The value " + o + " cannot be converted to a boolean");
+ }
+
+ private int toInt(Object o, int defaultValue) {
+ if (o instanceof Number) {
+ return ((Number) o).intValue();
+ } else if (o instanceof String) {
+ return Integer.parseInt((String) o);
+ } else if (o == null) {
+ return defaultValue;
+ }
+ throw new IllegalArgumentException("The value " + o + " cannot be converted to an int");
+ }
+
+ private long toLong(Object o, long defaultValue) {
+ if (o instanceof Number) {
+ return ((Number) o).longValue();
+ } else if (o instanceof String) {
+ return Long.parseLong((String) o);
+ } else if (o == null) {
+ return defaultValue;
+ }
+ throw new IllegalArgumentException("The value " + o + " cannot be converted to a long");
+ }
+
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/JDBCConnectionProviderImpl.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,28 @@
+package org.apache.aries.tx.control.jdbc.local.impl;
+
+import java.sql.Connection;
+import java.util.UUID;
+
+import javax.sql.DataSource;
+
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionException;
+import org.osgi.service.transaction.control.jdbc.JDBCConnectionProvider;
+
+public class JDBCConnectionProviderImpl implements JDBCConnectionProvider {
+
+ private final UUID uuid = UUID.randomUUID();
+
+ private final DataSource dataSource;
+
+ public JDBCConnectionProviderImpl(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ @Override
+ public Connection getResource(TransactionControl txControl)
+ throws TransactionException {
+ return new TxContextBindingConnection(txControl, dataSource , uuid);
+ }
+
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/main/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnection.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,108 @@
+package org.apache.aries.tx.control.jdbc.local.impl;
+
+import static org.osgi.service.transaction.control.TransactionStatus.NO_TRANSACTION;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import javax.sql.DataSource;
+
+import org.apache.aries.tx.control.jdbc.common.impl.ConnectionWrapper;
+import org.apache.aries.tx.control.jdbc.common.impl.ScopedConnectionWrapper;
+import org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper;
+import org.osgi.service.transaction.control.LocalResource;
+import org.osgi.service.transaction.control.TransactionContext;
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionException;
+
+public class TxContextBindingConnection extends ConnectionWrapper {
+
+ private final TransactionControl txControl;
+ private final UUID resourceId;
+ private final DataSource dataSource;
+
+ public TxContextBindingConnection(TransactionControl txControl,
+ DataSource dataSource, UUID resourceId) {
+ this.txControl = txControl;
+ this.dataSource = dataSource;
+ this.resourceId = resourceId;
+ }
+
+ @Override
+ protected final Connection getDelegate() {
+
+ TransactionContext txContext = txControl.getCurrentContext();
+
+ if (txContext == null) {
+ throw new TransactionException("The resource " + dataSource
+ + " cannot be accessed outside of an active Transaction Context");
+ }
+
+ Connection existing = (Connection) txContext.getScopedValue(resourceId);
+
+ if (existing != null) {
+ return existing;
+ }
+
+ Connection toReturn;
+ Connection toClose;
+
+ try {
+ if (txContext.getTransactionStatus() == NO_TRANSACTION) {
+ toClose = dataSource.getConnection();
+ toReturn = new ScopedConnectionWrapper(toClose);
+ } else if (txContext.supportsLocal()) {
+ toClose = dataSource.getConnection();
+ toReturn = new TxConnectionWrapper(toClose);
+ txContext.registerLocalResource(getLocalResource(toClose));
+ } else {
+ throw new TransactionException(
+ "There is a transaction active, but it does not support local participants");
+ }
+ } catch (Exception sqle) {
+ throw new TransactionException(
+ "There was a problem getting hold of a database connection",
+ sqle);
+ }
+
+
+ txContext.postCompletion(x -> {
+ try {
+ toClose.close();
+ } catch (SQLException sqle) {
+ // TODO log this
+ }
+ });
+
+ txContext.putScopedValue(resourceId, toReturn);
+
+ return toReturn;
+ }
+
+
+ private LocalResource getLocalResource(Connection conn) {
+ return new LocalResource() {
+ @Override
+ public void commit() throws TransactionException {
+ try {
+ conn.commit();
+ } catch (SQLException e) {
+ throw new TransactionException(
+ "An error occurred when committing the connection");
+ }
+ }
+
+ @Override
+ public void rollback() throws TransactionException {
+ try {
+ conn.rollback();
+ } catch (SQLException e) {
+ throw new TransactionException(
+ "An error occurred when rolling back the connection");
+ }
+ }
+
+ };
+ }
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapperTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapperTest.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapperTest.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/ScopedConnectionWrapperTest.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,196 @@
+package org.apache.aries.tx.control.jdbc.common.impl;
+
+import java.awt.List;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Savepoint;
+import java.util.concurrent.Executor;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("resource")
+public class ScopedConnectionWrapperTest {
+
+ @Mock
+ Connection conn;
+
+ @Test
+ public void testUnwrap() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.unwrap(List.class);
+
+ Mockito.verify(conn).unwrap(List.class);
+ }
+
+ @Test
+ public void testIsWrapperFor() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.isWrapperFor(List.class);
+
+ Mockito.verify(conn).isWrapperFor(List.class);
+ }
+
+ @Test
+ public void testCreateStatement() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.createStatement();
+
+ Mockito.verify(conn).createStatement();
+ }
+
+ @Test
+ public void testPrepareStatement() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.prepareStatement("foo");
+
+ Mockito.verify(conn).prepareStatement("foo");
+ }
+
+ @Test
+ public void testPrepareCall() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.prepareCall("foo");
+
+ Mockito.verify(conn).prepareCall("foo");
+ }
+
+ @Test
+ public void testNativeSQL() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.nativeSQL("foo");
+
+ Mockito.verify(conn).nativeSQL("foo");
+ }
+
+ @Test
+ public void testAutoCommit() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.setAutoCommit(true);
+
+ Mockito.verify(conn).setAutoCommit(true);
+ }
+
+ @Test
+ public void testGetAutoCommit() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.getAutoCommit();
+
+ Mockito.verify(conn).getAutoCommit();
+ }
+
+ @Test
+ public void testCommit() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.commit();
+
+ Mockito.verify(conn).commit();
+ }
+
+ @Test
+ public void testRollback() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.rollback();
+
+ Mockito.verify(conn).rollback();
+ }
+
+ @Test
+ public void testClose() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.close();
+
+ Mockito.verify(conn, Mockito.times(0)).close();
+ }
+
+ @Test
+ public void testIsClosed() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.isClosed();
+
+ Mockito.verify(conn).isClosed();
+ }
+
+ @Test
+ public void testAbort() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.abort(x -> {});
+
+ Mockito.verify(conn, Mockito.times(0)).abort(Mockito.any(Executor.class));
+ }
+
+ @Test
+ public void testTransactionIsolation() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.setTransactionIsolation(1);
+
+ Mockito.verify(conn).setTransactionIsolation(1);
+ }
+
+ @Test
+ public void testGetTransactionIsolation() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.getTransactionIsolation();
+
+ Mockito.verify(conn).getTransactionIsolation();
+ }
+
+ @Test
+ public void testSetSavepoint() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.setSavepoint();
+
+ Mockito.verify(conn).setSavepoint();
+ }
+
+ @Test
+ public void testSetSavepointString() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.setSavepoint("foo");
+
+ Mockito.verify(conn).setSavepoint("foo");
+ }
+
+ @Test
+ public void testRollbackSavepoint() throws SQLException {
+ Savepoint s = Mockito.mock(Savepoint.class);
+
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.rollback(s);
+
+ Mockito.verify(conn).rollback(s);
+ }
+
+ @Test
+ public void testReleaseSavepoint() throws SQLException {
+ Savepoint s = Mockito.mock(Savepoint.class);
+
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.releaseSavepoint(s);
+
+ Mockito.verify(conn).releaseSavepoint(s);
+ }
+
+ @Test
+ public void testSetReadOnly() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.setReadOnly(true);
+
+ Mockito.verify(conn).setReadOnly(true);
+ }
+
+ @Test
+ public void testIsReadOnly() throws SQLException {
+ Connection wrapped = new ScopedConnectionWrapper(conn);
+ wrapped.isReadOnly();
+
+ Mockito.verify(conn).isReadOnly();
+ }
+
+
+
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapperTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapperTest.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapperTest.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/common/impl/TxConnectionWrapperTest.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,179 @@
+package org.apache.aries.tx.control.jdbc.common.impl;
+
+import java.awt.List;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.concurrent.Executor;
+
+import org.apache.aries.tx.control.jdbc.common.impl.TxConnectionWrapper;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.service.transaction.control.TransactionException;
+
+@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("resource")
+public class TxConnectionWrapperTest {
+
+ @Mock
+ Connection conn;
+
+ @Test
+ public void testUnwrap() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.unwrap(List.class);
+
+ Mockito.verify(conn).unwrap(List.class);
+ }
+
+ @Test
+ public void testIsWrapperFor() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.isWrapperFor(List.class);
+
+ Mockito.verify(conn).isWrapperFor(List.class);
+ }
+
+ @Test
+ public void testCreateStatement() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.createStatement();
+
+ Mockito.verify(conn).createStatement();
+ }
+
+ @Test
+ public void testPrepareStatement() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.prepareStatement("foo");
+
+ Mockito.verify(conn).prepareStatement("foo");
+ }
+
+ @Test
+ public void testPrepareCall() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.prepareCall("foo");
+
+ Mockito.verify(conn).prepareCall("foo");
+ }
+
+ @Test
+ public void testNativeSQL() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.nativeSQL("foo");
+
+ Mockito.verify(conn).nativeSQL("foo");
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testAutoCommit() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.setAutoCommit(true);
+ }
+
+ @Test
+ public void testGetAutoCommit() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.getAutoCommit();
+
+ Mockito.verify(conn).getAutoCommit();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testCommit() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.commit();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testRollback() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.rollback();
+ }
+
+ @Test
+ public void testClose() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.close();
+
+ Mockito.verify(conn, Mockito.times(0)).close();
+ }
+
+ @Test
+ public void testIsClosed() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.isClosed();
+
+ Mockito.verify(conn).isClosed();
+ }
+
+ @Test
+ public void testAbort() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.abort(x -> {});
+
+ Mockito.verify(conn, Mockito.times(0)).abort(Mockito.any(Executor.class));
+ }
+
+ @Test
+ public void testTransactionIsolation() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.setTransactionIsolation(1);
+
+ Mockito.verify(conn).setTransactionIsolation(1);
+ }
+
+ @Test
+ public void testGetTransactionIsolation() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.getTransactionIsolation();
+
+ Mockito.verify(conn).getTransactionIsolation();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testSetSavepoint() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.setSavepoint();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testSetSavepointString() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.setSavepoint("foo");
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testRollbackSavepoint() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.rollback(null);
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testReleaseSavepoint() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.releaseSavepoint(null);
+ }
+
+ @Test
+ public void testSetReadOnly() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.setReadOnly(true);
+
+ Mockito.verify(conn).setReadOnly(true);
+ }
+
+ @Test
+ public void testIsReadOnly() throws SQLException {
+ Connection wrapped = new TxConnectionWrapper(conn);
+ wrapped.isReadOnly();
+
+ Mockito.verify(conn).isReadOnly();
+ }
+
+
+
+}
Added: aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java?rev=1730855&view=auto
==============================================================================
--- aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java (added)
+++ aries/trunk/tx-control/tx-control-provider-jdbc-local/src/test/java/org/apache/aries/tx/control/jdbc/local/impl/TxContextBindingConnectionTest.java Wed Feb 17 15:19:32 2016
@@ -0,0 +1,136 @@
+package org.apache.aries.tx.control.jdbc.local.impl;
+
+import static org.mockito.Mockito.times;
+import static org.osgi.service.transaction.control.TransactionStatus.ACTIVE;
+import static org.osgi.service.transaction.control.TransactionStatus.NO_TRANSACTION;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.sql.DataSource;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.service.transaction.control.LocalResource;
+import org.osgi.service.transaction.control.TransactionContext;
+import org.osgi.service.transaction.control.TransactionControl;
+import org.osgi.service.transaction.control.TransactionException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TxContextBindingConnectionTest {
+
+ @Mock
+ TransactionControl control;
+
+ @Mock
+ TransactionContext context;
+
+ @Mock
+ DataSource dataSource;
+
+ @Mock
+ Connection rawConnection;
+
+ Map<Object, Object> variables = new HashMap<>();
+
+ UUID id = UUID.randomUUID();
+
+ TxContextBindingConnection conn;
+
+ @Before
+ public void setUp() throws SQLException {
+ Mockito.when(dataSource.getConnection()).thenReturn(rawConnection).thenReturn(null);
+
+ Mockito.doAnswer(i -> variables.put(i.getArguments()[0], i.getArguments()[1]))
+ .when(context).putScopedValue(Mockito.any(), Mockito.any());
+ Mockito.when(context.getScopedValue(Mockito.any()))
+ .thenAnswer(i -> variables.get(i.getArguments()[0]));
+
+ conn = new TxContextBindingConnection(control, dataSource, id);
+ }
+
+ private void setupNoTransaction() {
+ Mockito.when(control.getCurrentContext()).thenReturn(context);
+ Mockito.when(context.getTransactionStatus()).thenReturn(NO_TRANSACTION);
+ }
+
+ private void setupActiveTransaction() {
+ Mockito.when(control.getCurrentContext()).thenReturn(context);
+ Mockito.when(context.supportsLocal()).thenReturn(true);
+ Mockito.when(context.getTransactionStatus()).thenReturn(ACTIVE);
+ }
+
+
+ @Test(expected=TransactionException.class)
+ public void testUnscoped() throws SQLException {
+ conn.isValid(500);
+ }
+
+ @Test
+ public void testNoTransaction() throws SQLException {
+ setupNoTransaction();
+
+ conn.isValid(500);
+ conn.isValid(500);
+
+ Mockito.verify(rawConnection, times(2)).isValid(500);
+ Mockito.verify(context, times(0)).registerLocalResource(Mockito.any());
+
+ Mockito.verify(context).postCompletion(Mockito.any());
+ }
+
+ @Test
+ public void testActiveTransactionCommit() throws SQLException {
+ setupActiveTransaction();
+
+ conn.isValid(500);
+ conn.isValid(500);
+
+ ArgumentCaptor<LocalResource> captor = ArgumentCaptor.forClass(LocalResource.class);
+
+ Mockito.verify(rawConnection, times(2)).isValid(500);
+ Mockito.verify(context).registerLocalResource(captor.capture());
+
+ Mockito.verify(context).postCompletion(Mockito.any());
+
+ captor.getValue().commit();
+
+ Mockito.verify(rawConnection).commit();
+ }
+
+ @Test
+ public void testActiveTransactionRollback() throws SQLException {
+ setupActiveTransaction();
+
+ conn.isValid(500);
+ conn.isValid(500);
+
+ ArgumentCaptor<LocalResource> captor = ArgumentCaptor.forClass(LocalResource.class);
+
+ Mockito.verify(rawConnection, times(2)).isValid(500);
+ Mockito.verify(context).registerLocalResource(captor.capture());
+
+ Mockito.verify(context).postCompletion(Mockito.any());
+
+ captor.getValue().rollback();
+
+ Mockito.verify(rawConnection).rollback();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void testActiveTransactionNoLocal() throws SQLException {
+ setupActiveTransaction();
+
+ Mockito.when(context.supportsLocal()).thenReturn(false);
+ conn.isValid(500);
+ }
+
+}