Search in sources :

Example 16 with PersistenceUnit

use of org.apache.openejb.jee.jpa.unit.PersistenceUnit in project tomee by apache.

the class MoviesXATest method jpa.

@Module
public PersistenceUnit jpa() {
    final PersistenceUnit unit = new PersistenceUnit("movie-unit");
    unit.setJtaDataSource("movieDatabase");
    unit.setNonJtaDataSource("movieDatabaseUnmanaged");
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(foreignKeys=true,schemaAction='dropDB,add')");
    unit.addClass(Movie.class);
    return unit;
}
Also used : PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) Module(org.apache.openejb.testing.Module)

Example 17 with PersistenceUnit

use of org.apache.openejb.jee.jpa.unit.PersistenceUnit in project tomee by apache.

the class ResourceLocalCdiEmTest method persistence.

@Module
public Persistence persistence() {
    final PersistenceUnit unit = new PersistenceUnit("rl-unit");
    unit.setTransactionType(TransactionType.RESOURCE_LOCAL);
    unit.setNonJtaDataSource("ResourceLocalCdiEmTest");
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    unit.setExcludeUnlistedClasses(true);
    final Persistence persistence = new Persistence(unit);
    persistence.setVersion("2.0");
    return persistence;
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) Module(org.apache.openejb.testing.Module)

Example 18 with PersistenceUnit

use of org.apache.openejb.jee.jpa.unit.PersistenceUnit in project tomee by apache.

the class ReloadableEntityManagerFactoryTest method persistence.

@Module
public Persistence persistence() throws Exception {
    final PersistenceUnit unit = new PersistenceUnit("foo-unit");
    unit.addClass(MyEntity.class);
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    unit.getProperties().setProperty("openjpa.DataCache", "false");
    unit.setExcludeUnlistedClasses(true);
    final Persistence persistence = new org.apache.openejb.jee.jpa.unit.Persistence(unit);
    persistence.setVersion("2.0");
    return persistence;
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) Module(org.apache.openejb.testing.Module)

Example 19 with PersistenceUnit

use of org.apache.openejb.jee.jpa.unit.PersistenceUnit in project tomee by apache.

the class ResourceLocalEmInjectionTest method persistence.

@Module
public Persistence persistence() {
    final PersistenceUnit unit = new PersistenceUnit("rl-unit");
    unit.setTransactionType(TransactionType.RESOURCE_LOCAL);
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    unit.setExcludeUnlistedClasses(true);
    final Persistence persistence = new Persistence(unit);
    persistence.setVersion("2.0");
    return persistence;
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) Module(org.apache.openejb.testing.Module)

Example 20 with PersistenceUnit

use of org.apache.openejb.jee.jpa.unit.PersistenceUnit in project tomee by apache.

the class EntityManagerPropogationTest method setUp.

public void setUp() throws OpenEJBException, IOException, NamingException {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    System.setProperty("openejb.embedded", "true");
    // Boot up the minimum required OpenEJB components
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Start creating the test application
    // Create an ejb-jar.xml for this app
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean("PleaseCloseMyExtendedEm", PleaseCloseMyExtendedEmBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean("PleaseCloseMyEm", PleaseCloseMyEmBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("PleaseCloseMyLessEm", PleaseCloseMyEmBean.class));
    // Add six beans and link them all in a chain
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extended", "Extendedx2");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx2", "Extendedx3");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx3", "Extendedx4");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx4", "Extendedx5");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "ExtendedToTransaction", "StatelessTransactionToExtended");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx5", "Extendedx6");
    ejbJar.addEnterpriseBean(new StatefulBean("Extendedx6", EndNodeBean.class));
    // Add six beans and link them all in a chain
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transaction", "Transactionx2");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx2", "Transactionx3");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx3", "Transactionx4");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx4", "Transactionx5");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx5", "Transactionx6");
    addStatefulBean(ejbJar, TransactionContextBean.class, "TransactionToExtended", "Extendedx5");
    addStatelessBean(ejbJar, TransactionContextBean.class, "StatelessTransactionToExtended", "Extendedx5");
    ejbJar.addEnterpriseBean(new StatefulBean("Transactionx6", EndNodeBean.class));
    ejbJar.setAssemblyDescriptor(new AssemblyDescriptor());
    ejbJar.getAssemblyDescriptor().addApplicationException(IllegalArgumentException.class, false, true);
    ejbJar.getAssemblyDescriptor().addApplicationException(ArgumentException.class, false, true);
    // List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    // declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(), "Extendedx5", "*"));
    // declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(), "TransactionToExtended", "*"));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    // Create an "ear"
    final AppModule appModule = new AppModule(ejbModule.getClassLoader(), "test-app");
    // Add the ejb-jar.xml to the ear
    appModule.getEjbModules().add(ejbModule);
    // Create a persistence-unit for this app
    final PersistenceUnit unit = new PersistenceUnit("testUnit");
    unit.addClass(Color.class);
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    // Add the persistence.xml to the "ear"
    appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
    // Configure and assemble the ear -- aka. deploy it
    final AppInfo info = config.configureApplication(appModule);
    assembler.createApplication(info);
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) PersistenceModule(org.apache.openejb.config.PersistenceModule) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)48 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)36 Module (org.apache.openejb.testing.Module)19 AppModule (org.apache.openejb.config.AppModule)10 EjbJar (org.apache.openejb.jee.EjbJar)10 AppInfo (org.apache.openejb.assembler.classic.AppInfo)9 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)9 EjbModule (org.apache.openejb.config.EjbModule)9 PersistenceModule (org.apache.openejb.config.PersistenceModule)8 WebApp (org.apache.openejb.jee.WebApp)7 ArrayList (java.util.ArrayList)5 StatelessBean (org.apache.openejb.jee.StatelessBean)5 File (java.io.File)4 Properties (java.util.Properties)4 URL (java.net.URL)3 Collection (java.util.Collection)3 List (java.util.List)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 Assembler (org.apache.openejb.assembler.classic.Assembler)3 PersistenceUnitInfo (org.apache.openejb.assembler.classic.PersistenceUnitInfo)3