// 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();