Search in sources :

Example 1 with EntityBeanInfo

use of org.apache.openejb.assembler.classic.EntityBeanInfo in project tomee by apache.

the class EjbJarInfoBuilder method initRelationshipRole.

private CmrFieldInfo initRelationshipRole(final EjbRelationshipRole role, final EjbRelationshipRole relatedRole, final Map<String, EnterpriseBeanInfo> infos) throws OpenEJBException {
    final CmrFieldInfo cmrFieldInfo = new CmrFieldInfo();
    // find the entityBeanInfo info for this role
    final String ejbName = role.getRelationshipRoleSource().getEjbName();
    final EnterpriseBeanInfo enterpriseBeanInfo = infos.get(ejbName);
    if (enterpriseBeanInfo == null) {
        throw new OpenEJBException("Relation role source ejb not found " + ejbName);
    }
    if (!(enterpriseBeanInfo instanceof EntityBeanInfo)) {
        throw new OpenEJBException("Relation role source ejb is not an entity bean " + ejbName);
    }
    final EntityBeanInfo entityBeanInfo = (EntityBeanInfo) enterpriseBeanInfo;
    cmrFieldInfo.roleSource = entityBeanInfo;
    // RoleName: this may be null
    cmrFieldInfo.roleName = role.getEjbRelationshipRoleName();
    cmrFieldInfo.synthetic = role.getCmrField() == null;
    // CmrFieldName: is null for uni-directional relationships
    if (role.getCmrField() != null) {
        cmrFieldInfo.fieldName = role.getCmrField().getCmrFieldName();
        // CollectionType: java.util.Collection or java.util.Set
        if (role.getCmrField().getCmrFieldType() != null) {
            cmrFieldInfo.fieldType = role.getCmrField().getCmrFieldType().toString();
        }
        if (cmrFieldInfo.fieldType == null && relatedRole.getMultiplicity() == Multiplicity.MANY) {
            cmrFieldInfo.fieldType = Collection.class.getName();
        }
    } else {
        final String relatedEjbName = relatedRole.getRelationshipRoleSource().getEjbName();
        final EnterpriseBeanInfo relatedEjb = infos.get(relatedEjbName);
        if (relatedEjb == null) {
            throw new OpenEJBException("Relation role source ejb not found " + relatedEjbName);
        }
        if (!(relatedEjb instanceof EntityBeanInfo)) {
            throw new OpenEJBException("Relation role source ejb is not an entity bean " + relatedEjbName);
        }
        final EntityBeanInfo relatedEntity = (EntityBeanInfo) relatedEjb;
        relatedRole.getRelationshipRoleSource();
        cmrFieldInfo.fieldName = relatedEntity.abstractSchemaName + "_" + relatedRole.getCmrField().getCmrFieldName();
        if (relatedRole.getMultiplicity() == Multiplicity.MANY) {
            cmrFieldInfo.fieldType = Collection.class.getName();
        }
    }
    // CascadeDelete
    cmrFieldInfo.cascadeDelete = role.getCascadeDelete();
    // Multiplicity: one or many
    cmrFieldInfo.many = role.getMultiplicity() == Multiplicity.MANY;
    // add the field to the entityBean
    entityBeanInfo.cmrFields.add(cmrFieldInfo);
    return cmrFieldInfo;
}
Also used : EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) OpenEJBException(org.apache.openejb.OpenEJBException) CmrFieldInfo(org.apache.openejb.assembler.classic.CmrFieldInfo) Collection(java.util.Collection) EntityBeanInfo(org.apache.openejb.assembler.classic.EntityBeanInfo)

Example 2 with EntityBeanInfo

use of org.apache.openejb.assembler.classic.EntityBeanInfo in project tomee by apache.

the class EjbJarInfoBuilder method initEntityBean.

