use of org.apache.openejb.assembler.classic.CmrFieldInfo 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;
}
use of org.apache.openejb.assembler.classic.CmrFieldInfo in project tomee by apache.
the class EjbJarInfoBuilder method initRelationships.
private void initRelationships(final EjbModule jar, final Map<String, EnterpriseBeanInfo> infos) throws OpenEJBException {
for (final EjbRelation ejbRelation : jar.getEjbJar().getRelationships().getEjbRelation()) {
final Iterator<EjbRelationshipRole> iterator = ejbRelation.getEjbRelationshipRole().iterator();
final EjbRelationshipRole left = iterator.next();
final EjbRelationshipRole right = iterator.next();
// left role info
final CmrFieldInfo leftCmrFieldInfo = initRelationshipRole(left, right, infos);
final CmrFieldInfo rightCmrFieldInfo = initRelationshipRole(right, left, infos);
leftCmrFieldInfo.mappedBy = rightCmrFieldInfo;
rightCmrFieldInfo.mappedBy = leftCmrFieldInfo;
}
}
Aggregations