Search in sources :

Example 1 with EntityBean$JAXB.readEntityBean

use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.

the class DebuggableVmHackery method deploy.

public AppModule deploy(final AppModule appModule) throws OpenEJBException {
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
        ejbJar.setRelationships(null);
        final List<String> removed = new ArrayList<>();
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            final String ejbName = bean.getEjbName();
            final EjbDeployment ejbDeployment = deployments.get(ejbName);
            pruneRefs(bean, ejbDeployment);
            // }
            if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
                continue;
            }
            ejbJar.removeEnterpriseBean(ejbName);
            openejbJar.removeEjbDeployment(ejbDeployment);
            removed.add(ejbName);
            final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
            if (assemblyDescriptor != null) {
                for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
                    for (final Method method : copy(permission.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            permission.getMethod().remove(method);
                        }
                    }
                    if (permission.getMethod().size() == 0) {
                        assemblyDescriptor.getMethodPermission().remove(permission);
                    }
                }
                for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
                    for (final Method method : copy(transaction.getMethod())) {
                        if (method.getEjbName().equals(ejbName)) {
                            transaction.getMethod().remove(method);
                        }
                    }
                    if (transaction.getMethod().size() == 0) {
                        assemblyDescriptor.getContainerTransaction().remove(transaction);
                    }
                }
                for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
                    if (binding.getEjbName().equals(ejbName)) {
                        assemblyDescriptor.getInterceptorBinding().remove(binding);
                    }
                }
            }
        }
        // Drop any ejb ref to with an ejb-link to a removed ejb
        for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
            bean.getEjbLocalRefMap().keySet().removeAll(removed);
            bean.getEjbRefMap().keySet().removeAll(removed);
        }
        for (final Interceptor interceptor : ejbJar.getInterceptors()) {
            pruneRefs(interceptor, new EjbDeployment());
        }
    }
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) ArrayList(java.util.ArrayList) Method(org.apache.openejb.jee.Method) MethodPermission(org.apache.openejb.jee.MethodPermission) InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Example 2 with EntityBean$JAXB.readEntityBean

use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.

the class InitEjbDeployments method deploy.

public synchronized AppModule deploy(final AppModule appModule) throws OpenEJBException {
    final Set<String> abstractSchemaNames = new HashSet<>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            if (isCmpEntity(bean)) {
                final EntityBean entity = (EntityBean) bean;
                final String name = entity.getAbstractSchemaName();
                if (name != null) {
                    abstractSchemaNames.add(name);
                }
            }
        }
    }
    final Map<String, String> contextData = new HashMap<>();
    contextData.put("appId", appModule.getModuleId());
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        contextData.put("host", ejbModule.isWebapp() ? findHost(ejbModule.getModuleId(), appModule.getWebModules()) : appModule.uniqueHostIfExists());
        contextData.put("hash", Integer.toString(ejbModule.hashCode()));
        contextData.put("ejbJarId", ejbModule.getModuleId());
        deploy(ejbModule, contextData, abstractSchemaNames);
    }
    contextData.clear();
    return appModule;
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) HashMap(java.util.HashMap) EntityBean(org.apache.openejb.jee.EntityBean) HashSet(java.util.HashSet)

Example 3 with EntityBean$JAXB.readEntityBean

use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.

the class CheckMethods method check_createMethodsAreImplemented.

public boolean check_createMethodsAreImplemented(final RemoteBean b, final Class bean, final Class home) {
    boolean result = true;
    final Method[] homeMethods = home.getMethods();
    for (Method homeMethod : homeMethods) {
        if (!homeMethod.getName().startsWith("create")) {
            continue;
        }
        final Method create = homeMethod;
        final StringBuilder ejbCreateName = new StringBuilder(create.getName());
        ejbCreateName.replace(0, 1, "ejbC");
        try {
            if (javax.ejb.EnterpriseBean.class.isAssignableFrom(bean)) {
                bean.getMethod(ejbCreateName.toString(), create.getParameterTypes());
            }
        // TODO: else { /* Check for Init method in pojo session bean class */ }
        } catch (final NoSuchMethodException e) {
            result = false;
            final String paramString = getParameters(create);
            if (b instanceof EntityBean) {
                final EntityBean entity = (EntityBean) b;
                fail(b, "entity.no.ejb.create", b.getEjbClass(), entity.getPrimKeyClass(), ejbCreateName.toString(), paramString);
            } else {
                if (b instanceof SessionBean) {
                    final SessionBean sb = (SessionBean) b;
                    // Under EJB 3.1, it is not required that a stateless session bean have an ejbCreate method, even when it has a home interface
                    if (!sb.getSessionType().equals(SessionType.STATELESS)) {
                        fail(b, "session.no.ejb.create", b.getEjbClass(), ejbCreateName.toString(), paramString);
                    }
                }
            }
        }
    }
    return result;
}
Also used : EntityBean(org.apache.openejb.jee.EntityBean) Method(java.lang.reflect.Method) SessionBean(org.apache.openejb.jee.SessionBean)

