├── .gitignore ├── .travis.yml ├── LICENSE ├── NOTICE ├── README.md ├── examples ├── README.md ├── org.ops4j.datasource-tasklist.cfg ├── pom.xml ├── tasklist-blueprint │ ├── .gitignore │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── aries │ │ │ │ └── jpa │ │ │ │ └── example │ │ │ │ └── tasklist │ │ │ │ └── blueprint │ │ │ │ └── impl │ │ │ │ ├── TaskServiceImpl.java │ │ │ │ └── TasklistServlet.java │ │ └── resources │ │ │ └── OSGI-INF │ │ │ └── blueprint │ │ │ └── context.xml │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── example │ │ │ └── tasklist │ │ │ └── blueprint │ │ │ └── impl │ │ │ └── TaskServiceImplTest.java │ │ └── resources │ │ └── META-INF │ │ └── persistence.xml ├── tasklist-cdi │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── aries │ │ │ │ └── jpa │ │ │ │ └── example │ │ │ │ └── tasklist │ │ │ │ └── cdi │ │ │ │ └── impl │ │ │ │ ├── TaskServiceImpl.java │ │ │ │ └── TasklistServlet.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── beans.xml │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── example │ │ │ └── tasklist │ │ │ └── cdi │ │ │ └── impl │ │ │ └── TaskServiceImplTest.java │ │ └── resources │ │ └── META-INF │ │ └── persistence.xml ├── tasklist-ds │ ├── .gitignore │ ├── README.txt │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── example │ │ │ └── tasklist │ │ │ └── ds │ │ │ └── impl │ │ │ ├── TaskServiceImpl.java │ │ │ ├── TasklistAdder.java │ │ │ └── TasklistServlet.java │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── tasklist │ │ │ └── closure │ │ │ └── impl │ │ │ └── TaskServiceImplTest.java │ │ └── resources │ │ └── META-INF │ │ └── persistence.xml └── tasklist-model │ ├── .gitignore │ ├── osgi.bnd │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── example │ │ └── tasklist │ │ └── model │ │ ├── Task.java │ │ └── TaskService.java │ └── resources │ └── META-INF │ └── persistence.xml ├── itests ├── jpa-container-blueprint-testbundle-dao │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── container │ │ │ └── itest │ │ │ └── bundle │ │ │ └── blueprint │ │ │ ├── CarDao.java │ │ │ ├── NewTxTestService.java │ │ │ ├── TestService.java │ │ │ ├── dao │ │ │ └── CarDaoImpl.java │ │ │ └── impl │ │ │ ├── NewTxTestServiceImpl.java │ │ │ └── TestServiceImpl.java │ │ └── resources │ │ └── OSGI-INF │ │ └── blueprint │ │ └── config.xml ├── jpa-container-blueprint-testbundle │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── container │ │ │ └── itest │ │ │ └── bundle │ │ │ └── blueprint │ │ │ └── impl │ │ │ ├── AbstractCarServiceImpl.java │ │ │ ├── CarLifeCycle.java │ │ │ ├── CarServiceEmJtaAnn.java │ │ │ ├── CarServiceImpl.java │ │ │ ├── CarServiceWithEmfImpl.java │ │ │ ├── CarServiceWithMethodImpl.java │ │ │ ├── CarServiceWithMultiAnnotationImpl.java │ │ │ ├── CarServiceWithRequiresNew.java │ │ │ └── CarServiceWithSupplierImpl.java │ │ └── resources │ │ └── OSGI-INF │ │ └── blueprint │ │ └── config.xml ├── jpa-container-itest-karaf │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── itest │ │ │ └── karaf │ │ │ ├── AbstractJPAItest.java │ │ │ ├── BlueprintTest.java │ │ │ └── DSTest.java │ │ └── resources │ │ ├── org.ops4j.pax.logging.cfg │ │ └── persistence.xml ├── jpa-container-itest │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ ├── blueprint │ │ │ └── aries │ │ │ │ └── itest │ │ │ │ ├── BlueprintDaoTest.java │ │ │ │ └── BlueprintTest.java │ │ │ ├── container │ │ │ └── itest │ │ │ │ ├── EclipseAdditionalTest.java │ │ │ │ ├── JPAContainerEclipseLinkTest.java │ │ │ │ ├── JPAContainerHibernate5_2Test.java │ │ │ │ ├── JPAContainerHibernateTest.java │ │ │ │ ├── JPAContainerOpenJPATest.java │ │ │ │ └── JPAContainerTest.java │ │ │ └── itest │ │ │ ├── AbstractCarJPAITest.java │ │ │ └── AbstractJPAItest.java │ │ └── resources │ │ ├── config │ │ ├── org.ops4j.datasource-testds.cfg │ │ ├── org.ops4j.datasource-testdsxa.cfg │ │ └── org.ops4j.pax.logging.cfg │ │ └── persistence.xml ├── jpa-container-testbundle-eclipselink │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── container │ │ │ └── itest │ │ │ └── eclipselink │ │ │ └── entities │ │ │ ├── Car2.java │ │ │ └── packageinfo │ │ └── resources │ │ └── META-INF │ │ ├── persistence.xml │ │ └── sql │ │ ├── create.sql │ │ ├── data.sql │ │ └── drop.sql ├── jpa-container-testbundle │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── container │ │ │ └── itest │ │ │ └── entities │ │ │ ├── Car.java │ │ │ ├── CarService.java │ │ │ ├── mapped │ │ │ ├── Truck.java │ │ │ └── packageinfo │ │ │ └── packageinfo │ │ └── resources │ │ └── META-INF │ │ ├── custom-mapping.xml │ │ └── persistence.xml ├── jpa-tck-itest │ ├── README.txt │ ├── org.osgi.test.cases.jpa.bnd │ ├── pom.xml │ └── runtests └── pom.xml ├── javax-persistence ├── 2_0 │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── javax │ │ └── persistence │ │ ├── AriesJPASpecActivator.java │ │ └── EMFBuilderServiceResolver.java ├── 2_1 │ ├── .gitignore │ ├── LICENSE │ ├── NOTICE │ ├── osgi.bnd │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── javax │ │ └── persistence │ │ ├── AriesJPASpecActivator.java │ │ └── EMFBuilderServiceResolver.java ├── README.md └── pom.xml ├── jpa-api ├── .gitignore ├── LICENSE ├── NOTICE ├── osgi.bnd ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── apache │ └── aries │ └── jpa │ ├── supplier │ ├── EmSupplier.java │ └── packageinfo │ └── template │ ├── EmConsumer.java │ ├── EmFunction.java │ ├── JpaTemplate.java │ ├── TransactionType.java │ └── packageinfo ├── jpa-blueprint ├── .gitignore ├── osgi.bnd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── aries │ │ │ └── jpa │ │ │ └── blueprint │ │ │ └── impl │ │ │ ├── Activator.java │ │ │ ├── AnnotationScanner.java │ │ │ ├── JpaComponentProcessor.java │ │ │ ├── JpaInterceptor.java │ │ │ ├── JpaNsHandler.java │ │ │ └── ResourceLocalTransactionParticipant.java │ └── resources │ │ ├── jpa20.xsd │ │ └── jpan10.xsd │ └── test │ └── java │ └── org │ └── apache │ └── aries │ └── jpa │ └── blueprint │ └── impl │ ├── AnnotationScannerTest.java │ ├── BlueprintContainerStub.java │ ├── CoordinatorStub.java │ ├── EntityManagerStub.java │ ├── JpaInterceptorTest.java │ ├── TestClass.java │ └── TestInterface.java ├── jpa-cdi ├── osgi.bnd ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── cdi │ │ ├── EntityManagerProducer.java │ │ ├── JpaExtension.java │ │ ├── PersistenceAnnotatedType.java │ │ ├── TransactionExtension.java │ │ ├── TransactionSupport.java │ │ ├── TransactionalContext.java │ │ ├── TransactionalInterceptor.java │ │ └── support │ │ ├── FilterLiteral.java │ │ ├── ForwardingAnnotatedField.java │ │ ├── ForwardingAnnotatedType.java │ │ ├── InjectLiteral.java │ │ ├── ServiceLiteral.java │ │ ├── SimpleBean.java │ │ ├── SyntheticAnnotatedField.java │ │ ├── UniqueIdentifier.java │ │ └── UniqueIdentifierLitteral.java │ └── resources │ └── META-INF │ ├── beans.xml │ └── services │ └── javax.enterprise.inject.spi.Extension ├── jpa-container-eclipselink-adapter ├── .gitignore ├── LICENSE ├── NOTICE ├── osgi.bnd ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── eclipselink │ │ └── adapter │ │ ├── Activator.java │ │ ├── EclipseLinkPersistenceProvider.java │ │ ├── PersistenceUnitProxyWithTargetServer.java │ │ ├── UnionClassLoader.java │ │ └── platform │ │ ├── OSGiTSServer.java │ │ └── OSGiTSWrapper.java │ └── resources │ └── org │ └── apache │ └── aries │ └── jpa │ └── eclipselink │ └── adapter │ └── jpaEclipseLinkAdapter.properties ├── jpa-container ├── .gitignore ├── LICENSE ├── NOTICE ├── osgi.bnd ├── pom.xml └── src │ ├── main │ ├── appended-resources │ │ └── META-INF │ │ │ ├── LICENSE.vm │ │ │ └── NOTICE.vm │ └── java │ │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── container │ │ ├── impl │ │ ├── Activator.java │ │ ├── AriesEntityManagerFactoryBuilder.java │ │ ├── DSFTracker.java │ │ ├── DataSourceTracker.java │ │ ├── ManagedEMF.java │ │ ├── PersistenceBundleTracker.java │ │ ├── PersistenceProviderTracker.java │ │ └── StoredPerProvider.java │ │ ├── parser │ │ └── impl │ │ │ ├── JPAAnnotationScanner.java │ │ │ ├── JPAHandler.java │ │ │ ├── PersistenceUnit.java │ │ │ ├── PersistenceUnitParser.java │ │ │ └── TempBundleDelegatingClassLoader.java │ │ └── weaving │ │ └── impl │ │ ├── DummyDataSource.java │ │ ├── JPAWeavingHook.java │ │ ├── TransformerRegistry.java │ │ ├── TransformerRegistrySingleton.java │ │ └── WrappingTransformer.java │ └── test │ └── java │ └── org │ └── apache │ └── aries │ └── jpa │ └── container │ └── impl │ ├── DataSourceTrackerTest.java │ ├── ManagedEMFTest.java │ └── PropsConfigurationTest.java ├── jpa-features ├── pom.xml └── src │ └── main │ └── feature │ └── feature.xml ├── jpa-parent └── pom.xml ├── jpa-repository └── pom.xml ├── jpa-support ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── osgi.bnd ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── aries │ │ └── jpa │ │ └── support │ │ ├── impl │ │ ├── AbstractJpaTemplate.java │ │ ├── EMSupplierImpl.java │ │ ├── ResourceLocalJpaTemplate.java │ │ └── XAJpaTemplate.java │ │ ├── osgi │ │ └── impl │ │ │ ├── Activator.java │ │ │ ├── CoordinatorTracker.java │ │ │ ├── EMFTracker.java │ │ │ ├── EmProxy.java │ │ │ └── TMTracker.java │ │ └── xa │ │ └── impl │ │ ├── TransactionAttribute.java │ │ └── TransactionToken.java │ └── test │ └── java │ └── org │ └── apache │ └── aries │ └── jpa │ ├── impl │ ├── DummyCoordination.java │ ├── DummyCoordinator.java │ └── EmSupplierTest.java │ └── support │ ├── impl │ └── XAJpaTemplateTest.java │ └── osgi │ └── impl │ └── EmfTrackerTest.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .classpath 3 | .settings 4 | .project 5 | .DS_Store 6 | *.iml 7 | .idea/ 8 | *.swp 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2010 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | Aries JPA includes the persistence schemas from the JPA specifications. 9 | Copyright 2005-2009 Sun Microsystems, Inc. All rights reserved. 10 | Aries JPA elects to include this software in this distribution under the 11 | CDDL license. You can obtain a copy of the License at: 12 | https://glassfish.dev.java.net/public/CDDL+GPL.html 13 | The source code is available at: 14 | https://glassfish.dev.java.net/source/browse/glassfish/ 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Aries JPA 2 | 3 | [![Build Status](https://builds.apache.org/buildStatus/icon?job=Aries-JPA-Trunk-JDK8)](https://builds.apache.org/job/Aries-JPA-Trunk-JDK8/) 4 | 5 | Implements the [JPA Service Specification from the OSGi compendium spec](https://osgi.org/specification/osgi.cmpn/7.0.0/service.jpa.html). Additionally some convenience 6 | services are provided to make it easier to use JPA in blueprint and DS. 7 | 8 | http://aries.apache.org/modules/jpaproject.html 9 | 10 | # Building 11 | 12 | mvn clean install 13 | 14 | # Examples 15 | 16 | See [examples](examples). 17 | 18 | # Running tck tests 19 | 20 | See itests/jpa-tck-itest/README.txt 21 | 22 | # Releasing 23 | 24 | Run the tck tests to make sure we are still conforming to the spec. 25 | 26 | mvn clean deploy 27 | mvn release:prepare -Darguments="-DskipTests" 28 | mvn release:perform 29 | 30 | After the release make sure to adapt the versions in the tck test modules. 31 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Installation instructions for jpa-examples 2 | 3 | Install at least Karaf 4.1.2 or 4.2.2. 4 | 5 | The blueprint example does not work in karaf 4.2.0 and 4.2.1. They deploy blueprint core 1.9.0 which has a severe [bug regarding 6 | interceptors](https://issues.apache.org/jira/browse/ARIES-1793). 7 | 8 | ## Copy DataSource config 9 | ``` 10 | cat https://raw.githubusercontent.com/apache/aries-jpa/master/examples/org.ops4j.datasource-tasklist.cfg | tac etc/org.ops4j.datasource-tasklist.cfg 11 | ``` 12 | 13 | ## Install features 14 | ``` 15 | feature:repo-add pax-jdbc 1.3.1 16 | feature:install scr transaction pax-jdbc-config pax-jdbc-h2 pax-jdbc-pool-dbcp2 http-whiteboard jpa hibernate 17 | ``` 18 | 19 | ### Closure based example. (Make sure to start karaf with JDK 8) 20 | ``` 21 | install -s mvn:org.apache.aries.jpa.example/org.apache.aries.jpa.example.tasklist.model/2.7.0 22 | install -s mvn:org.apache.aries.jpa.example/org.apache.aries.jpa.example.tasklist.ds/2.7.0 23 | ``` 24 | 25 | ### Blueprint based example 26 | ``` 27 | feature:install aries-blueprint 28 | install -s mvn:org.apache.aries.jpa.example/org.apache.aries.jpa.example.tasklist.model/2.7.0 29 | install -s mvn:org.apache.aries.jpa.example/org.apache.aries.jpa.example.tasklist.blueprint/2.7.0 30 | ``` 31 | 32 | ## Validate example 33 | 34 | After installing the examples you can check for the services. 35 | 36 | ``` 37 | service:list EntityManagerFactory 38 | ``` 39 | 40 | You should see a service for the persistence unit "tasklist". 41 | 42 | ``` 43 | service:list TaskService 44 | ``` 45 | 46 | You should see a service provided by either the tasklist.blueprint or tasklist.ds bundle depending on the example you installed. 47 | 48 | http://localhost:8181/tasklist 49 | 50 | If you open the above url in a webbrowser you should see a list with one task. 51 | Now add a task: 52 | http://localhost:8181/tasklist?add&taskId=4&title=Buy more coffee 53 | 54 | and check it is added to the list 55 | http://localhost:8181/tasklist 56 | -------------------------------------------------------------------------------- /examples/org.ops4j.datasource-tasklist.cfg: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | osgi.jdbc.driver.name=H2 18 | pool=dbcp2 19 | xa=true 20 | databaseName = tasklist;create=true 21 | dataSourceName = tasklist 22 | -------------------------------------------------------------------------------- /examples/tasklist-blueprint/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /examples/tasklist-blueprint/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA -------------------------------------------------------------------------------- /examples/tasklist-blueprint/src/main/java/org/apache/aries/jpa/example/tasklist/blueprint/impl/TaskServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.example.tasklist.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | 23 | import javax.persistence.EntityManager; 24 | import javax.persistence.PersistenceContext; 25 | import javax.persistence.criteria.CriteriaQuery; 26 | import javax.transaction.Transactional; 27 | import javax.transaction.Transactional.TxType; 28 | 29 | import org.apache.aries.jpa.example.tasklist.model.Task; 30 | import org.apache.aries.jpa.example.tasklist.model.TaskService; 31 | 32 | @Transactional 33 | public class TaskServiceImpl implements TaskService { 34 | 35 | @PersistenceContext(unitName = "tasklist") 36 | EntityManager em; 37 | 38 | @Transactional(TxType.SUPPORTS) 39 | @Override 40 | public Task getTask(Integer id) { 41 | return em.find(Task.class, id); 42 | } 43 | 44 | 45 | @Override 46 | public void addTask(Task task) { 47 | em.persist(task); 48 | em.flush(); 49 | } 50 | 51 | @Transactional(TxType.SUPPORTS) 52 | @Override 53 | public Collection getTasks() { 54 | CriteriaQuery query = em.getCriteriaBuilder().createQuery(Task.class); 55 | return em.createQuery(query.select(query.from(Task.class))).getResultList(); 56 | } 57 | 58 | @Override 59 | public void updateTask(Task task) { 60 | em.persist(task); 61 | } 62 | 63 | @Override 64 | public void deleteTask(Integer id) { 65 | em.remove(getTask(id)); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /examples/tasklist-blueprint/src/main/resources/OSGI-INF/blueprint/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /examples/tasklist-blueprint/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | 25 | org.hibernate.jpa.HibernatePersistenceProvider 26 | org.apache.aries.jpa.example.tasklist.model.Task 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/tasklist-cdi/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | Require-Capability: \ 19 | osgi.extender; filter:="(osgi.extender=pax.cdi)", \ 20 | org.ops4j.pax.cdi.extension; filter:="(extension=pax-cdi-extension2)", \ 21 | org.ops4j.pax.cdi.extension; filter:="(extension=aries-jpa-cdi)", 22 | -------------------------------------------------------------------------------- /examples/tasklist-cdi/src/main/java/org/apache/aries/jpa/example/tasklist/cdi/impl/TaskServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.example.tasklist.cdi.impl; 20 | 21 | import javax.persistence.EntityManager; 22 | import javax.persistence.PersistenceContext; 23 | import javax.persistence.criteria.CriteriaQuery; 24 | import javax.transaction.Transactional; 25 | import javax.transaction.Transactional.TxType; 26 | import java.util.Collection; 27 | 28 | import org.apache.aries.jpa.example.tasklist.model.Task; 29 | import org.apache.aries.jpa.example.tasklist.model.TaskService; 30 | 31 | @Transactional 32 | public class TaskServiceImpl implements TaskService { 33 | 34 | @PersistenceContext(unitName = "tasklist") 35 | EntityManager em; 36 | 37 | @Transactional(TxType.SUPPORTS) 38 | @Override 39 | public Task getTask(Integer id) { 40 | return em.find(Task.class, id); 41 | } 42 | 43 | 44 | @Override 45 | public void addTask(Task task) { 46 | em.persist(task); 47 | em.flush(); 48 | } 49 | 50 | @Transactional(TxType.SUPPORTS) 51 | @Override 52 | public Collection getTasks() { 53 | CriteriaQuery query = em.getCriteriaBuilder().createQuery(Task.class); 54 | return em.createQuery(query.select(query.from(Task.class))).getResultList(); 55 | } 56 | 57 | @Override 58 | public void updateTask(Task task) { 59 | em.persist(task); 60 | } 61 | 62 | @Override 63 | public void deleteTask(Integer id) { 64 | em.remove(getTask(id)); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /examples/tasklist-cdi/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/tasklist-cdi/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | 25 | org.hibernate.jpa.HibernatePersistenceProvider 26 | org.apache.aries.jpa.example.tasklist.model.Task 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/tasklist-ds/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /examples/tasklist-ds/README.txt: -------------------------------------------------------------------------------- 1 | Installation instructions on Karaf 4 2 | 3 | # Install DB and create DataSource service 4 | feature:repo-add pax-jdbc 0.6.0 5 | feature:install jdbc pax-jdbc-h2 pax-jdbc-config pax-jdbc-pool-dbcp2 6 | jdbc:ds-create -dn H2-pool-xa -url jdbc:h2:mem:tasklist tasklist 7 | 8 | # Install hibernate, aries jpa and example 9 | feature:install scr jpa hibernate/4.3.6.Final http-whiteboard 10 | install -s mvn:org.apache.aries.jpa.example/org.apache.aries.jpa.example.tasklist.model/2.0.0 11 | install -s mvn:org.apache.aries.jpa.example/org.apache.aries.jpa.example.tasklist.ds/2.0.0 12 | 13 | # This should show three active DS components 14 | scr:list 15 | 16 | # This should show the TaskService 17 | service:list TaskService 18 | 19 | # This should show the TasklistServlet 20 | http:list 21 | 22 | 23 | # Now open the url 24 | http://localhost:8181/tasklist 25 | # You should see one task named Task1 26 | -------------------------------------------------------------------------------- /examples/tasklist-ds/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -dsannotations: * 19 | 20 | -contract: JavaJPA -------------------------------------------------------------------------------- /examples/tasklist-ds/src/main/java/org/apache/aries/jpa/example/tasklist/ds/impl/TasklistAdder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.example.tasklist.ds.impl; 20 | 21 | import org.apache.aries.jpa.example.tasklist.model.Task; 22 | import org.apache.aries.jpa.example.tasklist.model.TaskService; 23 | import org.osgi.service.component.annotations.Activate; 24 | import org.osgi.service.component.annotations.Component; 25 | import org.osgi.service.component.annotations.Reference; 26 | 27 | @Component(immediate = true) 28 | public class TasklistAdder { 29 | TaskService taskService; 30 | 31 | @Reference 32 | public void setTaskService(TaskService taskService) { 33 | this.taskService = taskService; 34 | } 35 | 36 | @Activate 37 | public void addDemoTask() { 38 | if (taskService.getTask(1) == null) { 39 | Task task = new Task(); 40 | task.setId(1); 41 | task.setTitle("Task1"); 42 | taskService.addTask(task); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /examples/tasklist-ds/src/test/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | 25 | org.hibernate.jpa.HibernatePersistenceProvider 26 | org.apache.aries.jpa.example.tasklist.model.Task 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/tasklist-model/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /examples/tasklist-model/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | Meta-Persistence: \ 19 | META-INF/persistence.xml 20 | 21 | -contract: JavaJPA -------------------------------------------------------------------------------- /examples/tasklist-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 4.0.0 11 | 12 | 13 | org.apache.aries.jpa.example 14 | org.apache.aries.jpa.example.parent 15 | 2.7.4-SNAPSHOT 16 | .. 17 | 18 | 19 | org.apache.aries.jpa.example.tasklist.model 20 | Apache Aries JPA example tasklist model 21 | bundle 22 | 23 | 24 | 25 | org.apache.aries.jpa.javax.persistence 26 | javax.persistence_2.1 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/tasklist-model/src/main/java/org/apache/aries/jpa/example/tasklist/model/Task.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.example.tasklist.model; 20 | 21 | import java.util.Date; 22 | 23 | import javax.persistence.Entity; 24 | import javax.persistence.Id; 25 | import javax.xml.bind.annotation.XmlRootElement; 26 | 27 | @Entity 28 | @XmlRootElement 29 | public class Task { 30 | @Id 31 | Integer id; 32 | String title; 33 | String description; 34 | Date dueDate; 35 | boolean finished; 36 | 37 | public Task() { 38 | // Allow JPA to create the instance 39 | } 40 | 41 | public Task(Integer id, String title, String description) { 42 | super(); 43 | this.id = id; 44 | this.title = title; 45 | this.description = description; 46 | } 47 | 48 | public Integer getId() { 49 | return id; 50 | } 51 | 52 | public void setId(Integer id) { 53 | this.id = new Integer(id); 54 | } 55 | 56 | public String getTitle() { 57 | return title; 58 | } 59 | 60 | public void setTitle(String title) { 61 | this.title = title; 62 | } 63 | 64 | public String getDescription() { 65 | return description; 66 | } 67 | 68 | public void setDescription(String description) { 69 | this.description = description; 70 | } 71 | 72 | public Date getDueDate() { 73 | return dueDate; 74 | } 75 | 76 | public void setDueDate(Date dueDate) { 77 | this.dueDate = dueDate; 78 | } 79 | 80 | public boolean isFinished() { 81 | return finished; 82 | } 83 | 84 | public void setFinished(boolean finished) { 85 | this.finished = finished; 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /examples/tasklist-model/src/main/java/org/apache/aries/jpa/example/tasklist/model/TaskService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.example.tasklist.model; 20 | 21 | import java.util.Collection; 22 | 23 | public interface TaskService { 24 | Task getTask(Integer id); 25 | void addTask(Task task); 26 | void updateTask(Task task); 27 | void deleteTask(Integer id); 28 | Collection getTasks(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/tasklist-model/src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | 25 | org.hibernate.jpa.HibernatePersistenceProvider 26 | 27 | 28 | 29 | osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist) 30 | 31 | 32 | osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist) 33 | org.apache.aries.jpa.example.tasklist.model.Task 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/CarDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint; 20 | 21 | import java.util.List; 22 | 23 | import org.apache.aries.jpa.container.itest.entities.Car; 24 | 25 | public interface CarDao { 26 | 27 | void createNew(Car car); 28 | 29 | List getAllCars(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/NewTxTestService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint; 20 | 21 | import javax.transaction.Transaction; 22 | 23 | public interface NewTxTestService { 24 | 25 | void testNewTransaction(Transaction previousTransaction) throws Exception; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/TestService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint; 20 | 21 | public interface TestService { 22 | 23 | void performTest() throws Exception; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/dao/CarDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint.dao; 20 | 21 | import java.util.List; 22 | import javax.persistence.EntityManager; 23 | import javax.persistence.PersistenceContext; 24 | import javax.persistence.TypedQuery; 25 | 26 | import org.apache.aries.jpa.container.itest.bundle.blueprint.CarDao; 27 | import org.apache.aries.jpa.container.itest.entities.Car; 28 | 29 | public class CarDaoImpl implements CarDao { 30 | 31 | @PersistenceContext(unitName = "xa-test-unit") 32 | protected EntityManager em; 33 | 34 | @Override 35 | public void createNew(Car car) { 36 | em.persist(car); 37 | } 38 | 39 | @Override 40 | public List getAllCars() { 41 | TypedQuery query = em.createQuery("select c from Car c", Car.class); 42 | return query.getResultList(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/NewTxTestServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint.impl; 20 | 21 | import java.util.List; 22 | import javax.transaction.Transaction; 23 | import javax.transaction.TransactionManager; 24 | import javax.transaction.Transactional; 25 | import javax.transaction.Transactional.TxType; 26 | 27 | import org.apache.aries.jpa.container.itest.bundle.blueprint.CarDao; 28 | import org.apache.aries.jpa.container.itest.bundle.blueprint.NewTxTestService; 29 | import org.apache.aries.jpa.container.itest.entities.Car; 30 | 31 | public class NewTxTestServiceImpl implements NewTxTestService { 32 | 33 | private CarDao carDao; 34 | 35 | private TransactionManager transactionManager; 36 | 37 | public void setCarDao(CarDao carDao) { 38 | this.carDao = carDao; 39 | } 40 | 41 | public void setTransactionManager(TransactionManager transactionManager) { 42 | this.transactionManager = transactionManager; 43 | } 44 | 45 | @Override 46 | @Transactional(TxType.REQUIRES_NEW) 47 | public void testNewTransaction(Transaction previousTransaction) throws Exception { 48 | if (previousTransaction == transactionManager.getTransaction()) { 49 | throw new RuntimeException("No new transaction created for TxType.REQUIRES_NEW"); 50 | } 51 | 52 | List cars = carDao.getAllCars(); 53 | if (cars.size() != 0) { 54 | throw new RuntimeException("EntityManager query executed in suspended transaction!"); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle-dao/src/main/resources/OSGI-INF/blueprint/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /target/ 3 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/AbstractCarServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.container.itest.bundle.blueprint.impl; 17 | 18 | import javax.persistence.EntityManager; 19 | import javax.persistence.PersistenceContext; 20 | 21 | import org.apache.aries.jpa.container.itest.entities.CarService; 22 | 23 | public abstract class AbstractCarServiceImpl implements CarService { 24 | @PersistenceContext(unitName = "xa-test-unit") 25 | protected EntityManager em; 26 | } 27 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarServiceEmJtaAnn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | 23 | import javax.persistence.EntityManager; 24 | import javax.persistence.PersistenceContext; 25 | import javax.transaction.Transactional; 26 | 27 | import org.apache.aries.jpa.container.itest.entities.Car; 28 | import org.apache.aries.jpa.container.itest.entities.CarService; 29 | 30 | public class CarServiceEmJtaAnn implements CarService { 31 | @PersistenceContext(unitName = "xa-test-unit") 32 | protected EntityManager em; 33 | 34 | @Transactional(Transactional.TxType.SUPPORTS) 35 | @Override 36 | public Car getCar(String id) { 37 | return em.find(Car.class, id); 38 | } 39 | 40 | @Transactional 41 | @Override 42 | public void addCar(Car car) { 43 | em.persist(car); 44 | } 45 | 46 | @Transactional(Transactional.TxType.SUPPORTS) 47 | @Override 48 | public Collection getCars() { 49 | return em.createQuery("select c from Car c", Car.class).getResultList(); 50 | } 51 | 52 | @Transactional 53 | @Override 54 | public void updateCar(Car car) { 55 | em.persist(car); 56 | } 57 | 58 | @Transactional 59 | @Override 60 | public void deleteCar(String id) { 61 | em.remove(em.find(Car.class, id)); 62 | } 63 | 64 | public void setEm(EntityManager em) { 65 | this.em = em; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | 23 | import javax.persistence.EntityManager; 24 | 25 | import org.apache.aries.jpa.container.itest.entities.Car; 26 | 27 | public class CarServiceImpl extends AbstractCarServiceImpl { 28 | 29 | @Override 30 | public Car getCar(String id) { 31 | return em.find(Car.class, id); 32 | } 33 | 34 | @Override 35 | public void addCar(Car car) { 36 | em.persist(car); 37 | } 38 | 39 | @Override 40 | public Collection getCars() { 41 | return em.createQuery("select c from Car c", Car.class).getResultList(); 42 | } 43 | 44 | @Override 45 | public void updateCar(Car car) { 46 | em.merge(car); 47 | } 48 | 49 | @Override 50 | public void deleteCar(String id) { 51 | em.remove(em.find(Car.class, id)); 52 | } 53 | 54 | public void setEm(EntityManager em) { 55 | this.em = em; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarServiceWithMethodImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | 23 | import javax.persistence.EntityManager; 24 | import javax.persistence.PersistenceContext; 25 | 26 | import org.apache.aries.jpa.container.itest.entities.Car; 27 | import org.apache.aries.jpa.container.itest.entities.CarService; 28 | 29 | public class CarServiceWithMethodImpl implements CarService { 30 | 31 | EntityManager em; 32 | 33 | @Override 34 | public Car getCar(String id) { 35 | return em.find(Car.class, id); 36 | } 37 | 38 | @Override 39 | public void addCar(Car car) { 40 | em.persist(car); 41 | em.flush(); 42 | } 43 | 44 | @Override 45 | public Collection getCars() { 46 | return em.createQuery("select c from Car c", Car.class).getResultList(); 47 | } 48 | 49 | @Override 50 | public void updateCar(Car car) { 51 | em.persist(car); 52 | } 53 | 54 | @Override 55 | public void deleteCar(String id) { 56 | em.remove(getCar(id)); 57 | } 58 | 59 | @PersistenceContext(unitName = "xa-test-unit") 60 | public void setEm(EntityManager em) { 61 | this.em = em; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /itests/jpa-container-blueprint-testbundle/src/main/java/org/apache/aries/jpa/container/itest/bundle/blueprint/impl/CarServiceWithSupplierImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.bundle.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | 23 | import javax.persistence.PersistenceContext; 24 | 25 | import org.apache.aries.jpa.container.itest.entities.Car; 26 | import org.apache.aries.jpa.container.itest.entities.CarService; 27 | import org.apache.aries.jpa.supplier.EmSupplier; 28 | 29 | public class CarServiceWithSupplierImpl implements CarService { 30 | 31 | Collection colours; 32 | 33 | @PersistenceContext(unitName = "xa-test-unit") 34 | EmSupplier em; 35 | 36 | @Override 37 | public Car getCar(String id) { 38 | return em.get().find(Car.class, id); 39 | } 40 | 41 | @Override 42 | public void addCar(Car car) { 43 | em.get().persist(car); 44 | em.get().flush(); 45 | } 46 | 47 | @Override 48 | public Collection getCars() { 49 | return em.get().createQuery("select c from Car c", Car.class).getResultList(); 50 | } 51 | 52 | @Override 53 | public void updateCar(Car car) { 54 | em.get().persist(car); 55 | } 56 | 57 | @Override 58 | public void deleteCar(String id) { 59 | em.get().remove(getCar(id)); 60 | } 61 | 62 | public void setEm(EmSupplier em) { 63 | this.em = em; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /itests/jpa-container-itest-karaf/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /itests/jpa-container-itest-karaf/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /itests/jpa-container-itest-karaf/src/test/resources/org.ops4j.pax.logging.cfg: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | log4j2.appender.console.type = Console 19 | log4j2.appender.console.name = Console 20 | log4j2.appender.console.layout.type = PatternLayout 21 | log4j2.appender.console.layout.pattern = %d{DEFAULT} %-5.5p {%t} [%C.%M()] (%F:%L) : %m%n 22 | 23 | log4j2.appender.rolling.type = RollingRandomAccessFile 24 | log4j2.appender.rolling.name = RollingFile 25 | log4j2.appender.rolling.fileName = ${karaf.data}/log/karaf.log 26 | log4j2.appender.rolling.filePattern = ${karaf.data}/log/karaf-%i.log.gz 27 | log4j2.appender.rolling.append = true 28 | log4j2.appender.rolling.layout.type = PatternLayout 29 | log4j2.appender.rolling.layout.pattern = %d{DEFAULT} %-5.5p {%t} [%C.%M()] (%F:%L) : %m%n 30 | log4j2.appender.rolling.policies.type = Policies 31 | log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy 32 | log4j2.appender.rolling.policies.size.size = 16MB 33 | log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy 34 | log4j2.appender.rolling.strategy.max = 20 35 | 36 | log4j2.rootLogger.level = INFO 37 | log4j2.rootLogger.appenderRef.RollingFile.ref = RollingFile 38 | log4j2.rootLogger.appenderRef.Console.ref = Console 39 | log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter 40 | log4j2.rootLogger.appenderRef.Console.filter.threshold.level = ${karaf.log.console:-OFF} 41 | 42 | log4j2.logger.aries-tx.name = org.apache.aries.transaction 43 | log4j2.logger.aries-tx.level = DEBUG 44 | log4j2.logger.aries-jpa.name = org.apache.aries.jpa 45 | log4j2.logger.aries-jpa.level = DEBUG 46 | log4j2.logger.h2.name = h2database 47 | log4j2.logger.h2.level = DEBUG 48 | -------------------------------------------------------------------------------- /itests/jpa-container-itest-karaf/src/test/resources/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | Persistence unit for testing an incomplete persistence unit 26 | 27 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/blueprint/aries/itest/BlueprintDaoTest.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.blueprint.aries.itest; 17 | 18 | import org.apache.aries.jpa.container.itest.bundle.blueprint.TestService; 19 | import org.apache.aries.jpa.itest.AbstractJPAItest; 20 | import org.junit.Test; 21 | import org.ops4j.pax.exam.Configuration; 22 | import org.ops4j.pax.exam.Option; 23 | 24 | import static org.ops4j.pax.exam.CoreOptions.mavenBundle; 25 | 26 | public class BlueprintDaoTest extends AbstractJPAItest { 27 | 28 | @Test 29 | public void testNestedTransactionsWithIsolatedEntityManagers() throws Exception { 30 | TestService testService = getService(TestService.class, null); 31 | testService.performTest(); 32 | } 33 | 34 | @Configuration 35 | public Option[] configuration() { 36 | return new Option[] { 37 | baseOptions(), // 38 | jta12Bundles(), // 39 | ariesJpa20(), // 40 | hibernate(), // 41 | derbyDSF(), // 42 | testBundle(), // 43 | testBundleBlueprintDao(), 44 | mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.blueprint", "2.3.0"), 45 | // debug() 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerEclipseLinkTest.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.container.itest; 17 | 18 | import static org.junit.Assert.assertTrue; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.apache.aries.jpa.container.itest.entities.Car; 23 | import org.eclipse.persistence.internal.weaving.PersistenceWeaved; 24 | import org.junit.Test; 25 | import org.ops4j.pax.exam.Configuration; 26 | import org.ops4j.pax.exam.Option; 27 | import org.osgi.framework.Bundle; 28 | 29 | public class JPAContainerEclipseLinkTest extends JPAContainerTest { 30 | 31 | @Configuration 32 | public Option[] eclipseLinkConfig() { 33 | return new Option[] { 34 | baseOptions(), // 35 | ariesJpa21(), // 36 | jta12Bundles(), // 37 | eclipseLink(), // 38 | derbyDSF(), // 39 | testBundle() 40 | }; 41 | } 42 | 43 | @Test 44 | public void testClassIsWoven() throws Exception { 45 | assertTrue("Not PersistenceCapable", 46 | Arrays.asList(Car.class.getInterfaces()).contains(PersistenceWeaved.class)); 47 | } 48 | 49 | @Override 50 | protected String getProviderClassName() { 51 | return "org.eclipse.persistence.jpa.PersistenceProvider"; 52 | } 53 | 54 | @Override 55 | protected Bundle getProviderBundle() { 56 | return getBundleByName("org.apache.aries.jpa.eclipselink.adapter"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerHibernate5_2Test.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.container.itest; 17 | 18 | import org.hibernate.osgi.HibernateBundleActivator; 19 | import org.ops4j.pax.exam.Configuration; 20 | import org.ops4j.pax.exam.Option; 21 | import org.osgi.framework.Bundle; 22 | import org.osgi.framework.FrameworkUtil; 23 | 24 | public class JPAContainerHibernate5_2Test extends JPAContainerTest { 25 | 26 | @Configuration 27 | public Option[] configuration() { 28 | return new Option[] { 29 | baseOptions(), // 30 | ariesJpa21(), // 31 | derbyDSF(), // 32 | jta12Bundles(), // 33 | hibernate5_2(), // 34 | testBundle(), // 35 | }; 36 | } 37 | 38 | @Override 39 | protected String getProviderClassName() { 40 | return "org.hibernate.jpa.HibernatePersistenceProvider"; 41 | } 42 | 43 | @Override 44 | protected Bundle getProviderBundle() { 45 | return FrameworkUtil.getBundle(HibernateBundleActivator.class); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerHibernateTest.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.container.itest; 17 | 18 | import org.hibernate.osgi.HibernateBundleActivator; 19 | import org.ops4j.pax.exam.Configuration; 20 | import org.ops4j.pax.exam.Option; 21 | import org.osgi.framework.Bundle; 22 | import org.osgi.framework.FrameworkUtil; 23 | 24 | public class JPAContainerHibernateTest extends JPAContainerTest { 25 | 26 | @Configuration 27 | public Option[] configuration() { 28 | return new Option[] { 29 | baseOptions(), // 30 | ariesJpa20(), // 31 | derbyDSF(), // 32 | jta12Bundles(), // 33 | hibernate(), // 34 | testBundle(), // 35 | }; 36 | } 37 | 38 | @Override 39 | protected String getProviderClassName() { 40 | return "org.hibernate.ejb.HibernatePersistence"; 41 | } 42 | 43 | @Override 44 | protected Bundle getProviderBundle() { 45 | return FrameworkUtil.getBundle(HibernateBundleActivator.class); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerOpenJPATest.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.container.itest; 17 | 18 | import static org.junit.Assert.assertTrue; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.apache.aries.jpa.container.itest.entities.Car; 23 | import org.apache.openjpa.enhance.PersistenceCapable; 24 | import org.junit.Test; 25 | import org.ops4j.pax.exam.Configuration; 26 | import org.ops4j.pax.exam.Option; 27 | import org.osgi.framework.Bundle; 28 | import org.osgi.framework.FrameworkUtil; 29 | 30 | public class JPAContainerOpenJPATest extends JPAContainerTest { 31 | 32 | @Test 33 | public void testClassIsWoven() throws Exception { 34 | assertTrue("Not PersistenceCapable", 35 | Arrays.asList(Car.class.getInterfaces()).contains(PersistenceCapable.class)); 36 | } 37 | 38 | @Configuration 39 | public Option[] configuration() { 40 | return new Option[] { 41 | baseOptions(), // 42 | ariesJpa20(), // 43 | jta11Bundles(), // Openjpa currently does not work with jta 1.2. See https://issues.apache.org/jira/browse/OPENJPA-2607 44 | openJpa(), // 45 | derbyDSF(), // 46 | testBundle() 47 | }; 48 | 49 | } 50 | 51 | @Override 52 | protected String getProviderClassName() { 53 | return "org.apache.openjpa.persistence.PersistenceProviderImpl"; 54 | } 55 | 56 | @Override 57 | protected Bundle getProviderBundle() { 58 | return FrameworkUtil.getBundle(PersistenceCapable.class); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/resources/config/org.ops4j.datasource-testds.cfg: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | osgi.jdbc.driver.class=org.apache.derby.jdbc.EmbeddedDriver 19 | url=jdbc:derby:memory:TEST1;create=true 20 | dataSourceName=testds 21 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/resources/config/org.ops4j.datasource-testdsxa.cfg: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | 19 | osgi.jdbc.driver.class=org.apache.derby.jdbc.EmbeddedDriver 20 | pool=dbcp2 21 | xa=true 22 | url=jdbc:derby:memory:TESTXA;create=true 23 | dataSourceName=testdsxa 24 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/resources/config/org.ops4j.pax.logging.cfg: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | 19 | log4j.rootLogger=INFO, stdout 20 | #log4j.logger.org.apache.aries.transaction=DEBUG 21 | #log4j.logger.org.apache.aries.transaction.parsing=DEBUG 22 | #log4j.logger.org.apache.aries.jpa.blueprint.impl=DEBUG 23 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 24 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 25 | log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %c | %m%n 26 | -------------------------------------------------------------------------------- /itests/jpa-container-itest/src/test/resources/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | Persistence unit for testing an incomplete persistence unit 26 | 27 | 28 | Second Persistence unit for testing an incomplete persistence unit 29 | 30 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA 19 | Meta-Persistence: META-INF/persistence.xml 20 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/eclipselink/entities/Car2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.eclipselink.entities; 20 | 21 | import javax.persistence.Entity; 22 | import javax.persistence.Id; 23 | 24 | @Entity 25 | public class Car2 { 26 | @Id 27 | private String numberPlate; 28 | 29 | private String colour; 30 | 31 | private int engineSize; 32 | 33 | private int numberOfSeats; 34 | 35 | public String getNumberPlate() { 36 | return numberPlate; 37 | } 38 | 39 | public void setNumberPlate(String numberPlate) { 40 | this.numberPlate = numberPlate; 41 | } 42 | 43 | public String getColour() { 44 | return colour; 45 | } 46 | 47 | public void setColour(String colour) { 48 | this.colour = colour; 49 | } 50 | 51 | public int getEngineSize() { 52 | return engineSize; 53 | } 54 | 55 | public void setEngineSize(int engineSize) { 56 | this.engineSize = engineSize; 57 | } 58 | 59 | public int getNumberOfSeats() { 60 | return numberOfSeats; 61 | } 62 | 63 | public void setNumberOfSeats(int numberOfSeats) { 64 | this.numberOfSeats = numberOfSeats; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/src/main/java/org/apache/aries/jpa/container/itest/eclipselink/entities/packageinfo: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | version 1.0.0 20 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 17 | 19 | 20 | 21 | 23 | 24 | 27 | 30 | 33 | 35 | 37 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/create.sql: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | CREATE SCHEMA test_script 21 | CREATE TABLE CAR (NUMBERPLATE VARCHAR(50) PRIMARY KEY, COLOUR VARCHAR(50), ENGINESIZE INT, NUMBEROFSEATS INT) -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/data.sql: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | INSERT INTO CAR (NUMBERPLATE, COLOUR, ENGINESIZE, NUMBEROFSEATS) VALUES ('AB11CDE', 'Blue', 1300, 5) -------------------------------------------------------------------------------- /itests/jpa-container-testbundle-eclipselink/src/main/resources/META-INF/sql/drop.sql: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | Import-Package: \ 19 | org.hibernate.proxy;resolution:=optional, \ 20 | javassist.util.proxy;resolution:=optional, \ 21 | * 22 | DynamicImport-Package: \ 23 | org.hibernate.proxy, \ 24 | javassist.util.proxy 25 | Meta-Persistence: \ 26 | META-INF/persistence.xml 27 | 28 | -contract: JavaJPA -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 4.0.0 23 | 24 | 25 | org.apache.aries.jpa.itest 26 | org.apache.aries.jpa.itest.parent 27 | 2.7.4-SNAPSHOT 28 | .. 29 | 30 | 31 | org.apache.aries.jpa 32 | org.apache.aries.jpa.container.itest.bundle 33 | bundle 34 | Apache Aries JPA test bundle container 35 | 36 | 37 | 38 | org.apache.aries.jpa.javax.persistence 39 | javax.persistence_2.0 40 | ${project.version} 41 | provided 42 | 43 | 44 | 45 | For simple tests with DataSource, DataSourceFactory 46 | 47 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/Car.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.entities; 20 | 21 | import javax.persistence.Entity; 22 | import javax.persistence.Id; 23 | 24 | @Entity 25 | public class Car { 26 | @Id 27 | private String numberPlate; 28 | 29 | private String colour; 30 | 31 | private int engineSize; 32 | 33 | private int numberOfSeats; 34 | 35 | public String getNumberPlate() { 36 | return numberPlate; 37 | } 38 | 39 | public void setNumberPlate(String numberPlate) { 40 | this.numberPlate = numberPlate; 41 | } 42 | 43 | public String getColour() { 44 | return colour; 45 | } 46 | 47 | public void setColour(String colour) { 48 | this.colour = colour; 49 | } 50 | 51 | public int getEngineSize() { 52 | return engineSize; 53 | } 54 | 55 | public void setEngineSize(int engineSize) { 56 | this.engineSize = engineSize; 57 | } 58 | 59 | public int getNumberOfSeats() { 60 | return numberOfSeats; 61 | } 62 | 63 | public void setNumberOfSeats(int numberOfSeats) { 64 | this.numberOfSeats = numberOfSeats; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/CarService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.entities; 20 | 21 | import java.util.Collection; 22 | 23 | public interface CarService { 24 | Car getCar(String id); 25 | 26 | void addCar(Car car); 27 | 28 | Collection getCars(); 29 | 30 | void updateCar(Car car); 31 | 32 | void deleteCar(String id); 33 | } 34 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/mapped/Truck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.itest.entities.mapped; 20 | 21 | public class Truck { 22 | 23 | private String numberPlate; 24 | 25 | private String colour; 26 | 27 | private int engineSize; 28 | 29 | private double maxLoad; 30 | 31 | public String getNumberPlate() { 32 | return numberPlate; 33 | } 34 | 35 | public void setNumberPlate(String numberPlate) { 36 | this.numberPlate = numberPlate; 37 | } 38 | 39 | public String getColour() { 40 | return colour; 41 | } 42 | 43 | public void setColour(String colour) { 44 | this.colour = colour; 45 | } 46 | 47 | public int getEngineSize() { 48 | return engineSize; 49 | } 50 | 51 | public void setEngineSize(int engineSize) { 52 | this.engineSize = engineSize; 53 | } 54 | 55 | public double getMaxLoad() { 56 | return maxLoad; 57 | } 58 | 59 | public void setMaxLoad(double maxLoad) { 60 | this.maxLoad = maxLoad; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/mapped/packageinfo: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | version 1.0.0 20 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/src/main/java/org/apache/aries/jpa/container/itest/entities/packageinfo: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | version 1.0.0 20 | -------------------------------------------------------------------------------- /itests/jpa-container-testbundle/src/main/resources/META-INF/custom-mapping.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 24 | 25 | org.apache.aries.jpa.container.itest.entities.mapped 26 | 27 | 28 | SELECT DISTINCT record FROM Car record ORDER BY record.engineSize 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /itests/jpa-tck-itest/README.txt: -------------------------------------------------------------------------------- 1 | # How to run the tck tests 2 | 3 | # First you need to retrieve the tck and deploy the test jpa test jar (these steps only need to be done once) 4 | # 1. Request access to the OSGi tck. http://felix.apache.org/documentation/development/using-the-osgi-compliance-tests.html 5 | # 2. Get and extract https://svn.apache.org/repos/tck/osgi-cts/osgi.enterprise.tests/5.0.0/osgi.ct.enterprise.jar 6 | # 3. deploy the test jar to maven 7 | mvn install:install-file -Dfile=jar/org.osgi.test.cases.jpa-5.0.0.jar -DgroupId=org.apache.aries.tck -DartifactId=org.osgi.test.cases.jpa -Dversion=5.0.0 -Dpackaging=jar 8 | 9 | # 3. execute the commands below 10 | mvn clean install 11 | ./runtests 12 | 13 | -------------------------------------------------------------------------------- /itests/jpa-tck-itest/org.osgi.test.cases.jpa.bnd: -------------------------------------------------------------------------------- 1 | # Copyright (c) OSGi Alliance (2012). All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # bnd pack for project org.osgi.test.cases.jpa 16 | # Thu Nov 01 12:39:45 EDT 2012 17 | 18 | -standalone: 19 | 20 | -runpath = \ 21 | lib/org.eclipse.osgi-3.8.0.v20120529-1548.jar;version=file, \ 22 | lib/org.apache.servicemix.bundles.junit-4.11_1.jar;version=file;export="junit.framework;version=3.8,junit.framework;version=4.11" 23 | 24 | #-runtrace = true 25 | 26 | -target = \ 27 | lib/org.osgi.test.cases.jpa-5.0.0.jar;version=file, 28 | 29 | -runbundles = \ 30 | lib/pax-logging-api-1.7.3.jar;version=file, \ 31 | lib/pax-logging-service-1.7.3.jar;version=file, \ 32 | lib/derbyclient-10.11.1.1.jar;version=file, \ 33 | lib/org.osgi.service.jdbc-1.0.0.jar;version=file, \ 34 | lib/pax-jdbc-derbyclient-0.7.0.jar;version=file, \ 35 | lib/javax.persistence-2.1.0.jar;version=file, \ 36 | lib/geronimo-jta_1.1_spec-1.1.1.jar;version=file, \ 37 | lib/geronimo-servlet_2.5_spec-1.2.jar;version=file, \ 38 | lib/org.apache.felix.eventadmin-1.4.2.jar;version=file, \ 39 | lib/org.apache.felix.configadmin-1.8.0.jar;version=file, \ 40 | lib/org.eclipse.persistence.core-2.6.0.jar;version=file, \ 41 | lib/org.eclipse.persistence.jpa-2.6.0.jar;version=file, \ 42 | lib/org.eclipse.persistence.antlr-2.6.0.jar;version=file, \ 43 | lib/org.eclipse.persistence.jpa.jpql-2.6.0.jar;version=file, \ 44 | lib/org.eclipse.persistence.asm-2.6.0.jar;version=file, \ 45 | lib/org.apache.aries.jpa.eclipselink.adapter-2.6.0-SNAPSHOT.jar;version=file, \ 46 | lib/org.apache.aries.jpa.container-2.6.0-SNAPSHOT.jar;version=file, \ 47 | lib/org.osgi.test.cases.jpa-5.0.0.jar;version=file 48 | 49 | -runproperties = \ 50 | report="true", \ 51 | osgi.resolverMode="strict" 52 | 53 | -runsystempackages=javax.xml.stream; version=1.0, javax.xml.stream.events; version=1.0, javax.xml.stream.util; version=1.0 54 | 55 | -------------------------------------------------------------------------------- /itests/jpa-tck-itest/runtests: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | cp org.osgi.test.cases.jpa.bnd target 19 | cd target 20 | java -jar lib/biz.aQute.bnd-3.3.0.jar runtests --title osgi.ct 21 | cd .. 22 | -------------------------------------------------------------------------------- /itests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 4.0.0 23 | 24 | org.apache.aries.jpa.itest 25 | org.apache.aries.jpa.itest.parent 26 | Apache Aries JPA itests parent 27 | pom 28 | 29 | 30 | org.apache.aries.jpa 31 | org.apache.aries.jpa.parent 32 | 2.7.4-SNAPSHOT 33 | ../jpa-parent 34 | 35 | 36 | 37 | 1.7.3 38 | 4.10.0 39 | 3.11.3 40 | 2.6.7 41 | 4.2.15.Final 42 | 1.8.2_2 43 | 2.7.7_5 44 | 1.6.1_5 45 | 1.14.1_1 46 | 2.6.0 47 | 2.3.0 48 | 1.1.0 49 | 50 | 51 | 52 | jpa-container-blueprint-testbundle 53 | jpa-container-blueprint-testbundle-dao 54 | jpa-container-itest 55 | jpa-container-itest-karaf 56 | jpa-container-testbundle 57 | jpa-container-testbundle-eclipselink 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /javax-persistence/2_0/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /javax-persistence/2_0/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /javax-persistence/2_0/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Double exports copied from Geronimo to ensure maximal 19 | # compatibility with the mess of older implementations out there. 20 | # The JavaJPA contract is recommended to avoid issues here. 21 | 22 | Export-Package: \ 23 | javax.persistence;jpa="2.0";version="1.1",\ 24 | javax.persistence;jpa="2.0";version="2.0",\ 25 | javax.persistence.criteria;jpa="2.0";version="1.1",\ 26 | javax.persistence.criteria;jpa="2.0";version="2.0",\ 27 | javax.persistence.metamodel;jpa="2.0";version="1.1",\ 28 | javax.persistence.metamodel;jpa="2.0";version="2.0",\ 29 | javax.persistence.spi;jpa="2.0";version="1.1",\ 30 | javax.persistence.spi;jpa="2.0";version="2.0" 31 | 32 | Provide-Capability:\ 33 | osgi.contract;osgi.contract="JavaJPA";version:List="2,1";\ 34 | uses:="javax.persistence,javax.persistence.criteria,javax.persistence.metamodel,javax.persistence.spi" 35 | 36 | # Make the API substitutable with unversioned imports and a contract requirement 37 | 38 | Import-Package: \ 39 | !org.apache.geronimo.*,\ 40 | javax.persistence;version=0.0.0,\ 41 | javax.persistence.criteria;version=0.0.0,\ 42 | javax.persistence.metamodel;version=0.0.0,\ 43 | javax.persistence.spi;version=0.0.0,\ 44 | * 45 | 46 | Require-Capability:\ 47 | osgi.contract;filter:="(&(osgi.contract=JavaJPA)(version=2)(!(version>=2.1)))" 48 | 49 | Private-Package: \ 50 | org.apache.aries.jpa.javax.persistence,\ 51 | org.apache.geronimo.osgi.locator 52 | 53 | Bundle-Activator: org.apache.aries.jpa.javax.persistence.AriesJPASpecActivator 54 | 55 | Bundle-SymbolicName: org.apache.aries.jpa.javax.persistence_2.0 56 | -------------------------------------------------------------------------------- /javax-persistence/2_0/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 4.0.0 23 | 24 | 25 | org.apache.aries.jpa.javax.persistence 26 | org.apache.aries.jpa.javax.persistence.parent 27 | 2.7.4-SNAPSHOT 28 | .. 29 | 30 | 31 | javax.persistence_2.0 32 | bundle 33 | Apache Aries JPA Specification 2.0 API 34 | 35 | 36 | 37 | org.osgi 38 | org.osgi.core 39 | provided 40 | 41 | 42 | org.osgi 43 | org.osgi.compendium 44 | provided 45 | 46 | 47 | org.apache.geronimo.specs 48 | geronimo-jpa_2.0_spec 49 | 1.1 50 | provided 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /javax-persistence/2_0/src/main/java/org/apache/aries/jpa/javax/persistence/AriesJPASpecActivator.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.apache.aries.jpa.javax.persistence; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | import java.util.List; 21 | 22 | import javax.persistence.spi.PersistenceProvider; 23 | import javax.persistence.spi.PersistenceProviderResolver; 24 | import javax.persistence.spi.PersistenceProviderResolverHolder; 25 | 26 | import org.osgi.framework.BundleActivator; 27 | import org.osgi.framework.BundleContext; 28 | import org.osgi.util.tracker.ServiceTracker; 29 | 30 | public class AriesJPASpecActivator implements BundleActivator, PersistenceProviderResolver { 31 | 32 | private ServiceTracker tracker; 33 | 34 | private EMFBuilderServiceResolver emfResolver; 35 | 36 | @Override 37 | public void start(BundleContext context) throws Exception { 38 | emfResolver = new EMFBuilderServiceResolver(context); 39 | 40 | tracker = new ServiceTracker(context, 41 | PersistenceProvider.class, null); 42 | tracker.open(); 43 | 44 | PersistenceProviderResolverHolder.setPersistenceProviderResolver(this); 45 | } 46 | 47 | @Override 48 | public void stop(BundleContext context) throws Exception { 49 | PersistenceProviderResolverHolder.setPersistenceProviderResolver(null); 50 | tracker.close(); 51 | emfResolver.close(); 52 | } 53 | 54 | @Override 55 | public List getPersistenceProviders() { 56 | Collection services = tracker.getTracked().values(); 57 | 58 | List providers = new ArrayList(services.size() + 1); 59 | 60 | providers.add(emfResolver); 61 | providers.addAll(services); 62 | 63 | return providers; 64 | } 65 | 66 | @Override 67 | public void clearCachedProviders() { 68 | // This is a no-op 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /javax-persistence/2_1/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /javax-persistence/2_1/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /javax-persistence/2_1/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Double exports copied from Geronimo to ensure maximal 19 | # compatibility with the mess of older implementations out there. 20 | # The JavaJPA contract is recommended to avoid issues here. 21 | 22 | Export-Package: \ 23 | javax.persistence;jpa="2.1";version="1.2",\ 24 | javax.persistence;jpa="2.1";version="2.1",\ 25 | javax.persistence.criteria;jpa="2.1";version="1.2",\ 26 | javax.persistence.criteria;jpa="2.1";version="2.1",\ 27 | javax.persistence.metamodel;jpa="2.1";version="1.2",\ 28 | javax.persistence.metamodel;jpa="2.1";version="2.1",\ 29 | javax.persistence.spi;jpa="2.1";version="1.2",\ 30 | javax.persistence.spi;jpa="2.1";version="2.1" 31 | 32 | Provide-Capability:\ 33 | osgi.contract;osgi.contract="JavaJPA";version:List="2.1,2,1";\ 34 | uses:="javax.persistence,javax.persistence.criteria,javax.persistence.metamodel,javax.persistence.spi" 35 | 36 | # Make the API substitutable with unversioned imports and a contract requirement 37 | 38 | Import-Package: \ 39 | !org.apache.geronimo.*,\ 40 | javax.persistence;version=0.0.0,\ 41 | javax.persistence.criteria;version=0.0.0,\ 42 | javax.persistence.metamodel;version=0.0.0,\ 43 | javax.persistence.spi;version=0.0.0,\ 44 | * 45 | 46 | Require-Capability:\ 47 | osgi.contract;filter:="(&(osgi.contract=JavaJPA)(version=2.1)(!(version>=2.2)))" 48 | 49 | Private-Package: \ 50 | org.apache.aries.jpa.javax.persistence,\ 51 | org.apache.geronimo.osgi.locator 52 | 53 | Bundle-Activator: org.apache.aries.jpa.javax.persistence.AriesJPASpecActivator 54 | 55 | Bundle-SymbolicName: org.apache.aries.jpa.javax.persistence_2.1 56 | -------------------------------------------------------------------------------- /javax-persistence/2_1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 4.0.0 23 | 24 | 25 | org.apache.aries.jpa.javax.persistence 26 | org.apache.aries.jpa.javax.persistence.parent 27 | 2.7.4-SNAPSHOT 28 | .. 29 | 30 | 31 | javax.persistence_2.1 32 | bundle 33 | Apache Aries JPA Specification 2.1 API 34 | 35 | 36 | 37 | org.osgi 38 | org.osgi.core 39 | provided 40 | 41 | 42 | org.osgi 43 | org.osgi.compendium 44 | provided 45 | 46 | 47 | org.apache.geronimo.specs 48 | geronimo-jpa_2.1_spec 49 | 1.0-alpha-1 50 | provided 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /javax-persistence/2_1/src/main/java/org/apache/aries/jpa/javax/persistence/AriesJPASpecActivator.java: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.apache.aries.jpa.javax.persistence; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collection; 21 | import java.util.List; 22 | 23 | import javax.persistence.spi.PersistenceProvider; 24 | import javax.persistence.spi.PersistenceProviderResolver; 25 | import javax.persistence.spi.PersistenceProviderResolverHolder; 26 | 27 | import org.osgi.framework.BundleActivator; 28 | import org.osgi.framework.BundleContext; 29 | import org.osgi.util.tracker.ServiceTracker; 30 | 31 | public class AriesJPASpecActivator implements BundleActivator, PersistenceProviderResolver { 32 | 33 | private ServiceTracker tracker; 34 | 35 | private EMFBuilderServiceResolver emfResolver; 36 | 37 | @Override 38 | public void start(BundleContext context) throws Exception { 39 | emfResolver = new EMFBuilderServiceResolver(context); 40 | 41 | tracker = new ServiceTracker(context, 42 | PersistenceProvider.class, null); 43 | tracker.open(); 44 | 45 | PersistenceProviderResolverHolder.setPersistenceProviderResolver(this); 46 | } 47 | 48 | @Override 49 | public void stop(BundleContext context) throws Exception { 50 | PersistenceProviderResolverHolder.setPersistenceProviderResolver(null); 51 | tracker.close(); 52 | emfResolver.close(); 53 | } 54 | 55 | @Override 56 | public List getPersistenceProviders() { 57 | Collection services = tracker.getTracked().values(); 58 | 59 | List providers = new ArrayList(services.size() + 1); 60 | 61 | providers.add(emfResolver); 62 | providers.addAll(services); 63 | 64 | return providers; 65 | } 66 | 67 | @Override 68 | public void clearCachedProviders() { 69 | // This is a no-op 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /javax-persistence/README.md: -------------------------------------------------------------------------------- 1 | # Aries JPA Specification Jars 2 | 3 | These projects contain the JPA API at various versions, providing proper OSGi packaging and contracts so that they can be used easily in OSGi. 4 | 5 | ##Using the JPA API with your OSGi bundles 6 | 7 | If you are using a bnd based plugin (e.g. the bnd-maven-plugin or the maven-bundle-plugin) then you should make sure to set the following: 8 | 9 | -contract: * 10 | 11 | or 12 | 13 | -contract: JavaJPA 14 | 15 | in your bnd configuration. This will ensure that your bundle is built depending on the JPA contract, and therefore that it will not need to be repackaged to use future, backward compatible versions of the JPA specification. -------------------------------------------------------------------------------- /javax-persistence/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 4.0.0 23 | 24 | org.apache.aries.jpa.javax.persistence 25 | org.apache.aries.jpa.javax.persistence.parent 26 | Apache Aries JPA Specification API 27 | pom 28 | 29 | 30 | org.apache.aries.jpa 31 | org.apache.aries.jpa.parent 32 | 2.7.4-SNAPSHOT 33 | ../jpa-parent 34 | 35 | 36 | 37 | true 38 | 39 | 40 | 41 | 2_0 42 | 2_1 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /jpa-api/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jpa-api/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /jpa-api/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA 19 | -------------------------------------------------------------------------------- /jpa-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 4.0.0 23 | 24 | 25 | org.apache.aries.jpa 26 | org.apache.aries.jpa.parent 27 | 2.7.4-SNAPSHOT 28 | ../jpa-parent 29 | 30 | 31 | org.apache.aries.jpa.api 32 | bundle 33 | Apache Aries JPA Container API 34 | 35 | 36 | 37 | org.osgi 38 | org.osgi.core 39 | provided 40 | 41 | 42 | org.apache.aries.jpa.javax.persistence 43 | javax.persistence_2.0 44 | ${project.version} 45 | provided 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/supplier/EmSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.supplier; 20 | 21 | import javax.persistence.EntityManager; 22 | 23 | /** 24 | * Provides a thread safe way to use an EntityManager. - The first call must be to preCall(). This will create 25 | * an EM for the current thread. - The EM can then be retrieved by calling get() and user normally - At the 26 | * end postCall() has to be called to close the EntityManager If this is used on nested methods then the EM is 27 | * only created / closed on the outermost calls to preCall() / postCall() 28 | */ 29 | public interface EmSupplier { 30 | 31 | /** 32 | * Is called before first access to get() in a method 33 | * @deprecated Use a Coordination instead 34 | */ 35 | @Deprecated 36 | void preCall(); 37 | 38 | EntityManager get(); 39 | 40 | /** 41 | * Is called after last access to get() in a method 42 | * @deprecated Use a Coordination instead 43 | */ 44 | @Deprecated 45 | void postCall(); 46 | } 47 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/supplier/packageinfo: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | version 1.0.0 20 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/template/EmConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.template; 20 | 21 | import javax.persistence.EntityManager; 22 | 23 | public interface EmConsumer { 24 | void accept(EntityManager em); 25 | } 26 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/template/EmFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.template; 20 | 21 | import javax.persistence.EntityManager; 22 | 23 | public interface EmFunction { 24 | R apply(EntityManager em); 25 | } 26 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/template/JpaTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.template; 20 | 21 | 22 | public interface JpaTemplate { 23 | R txExpr(TransactionType type, EmFunction code); 24 | void tx(TransactionType type, EmConsumer code); 25 | 26 | R txExpr(EmFunction code); 27 | void tx(EmConsumer code); 28 | } 29 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/template/TransactionType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.template; 20 | 21 | public enum TransactionType { 22 | Mandatory, Never, NotSupported, Required, RequiresNew, Supports // NOSONAR 23 | } 24 | -------------------------------------------------------------------------------- /jpa-api/src/main/java/org/apache/aries/jpa/template/packageinfo: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | version 1.0.0 20 | -------------------------------------------------------------------------------- /jpa-blueprint/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jpa-blueprint/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA 19 | Bundle-Activator: org.apache.aries.jpa.blueprint.impl.Activator 20 | -------------------------------------------------------------------------------- /jpa-blueprint/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | org.apache.aries.jpa 24 | org.apache.aries.jpa.parent 25 | 2.7.4-SNAPSHOT 26 | ../jpa-parent 27 | 28 | org.apache.aries.jpa.blueprint 29 | Apache Aries JPA blueprint 30 | Blueprint integration for injecting EntityManager, EntityManagerFactory and EmSupplier. 31 | bundle 32 | 33 | 34 | 35 | 36 | org.apache.aries.jpa.javax.persistence 37 | javax.persistence_2.0 38 | ${project.version} 39 | provided 40 | 41 | 42 | org.apache.geronimo.specs 43 | geronimo-jta_1.1_spec 44 | 45 | 46 | org.osgi 47 | org.osgi.core 48 | provided 49 | 50 | 51 | org.osgi 52 | org.osgi.compendium 53 | provided 54 | 55 | 56 | org.apache.aries.blueprint 57 | org.apache.aries.blueprint.core 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/Activator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.blueprint.impl; 20 | 21 | import java.util.Dictionary; 22 | import java.util.Hashtable; 23 | 24 | import org.apache.aries.blueprint.NamespaceHandler; 25 | import org.osgi.framework.BundleActivator; 26 | import org.osgi.framework.BundleContext; 27 | 28 | public class Activator implements BundleActivator { 29 | 30 | @Override 31 | public void start(BundleContext context) throws Exception { 32 | JpaNsHandler handler = new JpaNsHandler(); 33 | context.registerService(NamespaceHandler.class, handler, createProps(JpaNsHandler.NAMESPACE_JPAN_10)); 34 | context.registerService(NamespaceHandler.class, handler, createProps(JpaNsHandler.NAMESPACE_JPA_20)); 35 | } 36 | 37 | private static Dictionary createProps(String namespace) { 38 | Dictionary props = new Hashtable(); // NOSONAR 39 | props.put("osgi.service.blueprint.namespace", namespace); 40 | return props; 41 | } 42 | 43 | @Override 44 | public void stop(BundleContext context) throws Exception { 45 | // Unregistering happens automatically 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/ResourceLocalTransactionParticipant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.blueprint.impl; 20 | 21 | import javax.persistence.EntityManager; 22 | 23 | import org.osgi.service.coordinator.Coordination; 24 | import org.osgi.service.coordinator.Participant; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | final class ResourceLocalTransactionParticipant implements Participant { 29 | private static final Logger LOG = LoggerFactory.getLogger(ResourceLocalTransactionParticipant.class); 30 | private final EntityManager em; 31 | 32 | ResourceLocalTransactionParticipant(EntityManager em) { 33 | this.em = em; 34 | em.getTransaction().begin(); 35 | } 36 | 37 | @Override 38 | public void failed(Coordination coordination) throws Exception { 39 | em.getTransaction().setRollbackOnly(); 40 | } 41 | 42 | @Override 43 | public void ended(Coordination coordination) throws Exception { 44 | if (em.getTransaction().getRollbackOnly()) { 45 | try { 46 | em.getTransaction().rollback(); 47 | } catch (Exception e) { 48 | LOG.debug("Exception on transaction rollback", e); 49 | } 50 | } else { 51 | em.getTransaction().commit(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /jpa-blueprint/src/main/resources/jpa20.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /jpa-blueprint/src/main/resources/jpan10.xsd: -------------------------------------------------------------------------------- 1 | 2 | 20 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/BlueprintContainerStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | import org.osgi.service.blueprint.container.BlueprintContainer; 27 | import org.osgi.service.blueprint.reflect.ComponentMetadata; 28 | 29 | public class BlueprintContainerStub implements BlueprintContainer { 30 | 31 | private Map instances; 32 | 33 | public BlueprintContainerStub() { 34 | instances = new HashMap(); 35 | instances.put("coordinator", new CoordinatorStub()); 36 | instances.put("em", new EntityManagerStub()); 37 | } 38 | 39 | @Override 40 | public Set getComponentIds() { 41 | // TODO Auto-generated method stub 42 | return null; 43 | } 44 | 45 | @Override 46 | public Object getComponentInstance(String id) { 47 | if ("em".equals(id)) { 48 | try { 49 | Thread.sleep(3000); 50 | } catch (InterruptedException e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | return instances.get(id); 55 | } 56 | 57 | @Override 58 | public ComponentMetadata getComponentMetadata(String id) { 59 | // TODO Auto-generated method stub 60 | return null; 61 | } 62 | 63 | @Override 64 | public Collection getMetadata(Class type) { 65 | // TODO Auto-generated method stub 66 | return null; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/CoordinatorStub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.blueprint.impl; 20 | 21 | import java.util.Collection; 22 | 23 | import org.osgi.service.coordinator.Coordination; 24 | import org.osgi.service.coordinator.Coordinator; 25 | import org.osgi.service.coordinator.Participant; 26 | 27 | public class CoordinatorStub implements Coordinator { 28 | 29 | @Override 30 | public Coordination create(String name, long timeMillis) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public Coordination begin(String name, long timeMillis) { 36 | return null; 37 | } 38 | 39 | @Override 40 | public Coordination peek() { 41 | return null; 42 | } 43 | 44 | @Override 45 | public Coordination pop() { 46 | return null; 47 | } 48 | 49 | @Override 50 | public boolean fail(Throwable cause) { 51 | return false; 52 | } 53 | 54 | @Override 55 | public boolean addParticipant(Participant participant) { 56 | return false; 57 | } 58 | 59 | @Override 60 | public Collection getCoordinations() { 61 | return null; 62 | } 63 | 64 | @Override 65 | public Coordination getCoordination(long id) { 66 | return null; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.blueprint.impl; 20 | 21 | import javax.persistence.EntityManager; 22 | import javax.persistence.EntityManagerFactory; 23 | import javax.persistence.PersistenceContext; 24 | import javax.persistence.PersistenceUnit; 25 | 26 | public class TestClass { 27 | 28 | @PersistenceContext(unitName="test") 29 | EntityManager em; 30 | 31 | public void setEm(EntityManager em) { 32 | this.em = em; 33 | } 34 | 35 | EntityManagerFactory emf; 36 | 37 | @PersistenceUnit(unitName="test2") 38 | public void setEmf(EntityManagerFactory emf) { 39 | this.emf = emf; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /jpa-blueprint/src/test/java/org/apache/aries/jpa/blueprint/impl/TestInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.blueprint.impl; 20 | 21 | public interface TestInterface { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /jpa-cdi/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | Import-Package: \ 19 | javax.persistence*;version=2.1, \ 20 | * 21 | Provide-Capability: \ 22 | org.ops4j.pax.cdi.extension; extension=aries-jpa-cdi; \ 23 | version:Version=${version;====;${replace;${project.version};-;.}} 24 | Require-Capability: \ 25 | org.ops4j.pax.cdi.extension; filter:="(extension=pax-cdi-extension2)" 26 | osgi.extender; filter:="(osgi.extender=aries.jpa)" 27 | 28 | 29 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/EntityManagerProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi; 18 | 19 | import javax.persistence.EntityManager; 20 | import java.lang.reflect.Proxy; 21 | 22 | import org.apache.aries.jpa.template.JpaTemplate; 23 | import org.apache.aries.jpa.template.TransactionType; 24 | 25 | public class EntityManagerProducer { 26 | 27 | public static EntityManager create(JpaTemplate template) { 28 | return (EntityManager) Proxy.newProxyInstance(EntityManager.class.getClassLoader(), 29 | new Class[]{EntityManager.class}, 30 | (proxy, method, args) -> { 31 | try { 32 | return template.txExpr(TransactionType.Supports, em -> { 33 | try { 34 | return method.invoke(em, args); 35 | } catch (RuntimeException e) { 36 | throw e; 37 | } catch (Exception e) { 38 | throw new RuntimeException(e); 39 | } 40 | }); 41 | } catch (RuntimeException e) { 42 | if (e.getClass() == RuntimeException.class 43 | && e.getCause() != null 44 | && e.getCause().toString().equals(e.getMessage())) { 45 | throw e.getCause(); 46 | } 47 | throw e; 48 | } 49 | }); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/JpaExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi; 18 | 19 | import javax.enterprise.context.ApplicationScoped; 20 | import javax.enterprise.event.Observes; 21 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 22 | import javax.enterprise.inject.spi.AnnotatedField; 23 | import javax.enterprise.inject.spi.Bean; 24 | import javax.enterprise.inject.spi.BeanManager; 25 | import javax.enterprise.inject.spi.Extension; 26 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 27 | import javax.persistence.PersistenceContext; 28 | import javax.persistence.PersistenceUnit; 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | @ApplicationScoped 33 | public class JpaExtension implements Extension { 34 | 35 | List> beans = new ArrayList>(); 36 | 37 | public void processAnnotatedType(@Observes ProcessAnnotatedType event, BeanManager manager) { 38 | boolean hasPersistenceField = false; 39 | for (AnnotatedField field : event.getAnnotatedType().getFields()) { 40 | if (field.isAnnotationPresent(PersistenceContext.class) 41 | || field.isAnnotationPresent(PersistenceUnit.class)) { 42 | hasPersistenceField = true; 43 | break; 44 | } 45 | } 46 | if (hasPersistenceField) { 47 | PersistenceAnnotatedType pat = new PersistenceAnnotatedType(manager, event.getAnnotatedType()); 48 | beans.addAll(pat.getProducers()); 49 | event.setAnnotatedType(pat); 50 | } 51 | } 52 | 53 | public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) { 54 | for (Bean bean : beans) { 55 | event.addBean(bean); 56 | } 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/TransactionSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi; 18 | 19 | import javax.enterprise.context.ApplicationScoped; 20 | import javax.inject.Inject; 21 | import javax.transaction.TransactionManager; 22 | import javax.transaction.TransactionSynchronizationRegistry; 23 | 24 | import org.ops4j.pax.cdi.api2.Global; 25 | import org.ops4j.pax.cdi.api2.Service; 26 | 27 | @ApplicationScoped 28 | public class TransactionSupport { 29 | 30 | @Inject @Global @Service 31 | private TransactionManager transactionManager; 32 | 33 | @Inject @Global @Service 34 | private TransactionSynchronizationRegistry transactionSynchronizationRegistry; 35 | 36 | public TransactionManager getTransactionManager() { 37 | return transactionManager; 38 | } 39 | 40 | public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { 41 | return transactionSynchronizationRegistry; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/FilterLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.enterprise.util.AnnotationLiteral; 20 | 21 | import org.ops4j.pax.cdi.api2.Filter; 22 | 23 | public final class FilterLiteral extends AnnotationLiteral implements Filter { 24 | 25 | private final String filter; 26 | 27 | public FilterLiteral(String filter) { 28 | this.filter = filter; 29 | } 30 | 31 | @Override 32 | public String value() { 33 | return filter; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/ForwardingAnnotatedField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.enterprise.inject.spi.AnnotatedField; 20 | import javax.enterprise.inject.spi.AnnotatedType; 21 | import java.lang.annotation.Annotation; 22 | import java.lang.reflect.Field; 23 | import java.lang.reflect.Type; 24 | import java.util.Set; 25 | 26 | public class ForwardingAnnotatedField implements AnnotatedField { 27 | 28 | private final AnnotatedField delegate; 29 | 30 | public ForwardingAnnotatedField(AnnotatedField delegate) { 31 | this.delegate = delegate; 32 | } 33 | 34 | @Override 35 | public Field getJavaMember() { 36 | return delegate.getJavaMember(); 37 | } 38 | 39 | @Override 40 | public boolean isStatic() { 41 | return delegate.isStatic(); 42 | } 43 | 44 | @Override 45 | public AnnotatedType getDeclaringType() { 46 | return delegate.getDeclaringType(); 47 | } 48 | 49 | @Override 50 | public Type getBaseType() { 51 | return delegate.getBaseType(); 52 | } 53 | 54 | @Override 55 | public Set getTypeClosure() { 56 | return delegate.getTypeClosure(); 57 | } 58 | 59 | @Override 60 | public T getAnnotation(Class annotationType) { 61 | return delegate.getAnnotation(annotationType); 62 | } 63 | 64 | @Override 65 | public Set getAnnotations() { 66 | return delegate.getAnnotations(); 67 | } 68 | 69 | @Override 70 | public boolean isAnnotationPresent(Class annotationType) { 71 | return delegate.isAnnotationPresent(annotationType); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/InjectLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.enterprise.util.AnnotationLiteral; 20 | import javax.inject.Inject; 21 | 22 | public final class InjectLiteral extends AnnotationLiteral implements Inject { 23 | 24 | public static InjectLiteral INJECT = new InjectLiteral(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/ServiceLiteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.enterprise.util.AnnotationLiteral; 20 | 21 | import org.ops4j.pax.cdi.api2.Service; 22 | 23 | public final class ServiceLiteral extends AnnotationLiteral implements Service { 24 | 25 | public static final Service SERVICE = new ServiceLiteral(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/SyntheticAnnotatedField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.enterprise.inject.spi.AnnotatedField; 20 | import java.lang.annotation.Annotation; 21 | import java.util.Collections; 22 | import java.util.HashMap; 23 | import java.util.HashSet; 24 | import java.util.Map; 25 | import java.util.Set; 26 | 27 | public class SyntheticAnnotatedField extends ForwardingAnnotatedField { 28 | 29 | private final Map, Annotation> annotations = new HashMap<>(); 30 | 31 | public SyntheticAnnotatedField(AnnotatedField delegate) { 32 | this(delegate, Collections.emptyList()); 33 | } 34 | 35 | public SyntheticAnnotatedField(AnnotatedField delegate, Iterable annotations) { 36 | super(delegate); 37 | for (Annotation annotation : annotations) { 38 | addAnnotation(annotation); 39 | } 40 | for (Annotation annotation : delegate.getAnnotations()) { 41 | addAnnotation(annotation); 42 | } 43 | } 44 | 45 | public void addAnnotation(Annotation annotation) { 46 | this.annotations.put(annotation.annotationType(), annotation); 47 | } 48 | 49 | @Override 50 | @SuppressWarnings("unchecked") 51 | public T getAnnotation(Class annotationType) { 52 | return (T) annotations.get(annotationType); 53 | } 54 | 55 | @Override 56 | public Set getAnnotations() { 57 | return Collections.unmodifiableSet(new HashSet<>(annotations.values())); 58 | } 59 | 60 | @Override 61 | public boolean isAnnotationPresent(Class annotationType) { 62 | return annotations.containsKey(annotationType); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/UniqueIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.inject.Qualifier; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.FIELD; 24 | import static java.lang.annotation.ElementType.METHOD; 25 | import static java.lang.annotation.ElementType.PARAMETER; 26 | import static java.lang.annotation.ElementType.TYPE; 27 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 | 29 | @Target({METHOD, FIELD, PARAMETER, TYPE}) 30 | @Retention(RUNTIME) 31 | @Qualifier 32 | public @interface UniqueIdentifier { 33 | 34 | String id(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/java/org/apache/aries/jpa/cdi/support/UniqueIdentifierLitteral.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.aries.jpa.cdi.support; 18 | 19 | import javax.enterprise.util.AnnotationLiteral; 20 | import java.util.UUID; 21 | 22 | public class UniqueIdentifierLitteral extends AnnotationLiteral implements UniqueIdentifier { 23 | 24 | private final String id; 25 | 26 | public UniqueIdentifierLitteral(String id) { 27 | this.id = id; 28 | } 29 | 30 | @Override 31 | public String id() { 32 | return id; 33 | } 34 | 35 | public static UniqueIdentifierLitteral random() { 36 | return new UniqueIdentifierLitteral(UUID.randomUUID().toString()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | -------------------------------------------------------------------------------- /jpa-cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | org.apache.aries.jpa.cdi.TransactionExtension 19 | org.apache.aries.jpa.cdi.JpaExtension 20 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | Export-Package: !* 19 | Bundle-Activator: org.apache.aries.jpa.eclipselink.adapter.Activator 20 | 21 | # This plugin can work with JPA 2.0 or 2.1, but not future versions (which 22 | # May change the PersistenceProvider interface), so we have a custom contract. 23 | Require-Capability: \ 24 | osgi.contract; filter:="(&(osgi.contract=JavaJPA)(|(version=2)(version=2.1))(!(version>=2.2)))",\ 25 | osgi.identity; effective:=active; filter:="(osgi.identity=org.eclipse.persistence.jpa)" 26 | Provide-Capability: \ 27 | osgi.service; effective:=active; objectClass=javax.persistence.spi.PersistenceProvider 28 | 29 | # To ensure the contract works properly we import without versions 30 | Import-Package:\ 31 | javax.persistence;version=0.0.0,\ 32 | javax.persistence.criteria;version=0.0.0,\ 33 | javax.persistence.metamodel;version=0.0.0,\ 34 | javax.persistence.spi;version=0.0.0,\ 35 | * 36 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkPersistenceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.eclipselink.adapter; 20 | 21 | import java.util.Map; 22 | 23 | import javax.persistence.EntityManagerFactory; 24 | import javax.persistence.spi.PersistenceProvider; 25 | import javax.persistence.spi.PersistenceUnitInfo; 26 | import javax.persistence.spi.ProviderUtil; 27 | 28 | import org.osgi.framework.Bundle; 29 | 30 | @SuppressWarnings({"rawtypes", "unchecked"}) 31 | final class EclipseLinkPersistenceProvider implements PersistenceProvider { 32 | private final PersistenceProvider delegate; 33 | private final Bundle eclipeLinkBundle; 34 | 35 | EclipseLinkPersistenceProvider(PersistenceProvider delegate, Bundle eclipeLinkBundle) { 36 | this.delegate = delegate; 37 | this.eclipeLinkBundle = eclipeLinkBundle; 38 | } 39 | 40 | @Override 41 | public ProviderUtil getProviderUtil() { 42 | return delegate.getProviderUtil(); 43 | } 44 | 45 | @Override 46 | public EntityManagerFactory createEntityManagerFactory(String arg0, Map arg1) { 47 | return delegate.createEntityManagerFactory(arg0, arg1); 48 | } 49 | 50 | @Override 51 | public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo punit, Map props) { 52 | return delegate.createContainerEntityManagerFactory(new PersistenceUnitProxyWithTargetServer(punit, eclipeLinkBundle, props), props); 53 | } 54 | 55 | @Override 56 | public void generateSchema(PersistenceUnitInfo punit, Map arg1) { 57 | delegate.generateSchema(new PersistenceUnitProxyWithTargetServer(punit, eclipeLinkBundle, arg1), arg1); 58 | } 59 | 60 | @Override 61 | public boolean generateSchema(String arg0, Map arg1) { 62 | return delegate.generateSchema(arg0, arg1); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/platform/OSGiTSServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.eclipselink.adapter.platform; 20 | 21 | import org.eclipse.persistence.platform.server.ServerPlatformBase; 22 | import org.eclipse.persistence.sessions.DatabaseSession; 23 | 24 | @SuppressWarnings("rawtypes") 25 | public class OSGiTSServer extends ServerPlatformBase { 26 | 27 | public OSGiTSServer(DatabaseSession newDatabaseSession) { 28 | super(newDatabaseSession); 29 | } 30 | 31 | @Override 32 | public Class getExternalTransactionControllerClass() { 33 | return OSGiTSWrapper.class; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/platform/OSGiTSWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.eclipselink.adapter.platform; 20 | 21 | import javax.transaction.TransactionManager; 22 | 23 | import org.eclipse.persistence.transaction.JTATransactionController; 24 | import org.osgi.framework.BundleContext; 25 | import org.osgi.framework.FrameworkUtil; 26 | import org.osgi.framework.ServiceReference; 27 | 28 | @SuppressWarnings({"rawtypes", "unchecked"}) 29 | public class OSGiTSWrapper extends JTATransactionController { 30 | 31 | @Override 32 | protected TransactionManager acquireTransactionManager() throws Exception { 33 | BundleContext ctx = FrameworkUtil.getBundle(OSGiTSWrapper.class).getBundleContext(); 34 | 35 | if (ctx != null) { 36 | ServiceReference ref = ctx.getServiceReference(TransactionManager.class.getName()); 37 | 38 | if (ref != null) { 39 | return (TransactionManager) ctx.getService(ref); 40 | } 41 | } 42 | 43 | return super.acquireTransactionManager(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /jpa-container-eclipselink-adapter/src/main/resources/org/apache/aries/jpa/eclipselink/adapter/jpaEclipseLinkAdapter.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | error.creating.eclipselink.provider=An exception was caught trying to instantiate the EclipseLink JPA provider. -------------------------------------------------------------------------------- /jpa-container/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jpa-container/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /jpa-container/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | Export-Package: \ 19 | org.osgi.service.jpa 20 | 21 | Bundle-Activator: org.apache.aries.jpa.container.impl.Activator 22 | Provide-Capability: \ 23 | osgi.extender;osgi.extender=aries.jpa;version:Version="${project.version.clean}",\ 24 | osgi.extender;osgi.extender="osgi.jpa";version:Version="1.1";uses:="org.osgi.service.jpa,javax.persistence",\ 25 | osgi.service;objectClass=javax.persistence.EntityManagerFactory;effective:=active;uses:=javax.persistence,\ 26 | osgi.service;objectClass=org.osgi.service.jpa.EntityManagerFactoryBuilder;effective:=active";uses:=org.osgi.service.jpa 27 | 28 | # The Aries JPA container is able to work with JPA 2.0 or 2.1, but may need enhancement 29 | # For future versions, hence we prohibit versions of the contract greater than 2.1.x 30 | # Because of this complexity we can't just use -contract: JavaJPA. 31 | Require-Capability: \ 32 | osgi.contract;filter:="(&(osgi.contract=JavaJPA)(|(version=2)(version=2.1))(!(version>=2.2)))",\ 33 | osgi.service;effective:=active;filter:="(objectClass=javax.persistence.spi.PersistenceProvider)" 34 | 35 | # To ensure the contract works properly we import without versions 36 | Import-Package:\ 37 | javax.persistence;version=0.0.0,\ 38 | javax.persistence.criteria;version=0.0.0,\ 39 | javax.persistence.metamodel;version=0.0.0,\ 40 | javax.persistence.spi;version=0.0.0,\ 41 | * 42 | -------------------------------------------------------------------------------- /jpa-container/src/main/appended-resources/META-INF/NOTICE.vm: -------------------------------------------------------------------------------- 1 | Aries JPA includes the persistence schemas from the JPA specifications. 2 | Copyright 2005-2009 Sun Microsystems, Inc. All rights reserved. 3 | Aries JPA elects to include this software in this distribution under the 4 | CDDL license. You can obtain a copy of the License at: 5 | https://glassfish.dev.java.net/public/CDDL+GPL.html 6 | The source code is available at: 7 | https://glassfish.dev.java.net/source/browse/glassfish/ 8 | -------------------------------------------------------------------------------- /jpa-container/src/main/java/org/apache/aries/jpa/container/impl/StoredPerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.impl; 20 | 21 | import org.osgi.framework.ServiceRegistration; 22 | import org.osgi.service.jpa.EntityManagerFactoryBuilder; 23 | 24 | public class StoredPerProvider { 25 | AriesEntityManagerFactoryBuilder builder; 26 | ServiceRegistration reg; 27 | } -------------------------------------------------------------------------------- /jpa-container/src/main/java/org/apache/aries/jpa/container/weaving/impl/TransformerRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.weaving.impl; 20 | 21 | import javax.persistence.spi.ClassTransformer; 22 | 23 | import org.osgi.framework.Bundle; 24 | 25 | public interface TransformerRegistry { 26 | 27 | /** 28 | * Register a new transformer with the WeavingHook 29 | * 30 | * @param pBundle The persistence bundle to weave 31 | * @param transformer The transformer to weave with 32 | */ 33 | public void addTransformer(Bundle pBundle, ClassTransformer transformer); 34 | 35 | 36 | /** 37 | * Remove a given transformer from this weaving hook. This must be 38 | * @param pBundle The persistence bundle to unweave 39 | * @param transformer The transformer to remove 40 | */ 41 | public void removeTransformer(Bundle pBundle, ClassTransformer transformer); 42 | } 43 | -------------------------------------------------------------------------------- /jpa-container/src/main/java/org/apache/aries/jpa/container/weaving/impl/TransformerRegistrySingleton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.weaving.impl; 20 | 21 | 22 | /** 23 | * This class is used to get hold of the active {@link TransformerRegistry} for this bundle. 24 | */ 25 | public class TransformerRegistrySingleton { 26 | private static TransformerRegistry instance; 27 | 28 | private TransformerRegistrySingleton() { 29 | } 30 | 31 | public static TransformerRegistry get() { 32 | if (instance == null) { 33 | instance = new JPAWeavingHook(); 34 | } 35 | return instance; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jpa-container/src/test/java/org/apache/aries/jpa/container/impl/DataSourceTrackerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.impl; 20 | 21 | import static org.mockito.Mockito.atLeastOnce; 22 | import static org.mockito.Mockito.mock; 23 | import static org.mockito.Mockito.verify; 24 | 25 | import org.junit.Test; 26 | import org.mockito.Mockito; 27 | import org.osgi.framework.BundleContext; 28 | import org.osgi.framework.InvalidSyntaxException; 29 | 30 | public class DataSourceTrackerTest { 31 | 32 | @Test 33 | public void testCreateFilterFull() throws InvalidSyntaxException { 34 | BundleContext context = mock(BundleContext.class); 35 | 36 | DataSourceTracker.createFilter(context, "osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)", "test"); 37 | 38 | verify(context, atLeastOnce()).createFilter(Mockito.eq("(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=tasklist))")); 39 | } 40 | 41 | @Test 42 | public void testCreateFilterSimple() throws InvalidSyntaxException { 43 | BundleContext context = mock(BundleContext.class); 44 | 45 | DataSourceTracker.createFilter(context, "tasklist", "test"); 46 | 47 | verify(context, atLeastOnce()).createFilter(Mockito.eq("(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=tasklist))")); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jpa-container/src/test/java/org/apache/aries/jpa/container/impl/ManagedEMFTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.container.impl; 20 | 21 | import static org.mockito.Mockito.verify; 22 | 23 | import java.util.Collections; 24 | import java.util.Dictionary; 25 | import java.util.Hashtable; 26 | 27 | import org.junit.Test; 28 | import org.junit.runner.RunWith; 29 | import org.mockito.Mock; 30 | import org.mockito.Mockito; 31 | import org.mockito.runners.MockitoJUnitRunner; 32 | import org.osgi.framework.InvalidSyntaxException; 33 | import org.osgi.service.cm.ConfigurationException; 34 | 35 | @RunWith(MockitoJUnitRunner.class) 36 | public class ManagedEMFTest { 37 | 38 | @Mock 39 | AriesEntityManagerFactoryBuilder builder; 40 | 41 | @Test 42 | public void testEmfWithoutProps() throws InvalidSyntaxException, ConfigurationException { 43 | ManagedEMF emf = new ManagedEMF(builder, "test"); 44 | emf.updated(null); 45 | Mockito.verifyZeroInteractions(builder); 46 | 47 | Hashtable props = new Hashtable(); 48 | emf.updated(props); 49 | verify(builder).createEntityManagerFactory(props); 50 | 51 | emf.updated(null); 52 | verify(builder).closeEMF(); 53 | 54 | } 55 | 56 | @Test 57 | public void testEmfWithProps() throws InvalidSyntaxException, ConfigurationException { 58 | ManagedEMF emf = new ManagedEMF(builder, "test"); 59 | 60 | Dictionary props = new Hashtable(); 61 | props.put("hibernate.hbm2ddl.auto", "create-drop"); 62 | emf.updated(props); 63 | 64 | verify(builder).createEntityManagerFactory(Collections.singletonMap( 65 | "hibernate.hbm2ddl.auto", "create-drop")); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /jpa-features/src/main/feature/feature.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 |
JPA implementation provided by Apache Aries JPA 2.x. NB: this feature doesn't provide the JPA engine, you have to install one by yourself (OpenJPA for instance)
23 | 24 | osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider 25 | 26 | 27 | mvn:org.apache.aries.jpa.javax.persistence/javax.persistence_2.1/${project.version} 28 | mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 29 | mvn:org.osgi/org.osgi.service.jdbc/1.0.0 30 | mvn:org.apache.felix/org.apache.felix.coordinator/1.0.2 31 | mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/${project.version} 32 | mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/${project.version} 33 | mvn:org.apache.aries.jpa/org.apache.aries.jpa.support/${project.version} 34 | 35 | aries-blueprint 36 | mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint/${project.version} 37 | 38 |
39 | 40 |
41 | -------------------------------------------------------------------------------- /jpa-support/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /jpa-support/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Aries 3 | Copyright 2009-2011 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). 7 | 8 | 9 | -------------------------------------------------------------------------------- /jpa-support/README.md: -------------------------------------------------------------------------------- 1 | #Aries JPA Helper services 2 | 3 | These services are deprecated in favour of the standard OSGi Transaction Control Service, which provides a much fuller set of available functions. -------------------------------------------------------------------------------- /jpa-support/osgi.bnd: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | -contract: JavaJPA 19 | Bundle-Activator: org.apache.aries.jpa.support.osgi.impl.Activator 20 | Require-Capability:\ 21 | osgi.service;effective:=active;filter:="(objectClass=org.osgi.service.coordinator.Coordinator)" 22 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/org/apache/aries/jpa/support/impl/AbstractJpaTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.support.impl; 20 | 21 | import javax.persistence.EntityManager; 22 | 23 | import org.apache.aries.jpa.template.EmConsumer; 24 | import org.apache.aries.jpa.template.EmFunction; 25 | import org.apache.aries.jpa.template.JpaTemplate; 26 | import org.apache.aries.jpa.template.TransactionType; 27 | 28 | public abstract class AbstractJpaTemplate implements JpaTemplate { 29 | 30 | @Override 31 | public void tx(final TransactionType type, final EmConsumer code) { 32 | txExpr(type, new EmFunction() { 33 | @Override 34 | public Object apply(EntityManager em) { 35 | code.accept(em); 36 | return null; 37 | } 38 | }); 39 | } 40 | 41 | @Override 42 | public R txExpr(final EmFunction code) { 43 | return txExpr(TransactionType.Required, code); 44 | } 45 | 46 | @Override 47 | public void tx(final EmConsumer code) { 48 | tx(TransactionType.Required, code); 49 | } 50 | 51 | protected RuntimeException wrapThrowable(Throwable ex, String message) { 52 | if (ex instanceof RuntimeException) { 53 | return (RuntimeException) ex; 54 | } 55 | return new RuntimeException(message, ex); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/Activator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.support.osgi.impl; 20 | 21 | import org.osgi.framework.BundleActivator; 22 | import org.osgi.framework.BundleContext; 23 | 24 | public class Activator implements BundleActivator { 25 | 26 | private CoordinatorTracker coordinatorTracker; 27 | 28 | @Override 29 | public void start(BundleContext context) throws Exception { 30 | coordinatorTracker = new CoordinatorTracker(context); 31 | coordinatorTracker.open(); 32 | } 33 | 34 | @Override 35 | public void stop(BundleContext context) throws Exception { 36 | coordinatorTracker.close(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/CoordinatorTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.support.osgi.impl; 20 | 21 | import org.osgi.framework.BundleContext; 22 | import org.osgi.framework.ServiceReference; 23 | import org.osgi.service.coordinator.Coordinator; 24 | import org.osgi.util.tracker.ServiceTracker; 25 | 26 | public class CoordinatorTracker extends ServiceTracker { 27 | 28 | public CoordinatorTracker(BundleContext context) { 29 | super(context, Coordinator.class, null); 30 | } 31 | 32 | @Override 33 | public EMFTracker addingService(ServiceReference ref) { 34 | Coordinator coordinator = context.getService(ref); 35 | EMFTracker emfTracker = new EMFTracker(context, coordinator); 36 | emfTracker.open(); 37 | return emfTracker; 38 | } 39 | 40 | @Override 41 | public void removedService(ServiceReference ref, EMFTracker emfTracker) { 42 | emfTracker.close(); 43 | super.removedService(ref, emfTracker); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /jpa-support/src/main/java/org/apache/aries/jpa/support/osgi/impl/EmProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.support.osgi.impl; 20 | 21 | import java.lang.reflect.InvocationHandler; 22 | import java.lang.reflect.InvocationTargetException; 23 | import java.lang.reflect.Method; 24 | 25 | import javax.persistence.EntityManager; 26 | 27 | import org.apache.aries.jpa.supplier.EmSupplier; 28 | 29 | public class EmProxy implements InvocationHandler { 30 | EmSupplier emSupplier; 31 | 32 | public EmProxy(EmSupplier emSupplier) { 33 | this.emSupplier = emSupplier; 34 | } 35 | 36 | @Override 37 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 38 | EntityManager em = emSupplier.get(); 39 | if (em == null) { 40 | throw new IllegalStateException("EntityManager not available. Make sure you run in an @Transactional method"); 41 | } 42 | try { 43 | return method.invoke(em, args); 44 | } catch (InvocationTargetException ex) { // NOSONAR 45 | throw ex.getTargetException(); 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /jpa-support/src/test/java/org/apache/aries/jpa/impl/DummyCoordinator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.aries.jpa.impl; 20 | 21 | import java.util.ArrayDeque; 22 | import java.util.Collection; 23 | 24 | import org.osgi.service.coordinator.Coordination; 25 | import org.osgi.service.coordinator.Coordinator; 26 | import org.osgi.service.coordinator.Participant; 27 | 28 | public class DummyCoordinator implements Coordinator { 29 | 30 | private java.util.Deque coordinations = new ArrayDeque(); 31 | 32 | @Override 33 | public Coordination create(String name, long timeMillis) { 34 | throw new IllegalStateException(); 35 | } 36 | 37 | 38 | @Override 39 | public Coordination begin(String name, long timeMillis) { 40 | Coordination oldCoordination = coordinations.peekLast(); 41 | Coordination coordination = new DummyCoordination(oldCoordination); 42 | this.coordinations.push(coordination); 43 | return coordination; 44 | } 45 | 46 | @Override 47 | public Coordination peek() { 48 | return coordinations.peek(); 49 | } 50 | 51 | @Override 52 | public Coordination pop() { 53 | return coordinations.pop(); 54 | } 55 | 56 | @Override 57 | public boolean fail(Throwable cause) { 58 | return false; 59 | } 60 | 61 | @Override 62 | public boolean addParticipant(Participant participant) { 63 | return false; 64 | } 65 | 66 | @Override 67 | public Collection getCoordinations() { 68 | return null; 69 | } 70 | 71 | @Override 72 | public Coordination getCoordination(long id) { 73 | return null; 74 | } 75 | 76 | } 77 | --------------------------------------------------------------------------------