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);
}
}
}
}
Aggregations