Example 4 with EntityBean$JAXB.readEntityBean

use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.

the class LegacyInterfaceTest method test.

public void test() 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));
    // <entity>
    // <ejb-name>License</ejb-name>
    // <local-home>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome</local-home>
    // <local>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal</local>
    // <ejb-class>org.apache.openejb.test.entity.cmr.onetoone.LicenseBean</ejb-class>
    // <persistence-type>Container</persistence-type>
    // <prim-key-class>java.lang.Integer</prim-key-class>
    // <reentrant>false</reentrant>
    // <cmp-version>2.x</cmp-version>
    // <abstract-schema-name>License</abstract-schema-name>
    // <cmp-field>
    // <field-name>id</field-name>
    // </cmp-field>
    // <cmp-field>
    // <field-name>number</field-name>
    // </cmp-field>
    // <cmp-field>
    // <field-name>points</field-name>
    // </cmp-field>
    // <cmp-field>
    // <field-name>notes</field-name>
    // </cmp-field>
    // <primkey-field>id</primkey-field>
    // <query>
    // <!-- CompondPK one-to-one shares the local home interface so we need to declare this useless finder -->
    // <query-method>
    // <method-name>findByPrimaryKey</method-name>
    // <method-params>
    // <method-param>org.apache.openejb.test.entity.cmr.onetoone.LicensePk</method-param>
    // </method-params>
    // </query-method>
    // <ejb-ql>SELECT OBJECT(DL) FROM License DL</ejb-ql>
    // </query>
    // </entity>
    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();
    // <container-transaction>
    // <method>
    // <ejb-name>MyBean</ejb-name>
    // <method-name>*</method-name>
    // </method>
    // <trans-attribute>Supports</trans-attribute>
    // </container-transaction>
    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());
    module.getEjbModules().add(new EjbModule(ejbJar));
    assembler.createApplication(config.configureApplication(module));
}
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) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) SingletonBean(org.apache.openejb.jee.SingletonBean) 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 5 with EntityBean$JAXB.readEntityBean

use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.

the class LegacyInterfaceTest method testCustomCmpMappings.

public void testCustomCmpMappings() 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 EntityMappings entityMappings = new EntityMappings();
    final Entity entity = new 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 Id id = new 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);
    final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entityMappings);
    module.getEjbModules().add(ejbModule);
    assertNull(module.getCmpMappings());
    assembler.createApplication(config.configureApplication(module));
    assertNotNull(module.getCmpMappings());
    final List<Basic> basicList = module.getCmpMappings().getEntityMap().get("openejb.org.apache.openejb.core.MyCmpBean").getAttributes().getBasic();
    assertEquals(1, basicList.size());
    assertEquals(300, basicList.get(0).getColumn().getLength().intValue());
    assertEquals("wNAME", basicList.get(0).getColumn().getName());
}
Also used : Entity(org.apache.openejb.jee.jpa.Entity) Basic(org.apache.openejb.jee.jpa.Basic) 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) Attributes(org.apache.openejb.jee.jpa.Attributes) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) CmpField(org.apache.openejb.jee.CmpField) Column(org.apache.openejb.jee.jpa.Column) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) 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) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) Assembler(org.apache.openejb.assembler.classic.Assembler) NamedQuery(org.apache.openejb.jee.jpa.NamedQuery) Id(org.apache.openejb.jee.jpa.Id) File(java.io.File)

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