Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.EntityBean


                    logger.info("Auto-assigning deployment-id for ejb " + bean.getEjbName() + ": EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
                }
            }

            if (isCmpEntity(bean)){
                EntityBean entity = (EntityBean) bean;
                if (entity.getAbstractSchemaName() == null){
                    String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");
                    // The AbstractSchemaName must be unique, we should check that it is
                    entity.setAbstractSchemaName(abstractSchemaName);
                }
            }
        }

        return ejbModule;
View Full Code Here


    }

    public boolean isCmp(EnterpriseBean b) {

        if (b instanceof EntityBean) {
            EntityBean entityBean = (EntityBean) b;
            PersistenceType persistenceType = entityBean.getPersistenceType();
            return persistenceType == PersistenceType.CONTAINER;
        }
        return false;
    }
View Full Code Here

        StatelessBean slsb = new StatelessBean();
        String slsbName = "SLSB";
        slsb.setEjbName(slsbName);
        ejbJar.addEnterpriseBean(slsb);
       
        EntityBean entity = new EntityBean();
        entity.setEjbName("entity");
        ejbJar.addEnterpriseBean(entity);
       
        MessageDrivenBean mdb = new MessageDrivenBean();
        mdb.setEjbName("mdb");
        ejbJar.addEnterpriseBean(mdb);
View Full Code Here

        Set<String> abstractSchemaNames = new HashSet<String>();
        for (EjbModule ejbModule : appModule.getEjbModules()) {
            for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
                if (isCmpEntity(bean)) {
                    EntityBean entity = (EntityBean) bean;
                    String name = entity.getAbstractSchemaName();
                    if (name != null) {
                        abstractSchemaNames.add(name);
                    }
                }
            }
View Full Code Here

            if (ejbDeployment.getContainerId() == null && annotation != null && isDefined(annotation.container())) {
                ejbDeployment.setContainerId(annotation.container());
            }

            if (isCmpEntity(bean)) {
                EntityBean entity = (EntityBean) bean;
                if (entity.getAbstractSchemaName() == null) {
                    String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");

                    // The AbstractSchemaName must be unique, we should check that it is
                    if (abstractSchemaNames.contains(abstractSchemaName)) {
                        int i = 2;
                        while (abstractSchemaNames.contains(abstractSchemaName + i)) {
                             i++;
                        }
                        abstractSchemaName = abstractSchemaName + i;
                    }

                    abstractSchemaNames.add(abstractSchemaName);
                    entity.setAbstractSchemaName(abstractSchemaName);
                }
            }
        }

        return ejbModule;
