コード例 #1
0
  public static void build(final JPAEdmAssociationView view, final int count) {
    Association association = view.getEdmAssociation();
    String associationName = null;
    String end1Name = association.getEnd1().getType().getName();
    String end2Name = association.getEnd2().getType().getName();

    if (end1Name.compareToIgnoreCase(end2Name) > 0) {
      associationName = end2Name + UNDERSCORE + end1Name;
    } else {
      associationName = end1Name + UNDERSCORE + end2Name;
    }
    if (count > 1) {
      associationName = associationName + Integer.toString(count - 1);
    }
    association.setName(associationName);
  }
コード例 #2
0
  public static void build(
      final JPAEdmAssociationView associationView,
      final JPAEdmPropertyView propertyView,
      final JPAEdmNavigationPropertyView navPropertyView,
      final int count) {

    String toName = null;
    String fromName = null;
    String navPropName = null;
    NavigationProperty navProp = navPropertyView.getEdmNavigationProperty();
    String namespace = buildNamespace(associationView);

    Association association = associationView.getEdmAssociation();
    navProp.setRelationship(new FullQualifiedName(namespace, association.getName()));

    FullQualifiedName associationEndTypeOne = association.getEnd1().getType();
    FullQualifiedName associationEndTypeTwo = association.getEnd2().getType();

    Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
    navProp.setMapping(new Mapping().setInternalName(jpaAttribute.getName()));

    String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView().getJPAEntityType().getName();
    JPAEdmMappingModelAccess mappingModelAccess = navPropertyView.getJPAEdmMappingModelAccess();

    try {
      PluralAttribute<?, ?, ?> jpattr = (PluralAttribute<?, ?, ?>) propertyView.getJPAAttribute();

      if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
        toName =
            mappingModelAccess.mapJPAEntityType(
                jpattr.getElementType().getJavaType().getSimpleName());
        fromName = mappingModelAccess.mapJPAEntityType(jpaEntityTypeName);
        navPropName = mappingModelAccess.mapJPARelationship(jpaEntityTypeName, jpattr.getName());
      }
      if (toName == null) {
        toName = jpattr.getElementType().getJavaType().getSimpleName();
      }
      if (fromName == null) {
        fromName = jpaEntityTypeName;
      }

      if (navPropName == null) {
        navPropName = toName.concat(NAVIGATION_NAME);
      }
      if (count > 1) {
        navPropName = navPropName + Integer.toString(count - 1);
      }
      navProp.setName(navPropName);

      if (toName.equals(associationEndTypeOne.getName())) {
        navProp.setFromRole(association.getEnd2().getRole());
        navProp.setToRole(association.getEnd1().getRole());
      } else if (toName.equals(associationEndTypeTwo.getName())) {
        navProp.setToRole(association.getEnd2().getRole());
        navProp.setFromRole(association.getEnd1().getRole());
      }

    } catch (Exception e) {
      if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
        navPropName =
            mappingModelAccess.mapJPARelationship(jpaEntityTypeName, jpaAttribute.getName());
        toName = mappingModelAccess.mapJPAEntityType(jpaAttribute.getJavaType().getSimpleName());
        fromName = mappingModelAccess.mapJPAEntityType(jpaEntityTypeName);
      }
      if (toName == null) {
        toName = jpaAttribute.getJavaType().getSimpleName();
      }
      if (fromName == null) {
        fromName = jpaEntityTypeName;
      }

      if (navPropName == null) {
        navPropName = toName.concat(NAVIGATION_NAME);
      }
      if (count > 1) {
        navPropName = navPropName + Integer.toString(count - 1);
      }
      navProp.setName(navPropName);

      if (toName.equals(associationEndTypeOne.getName())) {
        navProp.setFromRole(association.getEnd2().getRole());
        navProp.setToRole(association.getEnd1().getRole());
      } else if (toName.equals(associationEndTypeTwo.getName())) {

        navProp.setToRole(association.getEnd2().getRole());
        navProp.setFromRole(association.getEnd1().getRole());
      }
    }
  }