Search in sources :

Example 6 with EntityBean$JAXB.readEntityBean

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));
}
Also used : AppModule(org.apache.openejb.config.AppModule) NamedQuery(org.apache.openejb.jee.jpa.NamedQuery) Query(org.apache.openejb.jee.Query) QueryMethod(org.apache.openejb.jee.QueryMethod) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) PersistenceModule(org.apache.openejb.config.PersistenceModule) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) SingletonBean(org.apache.openejb.jee.SingletonBean) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) CmpField(org.apache.openejb.jee.CmpField) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) File(java.io.File) EjbJar(org.apache.openejb.jee.EjbJar)

Example 7 with EntityBean$JAXB.readEntityBean

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;
}
Also used : EntityBean(org.apache.openejb.jee.EntityBean) PersistenceType(org.apache.openejb.jee.PersistenceType)

Example 8 with EntityBean$JAXB.readEntityBean

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);
}
Also used : Entity(javax.persistence.Entity) Basic(org.apache.openejb.jee.jpa.Basic) NamedQuery(org.apache.openejb.jee.jpa.NamedQuery) Query(org.apache.openejb.jee.Query) QueryMethod(org.apache.openejb.jee.QueryMethod) Attributes(org.apache.openejb.jee.jpa.Attributes) EjbModule(org.apache.openejb.config.EjbModule) CmpField(org.apache.openejb.jee.CmpField) Column(org.apache.openejb.jee.jpa.Column) EjbJar(org.apache.openejb.jee.EjbJar) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) SingletonBean(org.apache.openejb.jee.SingletonBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) NamedQuery(org.apache.openejb.jee.jpa.NamedQuery) Id(javax.persistence.Id) File(java.io.File) EjbModule(org.apache.openejb.config.EjbModule) AppModule(org.apache.openejb.config.AppModule) Module(org.apache.openejb.testing.Module)

Example 9 with EntityBean$JAXB.readEntityBean

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;
}
Also used : EntityBean(org.apache.openejb.jee.EntityBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 10 with EntityBean$JAXB.readEntityBean

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;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EntityBean(org.apache.openejb.jee.EntityBean) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EntityBean (org.apache.openejb.jee.EntityBean)13 EjbJar (org.apache.openejb.jee.EjbJar)7 CmpField (org.apache.openejb.jee.CmpField)5 ContainerTransaction (org.apache.openejb.jee.ContainerTransaction)5 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)5 NamedQuery (org.apache.openejb.jee.jpa.NamedQuery)5 File (java.io.File)4 RemoteException (java.rmi.RemoteException)4 CreateException (javax.ejb.CreateException)4 EJBException (javax.ejb.EJBException)4 RemoveException (javax.ejb.RemoveException)4 AppModule (org.apache.openejb.config.AppModule)4 EjbModule (org.apache.openejb.config.EjbModule)4 ArrayList (java.util.ArrayList)3 Assembler (org.apache.openejb.assembler.classic.Assembler)3 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)3 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)3 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)3 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)3 Query (org.apache.openejb.jee.Query)3