use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class LegacyInterfaceTest method testCustomCmpMappingsWithMappingFileDefinedInPersistenceXml.
public void testCustomCmpMappingsWithMappingFileDefinedInPersistenceXml() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
cmp.setPrimKeyClass(Integer.class.getName());
cmp.setPrimkeyField("id");
cmp.getCmpField().add(new CmpField("id"));
cmp.getCmpField().add(new CmpField("name"));
final Query query = new Query();
query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
cmp.getQuery().add(query);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
final File f = new File("test").getAbsoluteFile();
if (!f.exists() && !f.mkdirs()) {
throw new Exception("Failed to create test directory: " + f);
}
final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
final EjbModule ejbModule = new EjbModule(ejbJar);
Persistence persistence = new Persistence();
PersistenceUnit pu = persistence.addPersistenceUnit("cmp");
pu.setTransactionType(TransactionType.JTA);
pu.setJtaDataSource("fake");
pu.setNonJtaDataSource("fake");
pu.getMappingFile().add("test-orm.xml");
pu.getClazz().add("openejb.org.apache.openejb.core.MyCmpBean");
module.addPersistenceModule(new PersistenceModule("pu", persistence));
module.getEjbModules().add(ejbModule);
assertNull(module.getCmpMappings());
assembler.createApplication(config.configureApplication(module));
assertNotNull(module.getCmpMappings());
// no mapping should be automatically generated
assertTrue(module.getCmpMappings().getEntityMap().isEmpty());
// pu should not be modified, no duplicate classes
assertEquals(1, pu.getClazz().size());
assertEquals("openejb.org.apache.openejb.core.MyCmpBean", pu.getClazz().get(0));
assertEquals(1, pu.getMappingFile().size());
assertEquals("test-orm.xml", pu.getMappingFile().get(0));
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class ValidationBase method isCmp.
public boolean isCmp(final EnterpriseBean b) {
if (b instanceof EntityBean) {
final EntityBean entityBean = (EntityBean) b;
final PersistenceType persistenceType = entityBean.getPersistenceType();
return persistenceType == PersistenceType.CONTAINER;
}
return false;
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class JPACMDIntegrationTest method ejbModule.
@Module
public EjbModule ejbModule() throws Exception {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
cmp.setPrimKeyClass(Integer.class.getName());
cmp.setPrimkeyField("id");
cmp.getCmpField().add(new CmpField("id"));
cmp.getCmpField().add(new CmpField("name"));
final Query query = new Query();
query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
cmp.getQuery().add(query);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
final File f = new File("test").getAbsoluteFile();
if (!f.exists() && !f.mkdirs()) {
throw new Exception("Failed to create test directory: " + f);
}
final EntityMappings entityMappings = new EntityMappings();
final org.apache.openejb.jee.jpa.Entity entity = new org.apache.openejb.jee.jpa.Entity();
entity.setClazz("openejb.org.apache.openejb.core.MyCmpBean");
entity.setName("MyCmpBean");
entity.setDescription("MyCmpBean");
entity.setAttributes(new Attributes());
final NamedQuery namedQuery = new NamedQuery();
namedQuery.setQuery("SELECT OBJECT(DL) FROM License DL");
entity.getNamedQuery().add(namedQuery);
final org.apache.openejb.jee.jpa.Id id = new org.apache.openejb.jee.jpa.Id();
id.setName("id");
entity.getAttributes().getId().add(id);
final Basic basic = new Basic();
basic.setName("name");
final Column column = new Column();
column.setName("wNAME");
column.setLength(300);
basic.setColumn(column);
entity.getAttributes().getBasic().add(basic);
entityMappings.getEntity().add(entity);
return new EjbModule(ejbJar);
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class CheckWrongClassTypeTest method wrongClassType.
@Keys({ @Key("wrong.class.type"), @Key("noInterfaceDeclared.entity") })
public EjbJar wrongClassType() throws OpenEJBException {
System.setProperty("openejb.validation.output.level", "VERBOSE");
final EjbJar ejbJar = new EjbJar();
final EntityBean entityBean = new EntityBean();
entityBean.setEjbClass(FooEntity.class);
entityBean.setEjbName("fooEntity");
entityBean.setPersistenceType(PersistenceType.BEAN);
ejbJar.addEnterpriseBean(entityBean);
return ejbJar;
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class CheckMissingClassTest method wrongClassType.
@Keys(@Key(value = "missing.class", count = 16))
public EjbJar wrongClassType() throws OpenEJBException {
System.setProperty("openejb.validation.output.level", "VERBOSE");
final EjbJar ejbJar = new EjbJar();
final StatelessBean stateless = new StatelessBean(FooStateless.class);
stateless.setHomeAndRemote("WrongHome", "WrongRemote");
stateless.setLocal("WrongLocal");
stateless.setLocalHome("WrongLocalHome");
ejbJar.addEnterpriseBean(stateless);
final StatefulBean stateful = new StatefulBean(FooStateful.class);
stateful.setHomeAndRemote("WrongHome", "WrongRemote");
stateful.setLocal("WrongLocal");
stateful.setLocalHome("WrongLocalHome");
ejbJar.addEnterpriseBean(stateful);
final EntityBean bmpEntityBean = new EntityBean(FooEntityBMP.class, PersistenceType.BEAN);
bmpEntityBean.setHome("WrongHome");
bmpEntityBean.setLocalHome("WrongLocalHome");
bmpEntityBean.setRemote("WrongRemote");
bmpEntityBean.setLocal("WrongLocal");
ejbJar.addEnterpriseBean(bmpEntityBean);
final EntityBean cmpEntityBean = new EntityBean(FooEntityCMP.class, PersistenceType.CONTAINER);
cmpEntityBean.setHome("WrongHome");
cmpEntityBean.setLocalHome("WrongLocalHome");
cmpEntityBean.setRemote("WrongRemote");
cmpEntityBean.setLocal("WrongLocal");
ejbJar.addEnterpriseBean(cmpEntityBean);
return ejbJar;
}
Aggregations