Copied: aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java (from r1680054, aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java?p2=aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java&p1=aries/trunk/jpa/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty)
Copied: aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo (from r1680054, aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo?p2=aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo&p1=aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Added: aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/persistence.xml URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/persistence.xml?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/persistence.xml (added) +++ aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/persistence.xml Tue May 19 09:47:49 2015 @@ -0,0 +1,56 @@ +<?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. --> +<persistence version="2.1" + xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + + <persistence-unit name="test-unit" + transaction-type="JTA"> + <description>Test persistence unit for the JPA Container and Context iTests</description> + <jta-data-source>osgi:service/javax.sql.DataSource/(transactional=true)</jta-data-source> + <class>org.apache.aries.jpa.container.itest.entities.Car</class> + <exclude-unlisted-classes>true</exclude-unlisted-classes> + <properties> + <property name="eclipselink.target-database" value="Derby" /> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> + <property name="eclipselink.ddl-generation.output-mode" + value="database" /> + </properties> + </persistence-unit> + + <persistence-unit name="script-test-unit" + transaction-type="RESOURCE_LOCAL"> + <properties> + <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:TEST;create=true" /> + <property name="javax.persistence.jdbc.driver" + value="org.apache.derby.jdbc.EmbeddedDriver" /> + <property name="eclipselink.target-database" value="Derby" /> + <property + name="javax.persistence.schema-generation.database.action" + value="drop-and-create" /> + <property + name="javax.persistence.schema-generation.create-source" + value="script" /> + <property + name="javax.persistence.schema-generation.create-script-source" + value="META-INF/sql/create.sql" /> + <property name="javax.persistence.sql-load-script-source" + value="META-INF/sql/data.sql" /> + <property name="javax.persistence.schema-generation.drop-source" + value="script" /> + <property + name="javax.persistence.schema-generation.drop-script-source" + value="META-INF/sql/drop.sql" /> + </properties> + </persistence-unit> +</persistence> Copied: aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/create.sql (from r1680054, aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/create.sql) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/create.sql?p2=aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/create.sql&p1=aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/create.sql&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/data.sql (from r1680054, aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/data.sql) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/data.sql?p2=aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/data.sql&p1=aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/data.sql&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/drop.sql (from r1680054, aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/drop.sql) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/drop.sql?p2=aries/trunk/jpa/itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/drop.sql&p1=aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/drop.sql&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle/.gitignore (from r1680054, aries/trunk/jpa/jpa-blueprint-testbundle/.gitignore) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/.gitignore?p2=aries/trunk/jpa/itests/jpa-container-testbundle/.gitignore&p1=aries/trunk/jpa/jpa-blueprint-testbundle/.gitignore&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle/LICENSE (from r1680054, aries/trunk/jpa/jpa-container-context/LICENSE) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/LICENSE?p2=aries/trunk/jpa/itests/jpa-container-testbundle/LICENSE&p1=aries/trunk/jpa/jpa-container-context/LICENSE&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle/NOTICE (from r1680054, aries/trunk/jpa/jpa-container-advancedtestbundle/NOTICE) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/NOTICE?p2=aries/trunk/jpa/itests/jpa-container-testbundle/NOTICE&p1=aries/trunk/jpa/jpa-container-advancedtestbundle/NOTICE&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle/pom.xml (from r1680054, aries/trunk/jpa/jpa-container-testbundle/pom.xml) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/pom.xml?p2=aries/trunk/jpa/itests/jpa-container-testbundle/pom.xml&p1=aries/trunk/jpa/jpa-container-testbundle/pom.xml&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container-testbundle/pom.xml (original) +++ aries/trunk/jpa/itests/jpa-container-testbundle/pom.xml Tue May 19 09:47:49 2015 @@ -32,7 +32,7 @@ <artifactId>org.apache.aries.jpa.container.itest.bundle</artifactId> <version>1.0.1-SNAPSHOT</version> <packaging>bundle</packaging> - <name>Test Bundle for Aries JPA Container iTests</name> + <name>Apache Aries JPA test bundle container</name> <scm> <connection>scm:svn:http://svn.apache.org/repos/asf/aries/trunk/jpa/jpa-container-testbundle</connection> @@ -81,4 +81,5 @@ </plugins> </build> + <description>For simple tests with DataSource, DataSourceFactory</description> </project> Copied: aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java (from r1680054, aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java?p2=aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java&p1=aries/trunk/jpa/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo (from r1680054, aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/java/org/apache/aries/jpa/container/advanced/itest/bundle/entities/packageinfo) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo?p2=aries/trunk/jpa/itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo&p1=aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/java/org/apache/aries/jpa/container/advanced/itest/bundle/entities/packageinfo&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml (from r1680054, aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml?p2=aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml&p1=aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml (original) +++ aries/trunk/jpa/itests/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml Tue May 19 09:47:49 2015 @@ -19,13 +19,12 @@ --> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" - version="1.0"> + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0"> <persistence-unit name="test-unit" transaction-type="RESOURCE_LOCAL"> <description>Test persistence unit for the JPA Container and Context iTests</description> - <jta-data-source>osgi:service/javax.sql.DataSource</jta-data-source> <non-jta-data-source>osgi:service/javax.sql.DataSource</non-jta-data-source> <properties> <!-- This is to avoid compile time enhancement which would conflict with hibernate --> @@ -40,45 +39,16 @@ <property name="hibernate.hbm2ddl.auto" value="create-drop"/> </properties> </persistence-unit> - - <persistence-unit name="bp-test-unit" transaction-type="JTA"> - <description>Test persistence unit for the JPA Container and Context iTests</description> - <jta-data-source>blueprint:comp/jta</jta-data-source> - <non-jta-data-source>blueprint:comp/nonjta</non-jta-data-source> - <properties> - <!-- These properties are creating the database on the fly. We are using them to avoid the tests having - to create a database --> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> - <property name="openjpa.jdbc.DBDictionary" value="derby"/> - <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyTenSevenDialect"/> - <property name="hibernate.hbm2ddl.auto" value="create-drop"/> - <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/> - </properties> - </persistence-unit> - - <persistence-unit name="bp-xa-test-unit" transaction-type="JTA"> - <description>Test persistence unit for the JPA Container and Context iTests</description> - <jta-data-source>blueprint:comp/xa</jta-data-source> - <non-jta-data-source>blueprint:comp/nonjta</non-jta-data-source> - <properties> - <!-- These properties are creating the database on the fly. We are using them to avoid the tests having - to create a database --> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> - <property name="openjpa.jdbc.DBDictionary" value="derby"/> - <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyTenSevenDialect"/> - <property name="hibernate.hbm2ddl.auto" value="create-drop"/> - </properties> - </persistence-unit> - + <persistence-unit name="dsf-test-unit" transaction-type="RESOURCE_LOCAL"> <description>Test persistence unit for the JPA Container DataSourceFactory iTests</description> <properties> - <!-- These properties are creating the database on the fly. We are using them to avoid the tests having + <!-- These properties are creating the database on the fly. We are using them to avoid the tests having to create a database --> - <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> - <property name="javax.persistence.jdbc.databaseName" value="memory:TEST;create=true"/> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> - <property name="openjpa.jdbc.DBDictionary" value="derby"/> + <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> + <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:TEST;create=true"/> + <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> + <property name="openjpa.jdbc.DBDictionary" value="derby"/> <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyTenSevenDialect"/> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> </properties> @@ -89,10 +59,10 @@ <properties> <!-- These properties are creating the database on the fly. We are using them to avoid the tests having to create a database --> - <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/> - <property name="javax.persistence.jdbc.databaseName" value="memory:TEST;create=true"/> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> - <property name="openjpa.jdbc.DBDictionary" value="derby"/> + <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver-pool-xa"/> + <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:TEST;create=true"/> + <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> + <property name="openjpa.jdbc.DBDictionary" value="derby"/> <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyTenSevenDialect"/> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> </properties> Added: aries/trunk/jpa/itests/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/pom.xml?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/itests/pom.xml (added) +++ aries/trunk/jpa/itests/pom.xml Tue May 19 09:47:49 2015 @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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> + + <groupId>org.apache.aries.jpa.itest</groupId> + <artifactId>org.apache.aries.jpa.itest.parent</artifactId> + <name>Apache Aries JPA itests parent</name> + <packaging>pom</packaging> + + <parent> + <groupId>org.apache.aries.jpa</groupId> + <artifactId>org.apache.aries.jpa.parent</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <properties> + <aries.skip.version.check>true</aries.skip.version.check> + </properties> + + <modules> + <module>jpa-container-blueprint-testbundle</module> + <module>jpa-container-advancedtestbundle</module> + <module>jpa-container-itest</module> + <module>jpa-container-testbundle</module> + <module>jpa-container-testbundle-eclipselink</module> + </modules> + +</project> + Modified: aries/trunk/jpa/jpa-api/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/pom.xml?rev=1680218&r1=1680217&r2=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-api/pom.xml (original) +++ aries/trunk/jpa/jpa-api/pom.xml Tue May 19 09:47:49 2015 @@ -31,8 +31,8 @@ <groupId>org.apache.aries.jpa</groupId> <artifactId>org.apache.aries.jpa.api</artifactId> <packaging>bundle</packaging> - <name>Aries JPA Container API</name> - <version>1.0.3-SNAPSHOT</version> + <name>Apache Aries JPA Container API</name> + <version>2.0.0-SNAPSHOT</version> <scm> <connection>scm:svn:http://svn.apache.org/repos/asf/aries/trunk/jpa/jpa-api</connection> @@ -43,15 +43,10 @@ <properties> <!-- Export package versions are maintained in packageinfo files --> <aries.osgi.export.pkg> - org.apache.aries.jpa.container.parsing, - org.apache.aries.jpa.container.sync, - org.apache.aries.jpa.container, - org.apache.aries.jpa.container.context + org.apache.aries.jpa.supplier, + org.apache.aries.jpa.template </aries.osgi.export.pkg> <aries.osgi.import> - javax.persistence;version="[1.0.0,3.0.0)", - javax.persistence.spi;version="[1.0.0,3.0.0)", - org.osgi.framework;version="[1.5.0,2.0.0)" </aries.osgi.import> <aries.osgi.private.pkg /> <lastReleaseVersion>1.0.0</lastReleaseVersion> Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/EmSupplier.java (from r1680054, aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/quiesce/impl/CountdownCallback.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/EmSupplier.java?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/EmSupplier.java&p1=aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/quiesce/impl/CountdownCallback.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/quiesce/impl/CountdownCallback.java (original) +++ aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/EmSupplier.java Tue May 19 09:47:49 2015 @@ -1,40 +1,42 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIESOR 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.jpa.container.quiesce.impl; - - -/** - * A {@link DestroyCallback} that delegates after the correct - * number of calls - */ -public final class CountdownCallback implements DestroyCallback { - private final DestroyCallback callback; - private int counter; - - public CountdownCallback(int count, - DestroyCallback callback) { - this.callback = callback; - counter = count; - } - - public void callback() { - if(--counter == 0) - callback.callback(); - } -} \ No newline at end of file +/* + * 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 WARRANTIESOR 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.jpa.supplier; + +import javax.persistence.EntityManager; + +/** + * Provides a thread safe way to use an EntityManager. - The first call must be to preCall(). This will create + * an EM for the current thread. - The EM can then be retrieved by calling get() and user normally - At the + * end postCall() has to be called to close the EntityManager If this is used on nested methods then the EM is + * only created / closed on the outermost calls to preCall() / postCall() + */ +public interface EmSupplier { + + /** + * Is called before first access to get() in a method + */ + void preCall(); + + EntityManager get(); + + /** + * Is called after last access to get() in a method + */ + void postCall(); +} Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/packageinfo (from r1680054, aries/trunk/jpa/jpa-blueprint-testbundle/src/main/java/org/apache/aries/jpa/blueprint/itest/entities/packageinfo) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/packageinfo?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/supplier/packageinfo&p1=aries/trunk/jpa/jpa-blueprint-testbundle/src/main/java/org/apache/aries/jpa/blueprint/itest/entities/packageinfo&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmConsumer.java (from r1680054, aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/quiesce/impl/DestroyCallback.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmConsumer.java?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmConsumer.java&p1=aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/quiesce/impl/DestroyCallback.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/quiesce/impl/DestroyCallback.java (original) +++ aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmConsumer.java Tue May 19 09:47:49 2015 @@ -1,26 +1,25 @@ -/* - * 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 WARRANTIESOR 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.jpa.container.quiesce.impl; - -/** - * An asynchronous callback for destroying something - */ -public interface DestroyCallback { - public void callback(); -} +/* + * 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 WARRANTIESOR 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.jpa.template; + +import javax.persistence.EntityManager; + +public interface EmConsumer { + void accept(EntityManager em); +} Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmFunction.java (from r1680054, aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/NLS.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmFunction.java?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmFunction.java&p1=aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/NLS.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/NLS.java (original) +++ aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/EmFunction.java Tue May 19 09:47:49 2015 @@ -16,11 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.aries.jpa.container.impl; +package org.apache.aries.jpa.template; -import org.apache.aries.util.nls.MessageUtil; +import javax.persistence.EntityManager; -public class NLS -{ - public static MessageUtil MESSAGES = MessageUtil.createMessageUtil(NLS.class, "org.apache.aries.jpa.container.nls.jpaContainerMessages"); -} \ No newline at end of file +public interface EmFunction<R> { + R apply(EntityManager em); +} Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/JpaTemplate.java (from r1680054, aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/DestroyCallback.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/JpaTemplate.java?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/JpaTemplate.java&p1=aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/DestroyCallback.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/DestroyCallback.java (original) +++ aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/JpaTemplate.java Tue May 19 09:47:49 2015 @@ -1,26 +1,28 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.aries.jpa.container.context.transaction.impl; - -/** - * A callback to indicate that a destroy operation has completed - */ -public interface DestroyCallback { - public void callback(); -} +/* + * 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 WARRANTIESOR 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.jpa.template; + + +public interface JpaTemplate { + <R> R txExpr(TransactionType type, EmFunction<R> code); + void tx(TransactionType type, EmConsumer code); + + <R> R txExpr(EmFunction<R> code); + void tx(EmConsumer code); +} Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/TransactionType.java (from r1680054, aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/TransactionType.java?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/TransactionType.java&p1=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java (original) +++ aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/TransactionType.java Tue May 19 09:47:49 2015 @@ -1,27 +1,23 @@ -/** - * 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.jpa.container.sync; - -public interface Synchronization { - - void preCall(); - - void postCall(); - -} +/** + * 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.jpa.template; + +public enum TransactionType { + Mandatory, Never, NotSupported, Required, RequiresNew, Supports +} Copied: aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/packageinfo (from r1680054, aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/packageinfo?p2=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/template/packageinfo&p1=aries/trunk/jpa/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== (empty) Added: aries/trunk/jpa/jpa-blueprint/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/pom.xml?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/jpa-blueprint/pom.xml (added) +++ aries/trunk/jpa/jpa-blueprint/pom.xml Tue May 19 09:47:49 2015 @@ -0,0 +1,61 @@ +<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.jpa</groupId> + <artifactId>org.apache.aries.jpa.parent</artifactId> + <version>2.0.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + <artifactId>org.apache.aries.jpa.blueprint</artifactId> + <name>Apache Aries JPA blueprint</name> + <packaging>bundle</packaging> + + <properties> + <aries.skip.version.check>true</aries.skip.version.check> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.aries.jpa</groupId> + <artifactId>org.apache.aries.jpa.api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + <version>1.0.1.Final</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jta_1.1_spec</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>org.apache.aries.blueprint.core</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Bundle-Activator>org.apache.aries.jpa.blueprint.impl.Activator</Bundle-Activator> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <description>Blueprint integration for injecting EntityManager, EntityManagerFactory and EmSupplier.</description> +</project> \ No newline at end of file Copied: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/Activator.java (from r1680054, aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/Activator.java?p2=aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/Activator.java&p1=aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java (original) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/Activator.java Tue May 19 09:47:49 2015 @@ -1,46 +1,42 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.aries.util; - -import org.osgi.framework.ServiceRegistration; - -/** - * A fake class for testing - */ -public final class AriesFrameworkUtil -{ - - /** - * Safely unregister the supplied ServiceRegistration, for when you don't - * care about the potential IllegalStateException and don't want - * it to run wild through your code - * - * @param reg The {@link ServiceRegistration}, may be null - */ - public static void safeUnregisterService(ServiceRegistration reg) - { - if(reg != null) { - try { - reg.unregister(); - } catch (IllegalStateException e) { - //This can be safely ignored - } - } - } -} +/** + * 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.jpa.blueprint.impl; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.aries.blueprint.NamespaceHandler; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + @Override + public void start(BundleContext context) throws Exception { + JpaNsHandler handler = new JpaNsHandler(); + Dictionary<String, String> props = new Hashtable<String, String>(); + props.put("osgi.service.blueprint.namespace", "http://aries.apache.org/xmlns/jpan/v1.0.0"); + context.registerService(NamespaceHandler.class, handler, props); + } + + @Override + public void stop(BundleContext context) throws Exception { + } + +} Added: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaBeanProcessor.java URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaBeanProcessor.java?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaBeanProcessor.java (added) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaBeanProcessor.java Tue May 19 09:47:49 2015 @@ -0,0 +1,116 @@ +/** + * 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.jpa.blueprint.impl; + +import java.lang.reflect.Field; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.apache.aries.blueprint.BeanProcessor; +import org.apache.aries.blueprint.ComponentDefinitionRegistry; +import org.apache.aries.blueprint.Interceptor; +import org.apache.aries.jpa.blueprint.supplier.impl.EmProxyFactory; +import org.apache.aries.jpa.blueprint.supplier.impl.EmSupplierProxy; +import org.apache.aries.jpa.supplier.EmSupplier; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.service.blueprint.reflect.BeanMetadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JpaBeanProcessor implements BeanProcessor { + private static final Logger LOGGER = LoggerFactory.getLogger(JpaInterceptor.class); + public static final String JPA_PROCESSOR_BEAN_NAME = "org_apache_aries_jpan"; + private Map<Object, EmSupplierProxy> proxies; + private ComponentDefinitionRegistry cdr; + + public JpaBeanProcessor() { + proxies = new ConcurrentHashMap<Object, EmSupplierProxy>(); + } + + public void setCdr(ComponentDefinitionRegistry cdr) { + this.cdr = cdr; + } + + public void afterDestroy(Object bean, String beanName) { + EmSupplierProxy proxy = proxies.get(bean); + if (proxy != null) { + proxy.close(); + } + } + + public Object afterInit(Object bean, String beanName, BeanCreator beanCreator, BeanMetadata beanData) { + return bean; + } + + public void beforeDestroy(Object bean, String beanName) { + } + + public Object beforeInit(Object bean, String beanName, BeanCreator beanCreator, BeanMetadata beanData) { + Class<?> c = bean.getClass(); + Field field = getEmSupplierField(c); + if (field == null) { + return bean; + } + PersistenceContext pcAnn = field.getAnnotation(PersistenceContext.class); + if (pcAnn == null) { + return bean; + } + + LOGGER.debug("Adding jpa/jta interceptor bean {} with class {}", beanName, c); + + field.setAccessible(true); + BundleContext context = FrameworkUtil.getBundle(c).getBundleContext(); + EmSupplierProxy supplierProxy = new EmSupplierProxy(context, pcAnn.unitName()); + proxies.put(bean, supplierProxy); + try { + field.set(bean, getProxy(field, supplierProxy)); + } catch (Exception e) { + throw new IllegalStateException("Error setting field " + field, e); + } + Interceptor interceptor = new JpaInterceptor(supplierProxy); + cdr.registerInterceptorWithComponent(beanData, interceptor); + return bean; + } + + private Object getProxy(Field field, EmSupplierProxy supplierProxy) { + if (field.getType() == EmSupplier.class) { + return supplierProxy; + } else if (field.getType() == EntityManager.class) { + return EmProxyFactory.create(supplierProxy); + } else { + throw new IllegalStateException( + "Field with @PersistenceContext is not of type EntityManager or EmSupplier " + + field); + } + } + + private Field getEmSupplierField(Class<?> c) { + for (Field field : c.getDeclaredFields()) { + if (field.getAnnotation(PersistenceContext.class) != null) { + return field; + } + } + return null; + } + +} Added: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java (added) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java Tue May 19 09:47:49 2015 @@ -0,0 +1,103 @@ +/* + * 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.jpa.blueprint.impl; + +import java.lang.reflect.Method; + +import javax.persistence.EntityManager; +import javax.persistence.spi.PersistenceUnitTransactionType; + +import org.apache.aries.blueprint.Interceptor; +import org.apache.aries.jpa.supplier.EmSupplier; +import org.osgi.service.blueprint.reflect.ComponentMetadata; + +public class JpaInterceptor implements Interceptor { + private EmSupplier emSupplier; + private Boolean cachedIsResourceLocal; + + public JpaInterceptor(EmSupplier emSupplier) { + this.emSupplier = emSupplier; + } + + public int getRank() { + return 0; + } + + public Object preCall(ComponentMetadata cm, Method m, Object... parameters) throws Throwable { + try { + emSupplier.preCall(); + EntityManager em = emSupplier.get(); + boolean weControlTx = isResourceLocal(em) && !em.getTransaction().isActive(); + if (weControlTx) { + em.getTransaction().begin(); + } + return weControlTx; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public void postCallWithException(ComponentMetadata cm, Method m, Throwable ex, Object preCallToken) { + boolean weControlTx = (Boolean)preCallToken; + if (weControlTx) { + safeRollback(emSupplier.get(), ex); + } + emSupplier.postCall(); + } + + public void postCallWithReturn(ComponentMetadata cm, Method m, Object returnType, Object preCallToken) + throws Exception { + boolean weControlTx = (Boolean)preCallToken; + if (weControlTx) { + emSupplier.get().getTransaction().commit(); + } + emSupplier.postCall(); + } + + private void safeRollback(EntityManager em, Throwable e) { + if (em != null) { + try { + em.getTransaction().rollback(); + } catch (Exception e1) { + } + } + } + + private boolean isResourceLocal(EntityManager em) { + if (cachedIsResourceLocal == null) { + cachedIsResourceLocal = isResourceLocalInternal(em); + } + return cachedIsResourceLocal; + } + + /** + * @param em + * @return + */ + private boolean isResourceLocalInternal(EntityManager em) { + PersistenceUnitTransactionType transactionType = (PersistenceUnitTransactionType)em.getProperties() + .get(PersistenceUnitTransactionType.class.getName()); + if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL) { + return true; + } else { + return false; + } + } +} Added: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaNsHandler.java URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaNsHandler.java?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaNsHandler.java (added) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaNsHandler.java Tue May 19 09:47:49 2015 @@ -0,0 +1,120 @@ +/* + * 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.jpa.blueprint.impl; + +import static org.osgi.service.jpa.EntityManagerFactoryBuilder.JPA_UNIT_NAME; + +import java.net.URL; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import javax.transaction.TransactionManager; + +import org.apache.aries.blueprint.ComponentDefinitionRegistry; +import org.apache.aries.blueprint.NamespaceHandler; +import org.apache.aries.blueprint.ParserContext; +import org.apache.aries.blueprint.mutable.MutableBeanMetadata; +import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata; +import org.apache.aries.blueprint.mutable.MutableReferenceMetadata; +import org.apache.aries.jpa.supplier.EmSupplier; +import org.osgi.service.blueprint.reflect.ComponentMetadata; +import org.osgi.service.blueprint.reflect.Metadata; +import org.osgi.service.blueprint.reflect.ReferenceMetadata; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +public class JpaNsHandler implements NamespaceHandler { + + private void parseElement(Element elt, ComponentMetadata cm, ParserContext pc) { + ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry(); + + if ("enable".equals(elt.getLocalName())) { + if (!cdr.containsComponentDefinition(JpaBeanProcessor.JPA_PROCESSOR_BEAN_NAME)) { + MutableBeanMetadata meta = pc.createMetadata(MutableBeanMetadata.class); + meta.setId(JpaBeanProcessor.JPA_PROCESSOR_BEAN_NAME); + meta.setRuntimeClass(JpaBeanProcessor.class); + meta.setProcessor(true); + meta.addProperty("cdr", passThrough(pc, cdr)); + cdr.registerComponentDefinition(meta); + } + } + } + + private MutablePassThroughMetadata passThrough(ParserContext pc, Object obj) { + MutablePassThroughMetadata cdrMeta = pc.createMetadata(MutablePassThroughMetadata.class); + cdrMeta.setObject(obj); + return cdrMeta; + } + + public ComponentMetadata decorate(Node node, ComponentMetadata cm, ParserContext pc) { + System.out.println(cm.getId()); + if (node instanceof Element) { + Element elt = (Element)node; + parseElement(elt, cm, pc); + } + return cm; + } + + public Metadata parse(Element elt, ParserContext pc) { + parseElement(elt, pc.getEnclosingComponent(), pc); + return null; + } + + public URL getSchemaLocation(String namespace) { + return this.getClass().getResource("/jpa10.xsd"); + } + + @SuppressWarnings("rawtypes") + public Set<Class> getManagedClasses() { + return null; + } + + @SuppressWarnings("unchecked") + ComponentMetadata createEmSupplierRef(ParserContext pc, String unitName) { + final MutableReferenceMetadata refMetadata = pc.createMetadata(MutableReferenceMetadata.class); + refMetadata.setActivation(getDefaultActivation(pc)); + refMetadata.setAvailability(ReferenceMetadata.AVAILABILITY_MANDATORY); + refMetadata.setRuntimeInterface(EmSupplier.class); + refMetadata.setInterface(EmSupplier.class.getName()); + refMetadata.setFilter(String.format("(%s=%s)", JPA_UNIT_NAME, unitName)); + refMetadata.setTimeout(Integer.parseInt(pc.getDefaultTimeout())); + refMetadata.setDependsOn((List<String>)Collections.EMPTY_LIST); + refMetadata.setId(pc.generateId()); + return refMetadata; + } + + @SuppressWarnings("unchecked") + ComponentMetadata createTransactionManagerRef(ParserContext pc) { + final MutableReferenceMetadata refMetadata = pc.createMetadata(MutableReferenceMetadata.class); + refMetadata.setActivation(getDefaultActivation(pc)); + refMetadata.setAvailability(ReferenceMetadata.AVAILABILITY_MANDATORY); + refMetadata.setRuntimeInterface(TransactionManager.class); + refMetadata.setInterface(TransactionManager.class.getName()); + refMetadata.setTimeout(Integer.parseInt(pc.getDefaultTimeout())); + refMetadata.setDependsOn((List<String>)Collections.EMPTY_LIST); + refMetadata.setId(pc.generateId()); + return refMetadata; + } + + private int getDefaultActivation(ParserContext ctx) { + return "ACTIVATION_EAGER".equalsIgnoreCase(ctx.getDefaultActivation()) + ? ReferenceMetadata.ACTIVATION_EAGER : ReferenceMetadata.ACTIVATION_LAZY; + } +} Copied: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxy.java (from r1680054, aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxy.java?p2=aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxy.java&p1=aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidPersistenceUnitException.java (original) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxy.java Tue May 19 09:47:49 2015 @@ -16,24 +16,29 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.aries.jpa.container.impl; +package org.apache.aries.jpa.blueprint.supplier.impl; -/** - * This exception is thrown if an {@link EntityManagerFactoryManager} has - * entered an invalid state and needs to be destroyed - */ -public class InvalidPersistenceUnitException extends Exception { +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +import javax.persistence.EntityManager; + +import org.apache.aries.jpa.supplier.EmSupplier; + +public class EmProxy implements InvocationHandler { + EmSupplier emSupplier; - /** - * For serialization - */ - private static final long serialVersionUID = 6523462131213055375L; - - public InvalidPersistenceUnitException(Exception e) { - super(e); - } + public EmProxy(EmSupplier emSupplier) { + this.emSupplier = emSupplier; + } - public InvalidPersistenceUnitException() { - } + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + EntityManager em = emSupplier.get(); + if (em == null) { + throw new IllegalStateException("EntityManager not available. Make sure you run in an @Transactional method"); + } + return method.invoke(em, args); + } } Copied: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxyFactory.java (from r1680054, aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/util/FakeManagedPersistenceUnitFactory.java) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxyFactory.java?p2=aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxyFactory.java&p1=aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/util/FakeManagedPersistenceUnitFactory.java&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/util/FakeManagedPersistenceUnitFactory.java (original) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmProxyFactory.java Tue May 19 09:47:49 2015 @@ -16,21 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.aries.jpa.container.util; +package org.apache.aries.jpa.blueprint.supplier.impl; -import org.apache.aries.jpa.container.ManagedPersistenceUnitInfoFactory; -import org.apache.aries.jpa.container.unit.impl.ManagedPersistenceUnitInfoFactoryImpl; +import java.lang.reflect.Proxy; -public class FakeManagedPersistenceUnitFactory extends - ManagedPersistenceUnitInfoFactoryImpl implements - ManagedPersistenceUnitInfoFactory { +import javax.persistence.EntityManager; - @Override - public String getDefaultProviderClassName() { - // TODO Auto-generated method stub - return "use.this.Provider"; - } - - +import org.apache.aries.jpa.supplier.EmSupplier; +public class EmProxyFactory { + + public static EntityManager create(final EmSupplier emSupplier) { + ClassLoader loader = EntityManager.class.getClassLoader(); + Class<?>[] ifAr = { + EntityManager.class + }; + return (EntityManager)Proxy.newProxyInstance(loader, ifAr, new EmProxy(emSupplier)); + } } Added: aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmSupplierProxy.java URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmSupplierProxy.java?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmSupplierProxy.java (added) +++ aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/supplier/impl/EmSupplierProxy.java Tue May 19 09:47:49 2015 @@ -0,0 +1,79 @@ +/* + * 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 WARRANTIESOR 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.jpa.blueprint.supplier.impl; + +import static org.osgi.service.jpa.EntityManagerFactoryBuilder.JPA_UNIT_NAME; + +import java.io.Closeable; + +import javax.persistence.EntityManager; + +import org.apache.aries.jpa.supplier.EmSupplier; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.util.tracker.ServiceTracker; + +public class EmSupplierProxy implements EmSupplier, Closeable { + private ServiceTracker<EmSupplier, EmSupplier> tracker; + + public EmSupplierProxy(BundleContext context, String unitName) { + String filterS = String.format("(&(objectClass=%s)(%s=%s))", EmSupplier.class.getName(), + JPA_UNIT_NAME, + unitName); + Filter filter; + try { + filter = FrameworkUtil.createFilter(filterS); + } catch (InvalidSyntaxException e) { + throw new IllegalStateException(e); + } + tracker = new ServiceTracker<>(context, filter, null); + tracker.open(); + } + + @Override + public EntityManager get() { + return getEmSupplier().get(); + } + + @Override + public void close() { + tracker.close(); + } + + @Override + public void preCall() { + getEmSupplier().preCall(); + } + + @Override + public void postCall() { + getEmSupplier().postCall(); + } + + private EmSupplier getEmSupplier() { + try { + return tracker.waitForService(10000); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + } + +} Copied: aries/trunk/jpa/jpa-blueprint/src/main/resources/jpa10.xsd (from r1680054, aries/trunk/jpa/jpa-blueprint-aries/src/test/resources/jpa.xml) URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/resources/jpa10.xsd?p2=aries/trunk/jpa/jpa-blueprint/src/main/resources/jpa10.xsd&p1=aries/trunk/jpa/jpa-blueprint-aries/src/test/resources/jpa.xml&r1=1680054&r2=1680218&rev=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-blueprint-aries/src/test/resources/jpa.xml (original) +++ aries/trunk/jpa/jpa-blueprint/src/main/resources/jpa10.xsd Tue May 19 09:47:49 2015 @@ -1,5 +1,6 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- + 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. @@ -14,33 +15,14 @@ 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. ---> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"> - <bean id="unit"> - <jpa:unit property="emf" unitname="myUnit" /> - </bean> - - <bean id="unitNoName"> - <jpa:unit property="emf2" /> - </bean> - - <bean id="emptyUnitName"> - <jpa:unit property="emf3" unitname="" /> - </bean> - - <bean id="context"> - <jpa:context property="em" unitname="myUnit"/> - </bean> - - <bean id="contextWithProps"> - <jpa:context property="em" type="EXTENDED"> - <jpa:map> - <entry key="one" value="eins" /> - <entry key="two" value="zwo" /> - </jpa:map> - </jpa:context> - </bean> +--> +<xsd:schema xmlns="http://aries.apache.org/xmlns/jpan/v1.0.0" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://aries.apache.org/xmlns/jpan/v1.0.0" + elementFormDefault="qualified" + attributeFormDefault="unqualified" + version="1.0.0"> -</blueprint> \ No newline at end of file + <xsd:element name="enable" type="xsd:string"></xsd:element> +</xsd:schema> Modified: aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml?rev=1680218&r1=1680217&r2=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml (original) +++ aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml Tue May 19 09:47:49 2015 @@ -32,7 +32,7 @@ <artifactId>org.apache.aries.jpa.eclipselink.adapter</artifactId> <packaging>bundle</packaging> <version>1.0.0-SNAPSHOT</version> - <name>Aries JPA Container adapter for use with EclipseLink</name> + <name>Apache Aries JPA Container adapter for EclipseLink</name> <scm> <connection>scm:svn:http://svn.apache.org/repos/asf/aries/trunk/jpa/jpa-container-eclipselink-adapter</connection> Modified: aries/trunk/jpa/jpa-container/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/pom.xml?rev=1680218&r1=1680217&r2=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/pom.xml (original) +++ aries/trunk/jpa/jpa-container/pom.xml Tue May 19 09:47:49 2015 @@ -17,22 +17,21 @@ 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"> - +<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.0</version> - <relativePath>../../parent/pom.xml</relativePath> + <groupId>org.apache.aries.jpa</groupId> + <artifactId>org.apache.aries.jpa.parent</artifactId> + <version>2.0.0-SNAPSHOT</version> </parent> - - <groupId>org.apache.aries.jpa</groupId> <artifactId>org.apache.aries.jpa.container</artifactId> + <name>Apache Aries JPA container</name> <packaging>bundle</packaging> - <version>1.0.3-SNAPSHOT</version> - <name>Aries JPA Container</name> + + <properties> + <aries.skip.version.check>true</aries.skip.version.check> + </properties> <scm> <connection>scm:svn:http://svn.apache.org/repos/asf/aries/trunk/jpa/jpa-container</connection> @@ -40,126 +39,51 @@ <url>http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container</url> </scm> - <properties> - <!-- Export package versions are maintained in packageinfo files --> - <aries.osgi.export.pkg /> - <aries.osgi.import> - javax.persistence;version="[1.0.0,3.0.0)", - javax.persistence.spi;version="[1.0.0,3.0.0)", - javax.persistence.criteria;version="[1.1.0,3.0.0)";resolution:=optional, - javax.persistence.metamodel;version="[1.1.0,3.0.0)";resolution:=optional, - !javax.transaction, - org.apache.aries.jpa.container*;provide:=true, - org.apache.aries.quiesce.manager;provide:=true;resolution:=optional, - org.apache.aries.quiesce.participant;provide:=true;resolution:=optional, - org.osgi.framework;version="[1.5,2)", - org.osgi.framework.hooks.weaving;resolution:=optional, - org.osgi.framework.wiring;resolution:=optional, - org.osgi.service.jdbc;resolution:=optional, - * - </aries.osgi.import> - <aries.osgi.dynamic> - javax.transaction;version="[1.1,2)" - </aries.osgi.dynamic> - <aries.osgi.activator> - org.apache.aries.jpa.container.impl.Activator - </aries.osgi.activator> - <lastReleaseVersion>1.0.0</lastReleaseVersion> - </properties> - <dependencies> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> - <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <artifactId>org.apache.aries.jpa.api</artifactId> - <groupId>org.apache.aries.jpa</groupId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>org.apache.aries.quiesce</groupId> - <artifactId>org.apache.aries.quiesce.api</artifactId> - <version>1.0.0</version> - <scope>provided</scope> </dependency> <dependency> - <artifactId>org.apache.aries.util</artifactId> - <groupId>org.apache.aries</groupId> - <version>1.0.0</version> - <scope>provided</scope> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + <version>1.0.1.Final</version> </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jpa_2.0_spec</artifactId> - <version>1.1</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.aries.testsupport</groupId> - <artifactId>org.apache.aries.testsupport.unit</artifactId> - <version>1.0.0</version> - <scope>test</scope> - </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.enterprise</artifactId> - <version>4.2.0</version> - <scope>provided</scope> + <groupId>org.apache.xbean</groupId> + <artifactId>xbean-bundleutils</artifactId> + <version>4.1</version> + <optional>true</optional> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jta_1.1_spec</artifactId> - <version>1.1.1</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.8.2</version> - <scope>test</scope> + <groupId>org.apache.xbean</groupId> + <artifactId>xbean-finder</artifactId> + <version>4.1</version> + <optional>true</optional> </dependency> </dependencies> <build> <plugins> <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> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Bundle-Activator>org.apache.aries.jpa.container.impl.Activator</Bundle-Activator> + <Export-Package> + org.osgi.service.jdbc, + org.osgi.service.jpa + </Export-Package> + </instructions> + </configuration> </plugin> </plugins> </build> - -</project> + <description>Implements the OSGi JPA Container from the enterprise spec. Provider a EntityManagerFactory and EntityManagerFactoryBuilder service</description> +</project> \ No newline at end of file Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/Activator.java URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/Activator.java?rev=1680218&r1=1680217&r2=1680218&view=diff ============================================================================== --- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/Activator.java (original) +++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/Activator.java Tue May 19 09:47:49 2015 @@ -1,26 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIESOR 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.jpa.container.impl; -import org.apache.aries.jpa.container.parsing.PersistenceDescriptorParser; -import org.apache.aries.jpa.container.parsing.impl.PersistenceDescriptorParserImpl; -import org.apache.aries.jpa.container.tx.impl.OSGiTransactionManager; +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.aries.jpa.container.weaving.impl.TransformerRegistry; +import org.apache.aries.jpa.container.weaving.impl.TransformerRegistrySingleton; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.hooks.weaving.WeavingHook; +import org.osgi.util.tracker.BundleTracker; public class Activator implements BundleActivator { - private PersistenceBundleManager pbm; + private BundleTracker<Bundle> persistenceBundleManager; + + @Override public void start(BundleContext context) throws Exception { - PersistenceDescriptorParser parser = new PersistenceDescriptorParserImpl(); - context.registerService(PersistenceDescriptorParser.class.getName(), parser, null); - pbm = new PersistenceBundleManager(context, parser); - pbm.open(); + registerWeavingHook(context, TransformerRegistrySingleton.get()); + + PersistenceBundleTracker customizer = new PersistenceBundleTracker(context); + persistenceBundleManager = new BundleTracker<>(context, Bundle.STARTING | Bundle.ACTIVE, customizer); + persistenceBundleManager.open(); + } + + /** + * ARIES-1019: Register with the highest possible service ranking to + * avoid ClassNotFoundException caused by interfaces added by earlier + * weaving hooks that are not yet visible to the bundle class loader. + */ + private void registerWeavingHook(BundleContext context, TransformerRegistry tr) { + Dictionary<String, Object> props = new Hashtable<String, Object>(1); + props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE); + context.registerService(WeavingHook.class.getName(), tr, props); } + @Override public void stop(BundleContext context) throws Exception { - pbm.close(); - OSGiTransactionManager otm = OSGiTransactionManager.get(); - if (otm != null) - otm.destroy(); + persistenceBundleManager.close(); } } Added: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java?rev=1680218&view=auto ============================================================================== --- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java (added) +++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/AriesEntityManagerFactoryBuilder.java Tue May 19 09:47:49 2015 @@ -0,0 +1,58 @@ +/* + * 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 WARRANTIESOR 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.jpa.container.impl; + +import java.util.Map; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.spi.PersistenceProvider; +import javax.persistence.spi.PersistenceUnitInfo; + +import org.osgi.service.jpa.EntityManagerFactoryBuilder; + +/** + * FIXME We are currently not configuring a DataSource for the persistence unit. + * It still works in the tests as the DataSource is defined in the DataSourceTracker or DSFTracker. + * This not fully correct though. + */ +public class AriesEntityManagerFactoryBuilder implements EntityManagerFactoryBuilder { + private static final String JAVAX_PERSISTENCE_JDBC_DRIVER = "javax.persistence.jdbc.driver"; + + private PersistenceProvider provider; + private PersistenceUnitInfo persistenceUnit; + private String driver; + + public AriesEntityManagerFactoryBuilder(PersistenceProvider provider, PersistenceUnitInfo persistenceUnit) { + this.provider = provider; + this.persistenceUnit = persistenceUnit; + this.driver = (String)persistenceUnit.getProperties().get(JAVAX_PERSISTENCE_JDBC_DRIVER); + } + + @Override + public EntityManagerFactory createEntityManagerFactory(Map<String, Object> props) { + String newDriver = (String)props.get(JAVAX_PERSISTENCE_JDBC_DRIVER); + if (driver == null) { + driver = newDriver; + } else if (newDriver != null && !newDriver.equals(driver)){ + throw new IllegalArgumentException("Can not rebind to a different database driver"); + } + return provider.createContainerEntityManagerFactory(persistenceUnit, props); + } + +}