View Full Code Here

            // skip all non-CMP beans
            if (!(enterpriseBean instanceof EntityBean) ||
                    ((EntityBean) enterpriseBean).getPersistenceType() != PersistenceType.CONTAINER) {
                continue;
            }
            EntityBean bean = (EntityBean) enterpriseBean;

            // Always set the abstract schema name
            if (bean.getAbstractSchemaName() == null) {
                String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");
                if (entitiesByName.containsKey(abstractSchemaName)) {
                    int i = 2;
                    while (entitiesByName.containsKey(abstractSchemaName + i)) {
                         i++;
                    }
                    abstractSchemaName = abstractSchemaName + i;
                }
                bean.setAbstractSchemaName(abstractSchemaName);
            }

            // try to add a new persistence-context-ref for cmp
            if (!addPersistenceContextRef(bean)) {
                // Bean already has a persistence-context-ref for cmp
                // which means it has a mapping, so skip this bean
                continue;
            }

            Entity entity = new Entity();

            // description: contains the name of the entity bean
            entity.setDescription(ejbModule.getModuleId() + "#" + bean.getEjbName());

            // name: the name of the entity in queries
            String entityName = bean.getAbstractSchemaName();
            entity.setName(entityName);

            // class: impl class name
            String cmpImplClassName = CmpUtil.getCmpImplClassName(bean.getAbstractSchemaName(), bean.getEjbClass());
            entity.setClazz(cmpImplClassName);

            // add the entity
            entityMappings.getEntity().add(entity);
            entitiesByName.put(bean.getEjbName(), entity);

            if (bean.getCmpVersion() == CmpVersion.CMP2) {
                mapClass2x(entity, bean, classLoader);
            } else {
                // map the cmp class, but if we are using a mapped super class, generate attribute-override instead of id and basic
                Collection<MappedSuperclass> mappedSuperclasses = mapClass1x(bean.getEjbClass(), entity, bean, classLoader);
                for (MappedSuperclass mappedSuperclass : mappedSuperclasses) {
                    mappedSuperclassByClass.put(mappedSuperclass.getClazz(), mappedSuperclass);
                }
            }

            // process queries
            for (Query query : bean.getQuery()) {
                NamedQuery namedQuery = new NamedQuery();
                QueryMethod queryMethod = query.getQueryMethod();

                // todo deployment id could change in one of the later conversions... use entity name instead, but we need to save it off
                StringBuilder name = new StringBuilder();
                name.append(entityName).append(".").append(queryMethod.getMethodName());
                if (queryMethod.getMethodParams() != null && !queryMethod.getMethodParams().getMethodParam().isEmpty()) {
                    name.append('(');
                    boolean first = true;
                    for (String methodParam : queryMethod.getMethodParams().getMethodParam()) {
                        if (!first) name.append(",");
                        name.append(methodParam);
                        first = false;
                    }
                    name.append(')');
                }
                namedQuery.setName(name.toString());

                namedQuery.setQuery(query.getEjbQl());
                entity.getNamedQuery().add(namedQuery);
            }
            // todo: there should be a common interface between ejb query object and openejb query object
            EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
            if (ejbDeployment != null) {
                for (org.apache.openejb.jee.oejb3.Query query : ejbDeployment.getQuery()) {
                    NamedQuery namedQuery = new NamedQuery();
                    org.apache.openejb.jee.oejb3.QueryMethod queryMethod = query.getQueryMethod();
View Full Code Here

            EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejb.getEjbName());
            if (!(enterpriseBean instanceof org.apache.openejb.jee.EntityBean) ||
                    ((EntityBean) enterpriseBean).getPersistenceType() != PersistenceType.CONTAINER) {
                continue;
            }
            EntityBean bean = (EntityBean) enterpriseBean;
            EntityData entityData = entities.get(moduleId + "#" + ejb.getEjbName());
            if (entityData == null) {
                // todo warn no such ejb in the ejb-jar.xml
                continue;
            }

            Collection<String> cmpFields = new ArrayList<String>(bean.getCmpField().size());
            for (CmpField cmpField : bean.getCmpField()) {
                cmpFields.add(cmpField.getFieldName());
            }

            OneOneFinders oneOneFinders = cmp.getOneOneFinders();
            if (oneOneFinders != null) {
View Full Code Here

        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

        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>

        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"));
        Query query = new Query();
        query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
        query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
        cmp.getQuery().add(query);
        List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();

        //<container-transaction>
        //  <method>
        //    <ejb-name>MyBean</ejb-name>
View Full Code Here

            EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejb.getEjbName());
            if (!(enterpriseBean instanceof org.apache.openejb.jee.EntityBean) ||
                    ((EntityBean) enterpriseBean).getPersistenceType() != PersistenceType.CONTAINER) {
                continue;
            }
            EntityBean bean = (EntityBean) enterpriseBean;
            EntityData entityData = entities.get(moduleId + "#" + ejb.getEjbName());
            if (entityData == null) {
                // todo warn no such ejb in the ejb-jar.xml
                continue;
            }

            Collection<String> cmpFields = new ArrayList<String>(bean.getCmpField().size());
            for (CmpField cmpField : bean.getCmpField()) {
                cmpFields.add(cmpField.getFieldName());
            }

            OneOneFinders oneOneFinders = cmp.getOneOneFinders();
            if (oneOneFinders != null) {
View Full Code Here

public class CheckWrongClassTypeTest {
    @Keys( { @Key("wrong.class.type"), @Key("noInterfaceDeclared.entity") })
    public EjbJar wrongClassType() throws OpenEJBException {
        System.setProperty("openejb.validation.output.level", "VERBOSE");
        EjbJar ejbJar = new EjbJar();
        EntityBean entityBean = new EntityBean();
        entityBean.setEjbClass(FooEntity.class);
        entityBean.setEjbName("fooEntity");
        entityBean.setPersistenceType(PersistenceType.BEAN);
        ejbJar.addEnterpriseBean(entityBean);
        return ejbJar;
    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.EntityBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.