コード例 #1
0
  // TODO: can this be implemented in a simpler way?  is there
  // any real value to using the map here as opposed to iterating
  // the relationships live?
  private EjbRelationshipRole getRoleDescriptor(
      String ejbName, String cmrFieldName, boolean opposite) {
    Map rels = (HashMap) relationshipRoleMap.get(ejbName);
    Iterator iterator = rels.keySet().iterator();

    while (iterator.hasNext()) {
      EjbRelation rel = (EjbRelation) iterator.next();
      EjbRelationshipRole role = (EjbRelationshipRole) rels.get(rel);
      EjbRelationshipRole role1 = rel.getEjbRelationshipRole();
      EjbRelationshipRole role2 = rel.getEjbRelationshipRole2();
      CmrField candidateCmr = role.getCmrField();

      if (ejbName.equals(role.getRelationshipRoleSource().getEjbName())
          && (candidateCmr != null)
          && cmrFieldName.equals(candidateCmr.getCmrFieldName())) {
        return ((opposite) ? ((role == role1) ? role2 : role1) : role);
      } else { // check for self ref relationship
        String ejb1 = role1.getRelationshipRoleSource().getEjbName();

        if (ejb1.equals(role2.getRelationshipRoleSource().getEjbName()) && ejbName.equals(ejb1)) {
          role = ((role == role1) ? role2 : role1);
          candidateCmr = role.getCmrField();

          if ((candidateCmr != null) && cmrFieldName.equals(candidateCmr.getCmrFieldName())) {
            return ((opposite) ? ((role == role1) ? role2 : role1) : role);
          }
        }
      }
    }
    throw new IllegalArgumentException();
  }
コード例 #2
0
  /** This method return the fieldName of relation role on the other end. */
  public String getInverseFieldName(String ejbName, String fieldName) {
    EjbRelationshipRole oppRole = getOppositeRoleDescriptor(ejbName, fieldName);
    CmrField inverse = ((oppRole == null) ? null : oppRole.getCmrField());
    String inverseName = ((inverse == null) ? null : inverse.getCmrFieldName());

    // if we are generating relationships, check for a generated inverse
    if (generateFields() && (inverseName == null)) {
      inverseName = getNameMapper().getGeneratedFieldForEjbField(ejbName, fieldName)[1];
    }

    return inverseName;
  }