You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by vi...@apache.org on 2010/02/04 15:31:45 UTC
svn commit: r906494 - in /incubator/aries/trunk/samples/transaction-sample:
./ osgi-jdbc-api/ osgi-jdbc-api/src/ osgi-jdbc-api/src/main/
osgi-jdbc-api/src/main/java/ osgi-jdbc-api/src/main/java/org/
osgi-jdbc-api/src/main/java/org/osgi/ osgi-jdbc-api/s...
Author: violetagg
Date: Thu Feb 4 14:31:44 2010
New Revision: 906494
URL: http://svn.apache.org/viewvc?rev=906494&view=rev
Log:
ARIES-122 Implementation of org.osgi.service.jdbc.DataSourceFactory interface for Derby and sample application which use it in JTA transactions according "OSGi Enterprise Specification"
Added:
incubator/aries/trunk/samples/transaction-sample/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/pom.xml
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/jdbc/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/jdbc/DataSourceFactory.java
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/pom.xml
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/derby/
incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/derby/DerbyActivator.java
incubator/aries/trunk/samples/transaction-sample/pom.xml
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/pom.xml
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/configuration/
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/configuration/config.ini
incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/txDemoDB.sql
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/pom.xml
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/GenericJTAException.java
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/TxDBServlet.java
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/tableTemplate.css
incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/web.xml
Added: incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/pom.xml?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/pom.xml (added)
+++ incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/pom.xml Thu Feb 4 14:31:44 2010
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.transaction-sample</groupId>
+ <artifactId>transaction-sample</artifactId>
+ <version>1.0.0</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>osgi-jdbc-api</artifactId>
+ <name>OSGi enterprise API or JDBC access</name>
+ <version>1.0.0</version>
+ <packaging>bundle</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>osgi-jdbc-api</Bundle-Name>
+ <Bundle-SymbolicName>${pom.groupId}.osgi-jdbc-api</Bundle-SymbolicName>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/jdbc/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/jdbc/DataSourceFactory.java?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/jdbc/DataSourceFactory.java (added)
+++ incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-api/src/main/java/org/osgi/service/jdbc/DataSourceFactory.java Thu Feb 4 14:31:44 2010
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) OSGi Alliance (2008). All Rights Reserved.
+ *
+ * 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.
+ */
+package org.osgi.service.jdbc;
+
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+/**
+ * DataSource providers should implement this interface and register it as an
+ * OSGi service with the JDBC driver class name in the "jdbc.driver" property.
+ */
+public interface DataSourceFactory {
+ /**
+ * Common property keys that DataSource clients should supply values for.
+ */
+ public static final String JDBC_URL = "url";
+ public static final String JDBC_USER = "user";
+ public static final String JDBC_PASSWORD = "password";
+ public static final String JDBC_DATABASE_NAME = "databaseName";
+ public static final String JDBC_DATASOURCE_NAME = "dataSourceName";
+ public static final String JDBC_DESCRIPTION = "description";
+ public static final String JDBC_NETWORK_PROTOCOL = "networkProtocol";
+ public static final String JDBC_PORT_NUMBER = "portNumber";
+ public static final String JDBC_ROLE_NAME = "roleName";
+ public static final String JDBC_SERVER_NAME = "serverName";
+
+ /**
+ * XA specific. Additional property keys that ConnectionPoolDataSource and
+ * XADataSource clients should supply values for
+ */
+ public static final String JDBC_INITIAL_POOL_SIZE = "initialPoolSize";
+ public static final String JDBC_MAX_IDLE_TIME = "maxIdleTime";
+ public static final String JDBC_MAX_POOL_SIZE = "maxPoolSize";
+ public static final String JDBC_MAX_STATEMENTS = "maxStatements";
+ public static final String JDBC_MIN_POOL_SIZE = "minPoolSize";
+ public static final String JDBC_PROPERTY_CYCLE = "propertyCycle";
+
+ /**
+ * Vendor-specific properties meant to further describe the driver. Clients
+ * may filter or test this property to determine if the driver is suitable,
+ * or the desired one.
+ */
+ public static final String JDBC_DRIVER_CLASS = "osgi.jdbc.driver.class";
+ public static final String JDBC_DRIVER_NAME = "osgi.jdbc.driver.name";
+ public static final String JDBC_DRIVER_VERSION = "osgi.jdbc.driver.version";
+
+ /**
+ * Create a new {@link DataSource} using the given properties.
+ *
+ * @param props properties used to configure the DataSource
+ * @return configured DataSource
+ */
+ public DataSource createDataSource( Properties props ) throws SQLException;
+
+ public XADataSource createXADataSource( Properties props ) throws SQLException;
+
+ public ConnectionPoolDataSource createConnectionPoolDataSource( Properties props ) throws SQLException;
+
+ public Driver getDriver( Properties props ) throws SQLException;
+}
Added: incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/pom.xml?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/pom.xml (added)
+++ incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/pom.xml Thu Feb 4 14:31:44 2010
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.transaction-sample</groupId>
+ <artifactId>transaction-sample</artifactId>
+ <version>1.0.0</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>osgi-jdbc-derby</artifactId>
+ <name>OSGi Enterprice API for JDBC Access</name>
+ <version>1.0.0</version>
+ <packaging>bundle</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.osgi</groupId>
+ <artifactId>osgi</artifactId>
+ <version>3.5.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.5.3.0_1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>osgi-jdbc-api</artifactId>
+ <version>1.0.0</version>
+ <type>bundle</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>osgi-jdbc-derby</Bundle-Name>
+ <Bundle-SymbolicName>${pom.groupId}.osgi-jdbc-derby</Bundle-SymbolicName>
+ <DynamicImport-Package>javax.transaction;version="1.1",javax.transaction.xa;version="1.1",*</DynamicImport-Package>
+ <Import-Package></Import-Package>
+ <Private-Package>org.apache.derby.*</Private-Package>
+ <Bundle-Activator>org.apache.aries.samples.osgijdbc.derby.DerbyActivator</Bundle-Activator>
+ <Export-Service>org.osgi.service.jdbc.DataSourceFactory</Export-Service>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/derby/DerbyActivator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/derby/DerbyActivator.java?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/derby/DerbyActivator.java (added)
+++ incubator/aries/trunk/samples/transaction-sample/osgi-jdbc-derby/src/main/java/org/apache/aries/samples/osgijdbc/derby/DerbyActivator.java Thu Feb 4 14:31:44 2010
@@ -0,0 +1,85 @@
+/**
+ * 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.aries.samples.osgijdbc.derby;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.apache.derby.jdbc.EmbeddedDriver;
+import org.apache.derby.jdbc.EmbeddedXADataSource;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.jdbc.DataSourceFactory;
+
+public class DerbyActivator implements DataSourceFactory, BundleActivator {
+
+ public ConnectionPoolDataSource createConnectionPoolDataSource( Properties props) {
+ EmbeddedConnectionPoolDataSource embeddedCPDataSource = new EmbeddedConnectionPoolDataSource();
+ embeddedCPDataSource.setDataSourceName(props.getProperty(JDBC_DATASOURCE_NAME));
+ embeddedCPDataSource.setDatabaseName(props.getProperty(JDBC_DATABASE_NAME));
+ embeddedCPDataSource.setUser(props.getProperty(JDBC_USER));
+ embeddedCPDataSource.setPassword(props.getProperty(JDBC_PASSWORD));
+ return embeddedCPDataSource;
+ }
+
+ public DataSource createDataSource(Properties props) {
+ EmbeddedDataSource embeddedDataSource = new EmbeddedDataSource();
+ embeddedDataSource.setDataSourceName(props.getProperty(JDBC_DATASOURCE_NAME));
+ embeddedDataSource.setDatabaseName(props.getProperty(JDBC_DATABASE_NAME));
+ embeddedDataSource.setUser(props.getProperty(JDBC_USER));
+ embeddedDataSource.setPassword(props.getProperty(JDBC_PASSWORD));
+ return embeddedDataSource;
+ }
+
+ public XADataSource createXADataSource(Properties props) {
+ EmbeddedXADataSource embeddedXADataSource = new EmbeddedXADataSource();
+ embeddedXADataSource.setDataSourceName(props.getProperty(JDBC_DATASOURCE_NAME));
+ embeddedXADataSource.setDatabaseName(props.getProperty(JDBC_DATABASE_NAME));
+ embeddedXADataSource.setUser(props.getProperty(JDBC_USER));
+ embeddedXADataSource.setPassword(props.getProperty(JDBC_PASSWORD));
+ return embeddedXADataSource;
+ }
+
+ public Driver getDriver(Properties props) {
+ EmbeddedDriver embeddedDriver = new EmbeddedDriver();
+ return embeddedDriver;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ new EmbeddedDriver();
+ context.registerService(DataSourceFactory.class.getName(), this, new Properties());
+ }
+
+ public void stop(BundleContext context) throws Exception {
+
+ try {
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (SQLException sqlexception) {
+ }
+ }
+
+}
Added: incubator/aries/trunk/samples/transaction-sample/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/pom.xml?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/pom.xml (added)
+++ incubator/aries/trunk/samples/transaction-sample/pom.xml Thu Feb 4 14:31:44 2010
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.aries.transaction-sample</groupId>
+ <version>1.0.0</version>
+ <artifactId>transaction-sample</artifactId>
+ <name>Apache Aries transaction sample</name>
+ <packaging>pom</packaging>
+
+ <parent>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>samples</artifactId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modules>
+ <module>osgi-jdbc-api</module>
+ <module>osgi-jdbc-derby</module>
+ <module>transaction-sample-web</module>
+ <module>transaction-assembly</module>
+ </modules>
+
+</project>
Added: incubator/aries/trunk/samples/transaction-sample/transaction-assembly/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-assembly/pom.xml?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-assembly/pom.xml (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-assembly/pom.xml Thu Feb 4 14:31:44 2010
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ * 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.
+ -->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.transaction-sample</groupId>
+ <artifactId>transaction-sample</artifactId>
+ <version>1.0.0</version>
+ </parent>
+
+ <artifactId>transaction-assembly</artifactId>
+ <name>Apache Aries transaction sample assembly</name>
+ <version>1.0.0</version>
+ <packaging>pom</packaging>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <version>3.5.0.v20090520</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>cm</artifactId>
+ <version>3.2.0-v20070116</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.osgi</groupId>
+ <artifactId>services</artifactId>
+ <version>3.1.200-v20070605</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ <version>1.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-service</artifactId>
+ <version>1.4</version>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-extender-war</artifactId>
+ <version>0.7.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-jetty-bundle</artifactId>
+ <version>0.7.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.web</groupId>
+ <artifactId>pax-web-jsp</artifactId>
+ <version>0.7.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.transaction</groupId>
+ <artifactId>org.apache.aries.transaction</artifactId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>osgi-jdbc-api</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>transaction-sample-web</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>osgi-jdbc-derby</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>2.5.6</version>
+ </dependency>
+
+
+ </dependencies>
+
+ <build>
+
+ <resources>
+ <resource>
+ <directory>${pom.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ </configuration>
+ <executions>
+ <execution>
+ <id>filter</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>resources</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <excludeTransitive>true</excludeTransitive>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
+
+
+
+
+
+
+
Added: incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/configuration/config.ini
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/configuration/config.ini?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/configuration/config.ini (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/configuration/config.ini Thu Feb 4 14:31:44 2010
@@ -0,0 +1,2 @@
+osgi.bundles=cm-3.2.0-v20070116.jar@start,services-3.1.200-v20070605.jar@start,pax-logging-api-1.4.jar@start,pax-logging-service-1.4.jar@start,pax-web-jetty-bundle-0.7.2.jar@start,pax-web-extender-war-0.7.2.jar@start,pax-web-jsp-0.7.2.jar@start,osgi-jdbc-derby-1.0.0.jar@start,osgi-jdbc-api-1.0.0.jar@start,org.apache.aries.transaction-1.0.0-incubating-SNAPSHOT.jar@start,transaction-sample-web-1.0.0.jar@start
+eclipse.ignoreApp=true
\ No newline at end of file
Added: incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/txDemoDB.sql
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/txDemoDB.sql?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/txDemoDB.sql (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-assembly/src/main/resources/txDemoDB.sql Thu Feb 4 14:31:44 2010
@@ -0,0 +1,3 @@
+connect 'jdbc:derby:txDemo;create=true';
+CREATE TABLE txDemo (value VARCHAR(40) NOT NULL);
+exit;
Added: incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/pom.xml?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/pom.xml (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/pom.xml Thu Feb 4 14:31:44 2010
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.transaction-sample</groupId>
+ <artifactId>transaction-sample</artifactId>
+ <version>1.0.0</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>transaction-sample-web</artifactId>
+ <name>Apache Aries Transaction sample servlet</name>
+ <version>1.0.0</version>
+ <packaging>bundle</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.groupId}.transaction-sample-web</Bundle-SymbolicName>
+ <Export-Package>!org.apache.aries.samples.*</Export-Package>
+ <Import-Package> javax.transaction;version="1.1",javax.transaction.xa;version="1.1",*</Import-Package>
+ <Web-ContextPath>/osgitransactions</Web-ContextPath>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+<!-- <dependency>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>blog-api</artifactId>
+ <version>1.0.0</version>
+ </dependency> -->
+ <dependency>
+ <groupId>org.apache.aries.samples</groupId>
+ <artifactId>osgi-jdbc-api</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>servlet-api-2.5</artifactId>
+ <version>6.1.5</version>
+ </dependency>
+ </dependencies>
+</project>
+
Added: incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/GenericJTAException.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/GenericJTAException.java?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/GenericJTAException.java (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/GenericJTAException.java Thu Feb 4 14:31:44 2010
@@ -0,0 +1,16 @@
+package org.apache.aries.samples.transaction;
+
+import javax.transaction.RollbackException;
+
+public class GenericJTAException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3760423779101497679L;
+
+ public GenericJTAException(Exception e) {
+ super (e);
+ }
+
+}
Added: incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/TxDBServlet.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/TxDBServlet.java?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/TxDBServlet.java (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/java/org/apache/aries/samples/transaction/TxDBServlet.java Thu Feb 4 14:31:44 2010
@@ -0,0 +1,223 @@
+/**
+ * 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.aries.samples.transaction;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.jdbc.DataSourceFactory;
+
+public class TxDBServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static final String OSGI_BUNDLECONTEXT_ATTRIBUTE = "osgi-bundlecontext";
+ private static final String CLEAN_TABLE = "delete from txDemo";
+ private static final String SELECT_TABLE = "SELECT * FROM txDemo";
+ private static final String INSERT_INTO_TABLE = "INSERT INTO txDemo VALUES(?)";
+ private static final String LOGO_HEADER = "<TABLE border='0\' cellpadding=\'0\' cellspacing='0' width='100%'> " +
+ "<TR> " +
+ "<TD align='left' class='topbardiv' nowrap=''>" +
+ "<A href='http://incubator.apache.org/aries/' title='Apache Aries (incubating)'>" +
+ "<IMG border='0' src='http://incubator.apache.org/aries/images/Arieslogo_Horizontal.gif'>" +
+ "</A>" +
+ "</TD>" +
+
+ "<TD align='right' nowrap=''>" +
+ "<A href='http://www.apache.org/' title='The Apache Software Foundation'>" +
+ "<IMG border='0' src='http://incubator.apache.org/aries/images/apache-incubator-logo.png'>" +
+ "</A>"+
+ "</TD>"+
+
+ "</TR>"+
+ "</TABLE>";
+
+ private PrintWriter pw = null;
+
+ public void init() throws ServletException {
+ }
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ pw = response.getWriter();
+ pw.write(LOGO_HEADER);
+ // Get the bundle context from ServletContext attributes
+ BundleContext ctx = (BundleContext) getServletContext().getAttribute(OSGI_BUNDLECONTEXT_ATTRIBUTE);
+
+ pw.println("<html>");
+ pw.println("<head>");
+ pw.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"tableTemplate.css\"/>");
+ pw.println("<body>");
+ pw.println("<h2 align=center><p><font face=\"Tahoma\">Sample Application for JDBC usage in JTA Transactions.</font></h2>");
+ pw.println("<p><p>");
+
+ ServiceReference tmServiceRef = ctx.getServiceReference("javax.transaction.TransactionManager");
+ ServiceReference derbyServiceRef = ctx.getServiceReference(DataSourceFactory.class.getName());
+
+ if(tmServiceRef == null || derbyServiceRef == null){
+ pw.println("<font face=\"Tahoma\">TransactionManager or Derby driver are not available in the OSGI registry.</font><br>");
+ } else {
+ TransactionManager tm = (TransactionManager)ctx.getService(tmServiceRef);
+ DataSourceFactory derbyRegistry = (DataSourceFactory)ctx.getService(derbyServiceRef);
+ try{
+ // Set the needed properties for the database connection
+ Properties props = new Properties();
+ props.put(DataSourceFactory.JDBC_URL, "jdbc:derby:txDemo");
+ props.put(DataSourceFactory.JDBC_DATABASE_NAME, "txDemo");
+ props.put(DataSourceFactory.JDBC_USER, "");
+ props.put(DataSourceFactory.JDBC_PASSWORD, "");
+ XADataSource xaDataSource = derbyRegistry.createXADataSource(props);
+
+ pw.println("<center><form><table><tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndCommit' size='100'/></td></tr>");
+ pw.println("<tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndRollback' size='100'/></center></td></tr>");
+ pw.println("<tr colspan='2' align='center'><td> </td><td><input type='submit' name='action' value='cleanTable' size='100' /> <input type='submit' name='action' value='printTable' size='100'/></td><tr></table></form></center>");
+
+
+ String value = request.getParameter("value");
+ String action = request.getParameter("action");
+
+ if(action != null && action.equals("InsertAndCommit")){
+ insertIntoTransaction(xaDataSource, tm, value, true);
+ } else if(action != null && action.equals("InsertAndRollback")){
+ insertIntoTransaction(xaDataSource, tm, value, false);
+ } else if(action != null && action.equals("cleanTable")){
+ cleanTable(xaDataSource);
+ }
+ printTable(xaDataSource);
+ } catch (Exception e){
+ pw.println("<font face=\"Tahoma\">Unexpected exception occurred "+ e.toString()+".</font><br>");
+ e.printStackTrace(pw);
+ }
+
+ }
+ pw.println("</body>");
+ pw.println("</html>");
+ pw.flush();
+ }// end of doGet(HttpServletRequest request, HttpServletResponse response)
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+ IOException {
+ doGet(request, response);
+ }// end of doPost(HttpServletRequest request, HttpServletResponse response)
+
+
+ /**
+ * Prints the table
+ * @param xaDataSource
+ * @throws SQLException
+ */
+ private void printTable(XADataSource xaDataSource) throws SQLException {
+ XAConnection xaConnection = xaDataSource.getXAConnection();
+ Connection connection = xaConnection.getConnection();
+ PreparedStatement selectStatement = connection.prepareStatement(SELECT_TABLE);
+ ResultSet set = selectStatement.executeQuery();
+ pw.write("<center><br><table>");
+ pw.write("<tr BGCOLOR=#FFCC33>");
+ pw.write("<td><font face=\"Tahoma\"><b>VALUES</font></td>");
+ pw.write("</tr>");
+ while (set.next()) {
+ pw.write("<tr>");
+ pw.write("<td><font face=\"Tahoma\">");
+ pw.write(set.getString("value"));
+ pw.write("</font></td>");
+ pw.write("</tr>");
+ }
+ pw.write("</table><br></center>");
+ }
+
+ /**
+ * This method demonstrates how to enlist JDBC connection into Transaction according OSGi enterprise specification.
+ *
+ * @param xads XADataSource
+ * @param tm TransactionManager
+ * @param value which will be inserted into table
+ * @param toCommit Specify if the transaction will be committed or rolledback
+ * @throws SQLException
+ * @throws GenericJTAException
+ */
+ private void insertIntoTransaction(XADataSource xads, TransactionManager tm, String value, boolean toCommit) throws SQLException, GenericJTAException{
+
+ XAConnection xaConnection = xads.getXAConnection();
+ Connection connection = xaConnection.getConnection();
+ XAResource xaResource = xaConnection.getXAResource();
+ try{
+ tm.begin();
+ Transaction transaction = tm.getTransaction();
+ transaction.enlistResource(xaResource);
+
+ PreparedStatement insertStatement = connection.prepareStatement(INSERT_INTO_TABLE);
+ insertStatement.setString(1, value);
+ insertStatement.executeUpdate();
+ if(toCommit){
+ transaction.commit();
+ } else {
+ transaction.rollback();
+ }
+ }catch(RollbackException e){
+ throw new GenericJTAException(e);
+ } catch (SecurityException e) {
+ throw new GenericJTAException(e);
+ } catch (IllegalStateException e) {
+ throw new GenericJTAException(e);
+ } catch (HeuristicMixedException e) {
+ throw new GenericJTAException(e);
+ } catch (HeuristicRollbackException e) {
+ throw new GenericJTAException(e);
+ } catch (SystemException e) {
+ throw new GenericJTAException(e);
+ } catch (NotSupportedException e) {
+ throw new GenericJTAException(e);
+ }
+ }
+
+
+ /**
+ * Cleans the Table
+ *
+ * @param xaDataSource
+ * @throws SQLException
+ */
+ private void cleanTable(XADataSource xaDataSource) throws SQLException {
+ XAConnection xaConnection = xaDataSource.getXAConnection();
+ Connection connection = xaConnection.getConnection();
+ PreparedStatement statement = connection.prepareStatement(CLEAN_TABLE);
+ statement.executeUpdate();
+ }
+
+}
Added: incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/tableTemplate.css
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/tableTemplate.css?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/tableTemplate.css (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/tableTemplate.css Thu Feb 4 14:31:44 2010
@@ -0,0 +1,7 @@
+table {
+ background-color:#FFF; width:80%; border-collapse:collapse;
+}
+
+td {
+ background-color:#FFF; border:1px solid black; padding:5px;
+}
\ No newline at end of file
Added: incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/web.xml?rev=906494&view=auto
==============================================================================
--- incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/web.xml (added)
+++ incubator/aries/trunk/samples/transaction-sample/transaction-sample-web/src/main/resources/WEB-INF/web.xml Thu Feb 4 14:31:44 2010
@@ -0,0 +1,15 @@
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>OSGi Transaction sample Web Application</display-name>
+ <servlet>
+ <servlet-name>TxDBServlet</servlet-name>
+ <servlet-class>org.apache.aries.samples.transaction.TxDBServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>TxDBServlet</servlet-name>
+ <url-pattern>/enlist</url-pattern>
+ </servlet-mapping>
+</web-app>