private EnterpriseBeanInfo initEntityBean(final EntityBean e, final Map m) throws OpenEJBException {
    final EntityBeanInfo bean = new EntityBeanInfo();
    final EjbDeployment d = (EjbDeployment) m.get(e.getEjbName());
    if (d == null) {
        throw new OpenEJBException("No deployment information in openejb-jar.xml for bean " + e.getEjbName() + ". Please redeploy the jar");
    }
    bean.ejbDeploymentId = d.getDeploymentId();
    bean.containerId = d.getContainerId();
    final Icon icon = e.getIcon();
    bean.largeIcon = icon == null ? null : icon.getLargeIcon();
    bean.smallIcon = icon == null ? null : icon.getSmallIcon();
    bean.description = e.getDescription();
    bean.displayName = e.getDisplayName();
    bean.ejbClass = e.getEjbClass();
    bean.abstractSchemaName = e.getAbstractSchemaName();
    bean.ejbName = e.getEjbName();
    bean.home = e.getHome();
    bean.remote = e.getRemote();
    bean.localHome = e.getLocalHome();
    bean.local = e.getLocal();
    bean.transactionType = "Container";
    bean.primKeyClass = e.getPrimKeyClass();
    bean.primKeyField = e.getPrimkeyField();
    bean.persistenceType = e.getPersistenceType().toString();
    bean.reentrant = String.valueOf(e.getReentrant());
    bean.properties.putAll(d.getProperties());
    final CmpVersion cmpVersion = e.getCmpVersion();
    if (e.getPersistenceType() == PersistenceType.CONTAINER) {
        if (cmpVersion != null && cmpVersion == CmpVersion.CMP1) {
            bean.cmpVersion = 1;
        } else {
            bean.cmpVersion = 2;
        }
    }
    final List<CmpField> cmpFields = e.getCmpField();
    for (final CmpField cmpField : cmpFields) {
        bean.cmpFieldNames.add(cmpField.getFieldName());
    }
    if (bean.persistenceType.equalsIgnoreCase("Container")) {
        for (final Query q : e.getQuery()) {
            final QueryInfo query = new QueryInfo();
            query.queryStatement = q.getEjbQl().trim();
            final MethodInfo method = new MethodInfo();
            method.ejbName = bean.ejbName;
            method.className = "*";
            final QueryMethod qm = q.getQueryMethod();
            method.methodName = qm.getMethodName();
            if (qm.getMethodParams() != null) {
                method.methodParams = qm.getMethodParams().getMethodParam();
            }
            query.method = method;
            final ResultTypeMapping resultType = q.getResultTypeMapping();
            if (ResultTypeMapping.REMOTE.equals(resultType)) {
                query.remoteResultType = true;
            }
            bean.queries.add(query);
        }
        for (final org.apache.openejb.jee.oejb3.Query q : d.getQuery()) {
            final QueryInfo query = new QueryInfo();
            query.description = q.getDescription();
            query.queryStatement = q.getObjectQl().trim();
            final MethodInfo method = new MethodInfo();
            method.ejbName = bean.ejbName;
            method.className = "*";
            final org.apache.openejb.jee.oejb3.QueryMethod qm = q.getQueryMethod();
            method.methodName = qm.getMethodName();
            if (qm.getMethodParams() != null) {
                method.methodParams = qm.getMethodParams().getMethodParam();
            }
            query.method = method;
            bean.queries.add(query);
        }
    }
    return bean;
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) ResultTypeMapping(org.apache.openejb.jee.ResultTypeMapping) Query(org.apache.openejb.jee.Query) QueryMethod(org.apache.openejb.jee.QueryMethod) QueryInfo(org.apache.openejb.assembler.classic.QueryInfo) CmpField(org.apache.openejb.jee.CmpField) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) MethodInfo(org.apache.openejb.assembler.classic.MethodInfo) InitMethodInfo(org.apache.openejb.assembler.classic.InitMethodInfo) NamedMethodInfo(org.apache.openejb.assembler.classic.NamedMethodInfo) RemoveMethodInfo(org.apache.openejb.assembler.classic.RemoveMethodInfo) EntityBeanInfo(org.apache.openejb.assembler.classic.EntityBeanInfo) Icon(org.apache.openejb.jee.Icon) CmpVersion(org.apache.openejb.jee.CmpVersion)

Aggregations

OpenEJBException (org.apache.openejb.OpenEJBException)2 EntityBeanInfo (org.apache.openejb.assembler.classic.EntityBeanInfo)2 Collection (java.util.Collection)1 CmrFieldInfo (org.apache.openejb.assembler.classic.CmrFieldInfo)1 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)1 InitMethodInfo (org.apache.openejb.assembler.classic.InitMethodInfo)1 MethodInfo (org.apache.openejb.assembler.classic.MethodInfo)1 NamedMethodInfo (org.apache.openejb.assembler.classic.NamedMethodInfo)1 QueryInfo (org.apache.openejb.assembler.classic.QueryInfo)1 RemoveMethodInfo (org.apache.openejb.assembler.classic.RemoveMethodInfo)1 CmpField (org.apache.openejb.jee.CmpField)1 CmpVersion (org.apache.openejb.jee.CmpVersion)1 Icon (org.apache.openejb.jee.Icon)1 Query (org.apache.openejb.jee.Query)1 QueryMethod (org.apache.openejb.jee.QueryMethod)1 ResultTypeMapping (org.apache.openejb.jee.ResultTypeMapping)1 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)1