if (roles == null || roles.size() != 2) {
// dunno what to do with this
continue;
}
EjbRelationshipRole left = roles.get(0);
EjbRelationshipRole right = roles.get(1);
String leftClass = getEjbClass(ejbJar, left.getRelationshipRoleSource().getEjbName());
String rightClass = getEjbClass(ejbJar, right.getRelationshipRoleSource().getEjbName());
String leftMethod = null;
try {
leftMethod = "get" + capitaliseFirstLetter(left.getCmrField().getCmrFieldName());
} catch (Exception e) {
}
String rightMethod = null;
try {
rightMethod = "get" + capitaliseFirstLetter(right.getCmrField().getCmrFieldName());
} catch (Exception e) {
}
boolean leftCascade = left.getCascadeDelete();
boolean rightCascade = right.getCascadeDelete();
Map<String, Object> leftProps = new HashMap<String, Object>();
leftProps.put("targetEntity", rightClass);
if (leftCascade) {
leftProps.put("cascade", new Object[] { javax.persistence.CascadeType.REMOVE }); //$NON-NLS-1$
}
Map<String, Object> rightProps = new HashMap<String, Object>();
rightProps.put("targetEntity", leftClass);
if (rightCascade) {
rightProps.put("cascade", new Object[] { javax.persistence.CascadeType.REMOVE }); //$NON-NLS-1$
}
if (Multiplicity.MANY.equals(left.getMultiplicity()) && Multiplicity.MANY.equals(right.getMultiplicity())) {
if (leftMethod != null)
facade.addMethodAnnotation(leftClass, leftMethod, new String[0], javax.persistence.ManyToMany.class, leftProps);
if (rightMethod != null)
facade.addMethodAnnotation(rightClass, rightMethod, new String[0], javax.persistence.ManyToMany.class, rightProps);
} else if (Multiplicity.MANY.equals(left.getMultiplicity()) && Multiplicity.ONE.equals(right.getMultiplicity())) {
if (leftMethod != null)
facade.addMethodAnnotation(leftClass, leftMethod, new String[0], javax.persistence.ManyToOne.class, leftProps);
if (rightMethod != null)
facade.addMethodAnnotation(rightClass, rightMethod, new String[0], javax.persistence.OneToMany.class, rightProps);
} else if (Multiplicity.ONE.equals(left.getMultiplicity()) && Multiplicity.MANY.equals(right.getMultiplicity())) {
if (leftMethod != null)
facade.addMethodAnnotation(leftClass, leftMethod, new String[0], javax.persistence.OneToMany.class, leftProps);
if (rightMethod != null)
facade.addMethodAnnotation(rightClass, rightMethod, new String[0], javax.persistence.ManyToOne.class, rightProps);
} else if (Multiplicity.ONE.equals(left.getMultiplicity()) && Multiplicity.ONE.equals(right.getMultiplicity())) {
if (leftMethod != null)
facade.addMethodAnnotation(leftClass, leftMethod, new String[0], javax.persistence.OneToOne.class, leftProps);
if (rightMethod != null)
facade.addMethodAnnotation(rightClass, rightMethod, new String[0], javax.persistence.OneToOne.class, rightProps);
}