Search in sources :

Example 1 with OneOneFinders

use of org.apache.openejb.jee.sun.OneOneFinders 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

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CmpField (org.apache.openejb.jee.CmpField)1 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)1 EntityBean (org.apache.openejb.jee.EntityBean)1 NamedQuery (org.apache.openejb.jee.jpa.NamedQuery)1 Cmp (org.apache.openejb.jee.sun.Cmp)1 Ejb (org.apache.openejb.jee.sun.Ejb)1 Finder (org.apache.openejb.jee.sun.Finder)1 OneOneFinders (org.apache.openejb.jee.sun.OneOneFinders)1