Search in sources :

Example 1 with EntityBean

use of org.apache.openejb.jee.EntityBean 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<String>();
    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<String, String>();
    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 2 with EntityBean

use of org.apache.openejb.jee.EntityBean 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<String>();
        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 3 with EntityBean

use of org.apache.openejb.jee.EntityBean 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 (int i = 0; i < homeMethods.length; i++) {
        if (!homeMethods[i].getName().startsWith("create")) {
            continue;
        }
        final Method create = homeMethods[i];
        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

use of org.apache.openejb.jee.EntityBean 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) 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

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

the class SunConversion method mergeEntityMappings.

private void mergeEntityMappings(final Map<String, EntityData> entities, final String moduleId, final EjbJar ejbJar, final OpenejbJar openejbJar, final SunEjbJar sunEjbJar) {
    if (openejbJar == null) {
        return;
    }
    if (sunEjbJar == null) {
        return;
    }
    if (sunEjbJar.getEnterpriseBeans() == null) {
        return;
    }
    for (final Ejb ejb : sunEjbJar.getEnterpriseBeans().getEjb()) {
        final Cmp cmp = ejb.getCmp();
        if (cmp == null) {
            // skip non cmp beans
            continue;
        }
        // skip all non-CMP beans
        final EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejb.getEjbName());
        if (!(enterpriseBean instanceof EntityBean) || ((EntityBean) enterpriseBean).getPersistenceType() != PersistenceType.CONTAINER) {
            continue;
        }
        final EntityBean bean = (EntityBean) enterpriseBean;
        final EntityData entityData = entities.get(moduleId + "#" + ejb.getEjbName());
        if (entityData == null) {
            // todo warn no such ejb in the ejb-jar.xml
            continue;
        }
        final Collection<String> cmpFields = new ArrayList<String>(bean.getCmpField().size());
        for (final CmpField cmpField : bean.getCmpField()) {
            cmpFields.add(cmpField.getFieldName());
        }
        final OneOneFinders oneOneFinders = cmp.getOneOneFinders();
        if (oneOneFinders != null) {
            for (final Finder finder : oneOneFinders.getFinder()) {
                final List<List<String>> params = parseQueryParamters(finder.getQueryParams());
                final String queryFilter = finder.getQueryFilter();
                final String ejbQl = convertToEjbQl(entityData.entity.getName(), cmpFields, finder.getQueryParams(), queryFilter);
                final NamedQuery namedQuery = new NamedQuery();
                final StringBuilder name = new StringBuilder();
                name.append(entityData.entity.getName()).append(".").append(finder.getMethodName());
                if (!params.isEmpty()) {
                    name.append('(');
                    boolean first = true;
                    for (final List<String> methodParam : params) {
                        if (!first) {
                            name.append(",");
                        }
                        name.append(methodParam.get(0));
                        first = false;
                    }
                    name.append(')');
                }
                namedQuery.setName(name.toString());
                namedQuery.setQuery(ejbQl);
                entityData.entity.getNamedQuery().add(namedQuery);
            }
        }
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Cmp(org.apache.openejb.jee.sun.Cmp) ArrayList(java.util.ArrayList) OneOneFinders(org.apache.openejb.jee.sun.OneOneFinders) Finder(org.apache.openejb.jee.sun.Finder) CmpField(org.apache.openejb.jee.CmpField) EntityBean(org.apache.openejb.jee.EntityBean) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamedQuery(org.apache.openejb.jee.jpa.NamedQuery) Ejb(org.apache.openejb.jee.sun.Ejb)

Aggregations

EntityBean (org.apache.openejb.jee.EntityBean)10 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)5 EjbJar (org.apache.openejb.jee.EjbJar)4 ArrayList (java.util.ArrayList)3 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)3 HashMap (java.util.HashMap)2 List (java.util.List)2 CmpField (org.apache.openejb.jee.CmpField)2 ContainerTransaction (org.apache.openejb.jee.ContainerTransaction)2 MessageDrivenBean (org.apache.openejb.jee.MessageDrivenBean)2 SessionBean (org.apache.openejb.jee.SessionBean)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 RemoteException (java.rmi.RemoteException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 CreateException (javax.ejb.CreateException)1