use of org.apache.openejb.jee.jpa.unit.Persistence in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppIdThirdParty.
/**
* Existing data source "orange-id", not controlled by us
* <p/>
* Application contains a web module with id "orange-id"
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit" />
* <p/>
* The orange-unit app should automatically use orange-id data source and the non-jta-datasource should be null
*
* @throws Exception
*/
public void testFromWebAppIdThirdParty() throws Exception {
final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
assertSame(supplied, resources.get(0));
final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");
final ClassLoader cl = this.getClass().getClassLoader();
final AppModule app = new AppModule(cl, "orange-app");
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final WebApp webApp = new WebApp();
webApp.setMetadataComplete(true);
app.getWebModules().add(new WebModule(webApp, "orange-web", cl, null, "orange-id"));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
final PersistenceUnitInfo unitInfo = appInfo.persistenceUnits.get(0);
//Check results
assertEquals(supplied.id, unitInfo.jtaDataSource);
assertNull(unitInfo.nonJtaDataSource);
}
use of org.apache.openejb.jee.jpa.unit.Persistence 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);
}
use of org.apache.openejb.jee.jpa.unit.Persistence in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testMultiple.
/**
* Existing data source "Orange", jta managed
* Existing data source "OrangeUnmanaged", not jta managed
* Existing data source "Lime", jta managed
* Existing data source "LimeUnmanaged", not jta managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit">
* <jta-data-source>Orange</jta-data-source>
* <non-jta-data-source>OrangeUnmanaged</non-jta-data-source>
* </persistence-unit>
* <persistence-unit name="lime-unit">
* <jta-data-source>Lime</jta-data-source>
* <non-jta-data-source>LimeUnmanaged</non-jta-data-source>
* </persistence-unit>
* <p/>
* This is the happy path.
*
* @throws Exception
*/
public void testMultiple() throws Exception {
final ResourceInfo orangeJta = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
final ResourceInfo orangeNonJta = addDataSource("OrangeUnmanaged", OrangeDriver.class, "jdbc:orange:some:stuff", false);
final ResourceInfo limeJta = addDataSource("Lime", LimeDriver.class, "jdbc:lime:some:stuff", true);
final ResourceInfo limeNonJta = addDataSource("LimeUnmanaged", LimeDriver.class, "jdbc:lime:some:stuff", false);
assertSame(orangeJta, resources.get(0));
assertSame(orangeNonJta, resources.get(1));
assertSame(limeJta, resources.get(2));
assertSame(limeNonJta, resources.get(3));
final PersistenceUnit unit1 = new PersistenceUnit("orange-unit");
unit1.setJtaDataSource("Orange");
unit1.setNonJtaDataSource("OrangeUnmanaged");
final PersistenceUnit unit2 = new PersistenceUnit("lime-unit");
unit2.setJtaDataSource("Lime");
unit2.setNonJtaDataSource("LimeUnmanaged");
final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
app.addPersistenceModule(new PersistenceModule("root", new Persistence(unit1, unit2)));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
// Check results
final PersistenceUnitInfo orangeUnit = appInfo.persistenceUnits.get(0);
final PersistenceUnitInfo limeUnit = appInfo.persistenceUnits.get(1);
assertNotNull(orangeUnit);
assertEquals(orangeJta.id, orangeUnit.jtaDataSource);
assertEquals(orangeNonJta.id, orangeUnit.nonJtaDataSource);
assertNotNull(limeUnit);
assertEquals(limeJta.id, limeUnit.jtaDataSource);
assertEquals(limeNonJta.id, limeUnit.nonJtaDataSource);
}
Aggregations