public static void build()

in odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java [127:204]


  public static void build(final JPAEdmPropertyView view, final boolean isComplexMode,
      final boolean skipDefaultNaming, final boolean isForeignKey) {
    Attribute<?, ?> jpaAttribute = view.getJPAAttribute();
    String jpaAttributeName = jpaAttribute.getName();
    String propertyName = null;
    String[] joinColumnNames = null;

    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
      if (isComplexMode) {
        propertyName =
            mappingModelAccess.mapJPAEmbeddableTypeAttribute(view.getJPAEdmComplexTypeView().getJPAEmbeddableType()
                .getJavaType().getSimpleName(), jpaAttributeName);
      } else {
        propertyName =
            mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
                jpaAttributeName);
      }
    }
    if (isForeignKey == true) {
      joinColumnNames = view.getJPAJoinColumns().get(view.getJPAJoinColumns().size() - 1);
    }

    if (skipDefaultNaming == false && propertyName == null) {
      propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
    } else if (propertyName == null) {
      propertyName = jpaAttributeName;
      if (isForeignKey) {
        if (mappingModelAccess != null) {
          propertyName =
              mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
                  joinColumnNames[0]);
        }
        if (propertyName == null) {
          propertyName = FK_PREFIX + UNDERSCORE + joinColumnNames[0];
        }
      }
    }

    view.getEdmSimpleProperty().setName(propertyName);

    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    mapping.setJPAType(jpaAttribute.getJavaType());

    AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember();
    if (annotatedElement != null) {
      Column column = annotatedElement.getAnnotation(Column.class);
      if (column != null) {
        mapping.setJPAColumnName(column.name());
      } else if (joinColumnNames != null) {
        mapping.setJPAColumnName(joinColumnNames[0]);
      } else {
        mapping.setJPAColumnName(jpaAttributeName);
      }
      if (isForeignKey) {
        jpaAttributeName += "." + view.getJPAReferencedAttribute().getName();
      }
    } else {
      ManagedType<?> managedType = jpaAttribute.getDeclaringType();
      if (managedType != null) {
        Class<?> clazz = managedType.getJavaType();
        try {
          Field field = clazz.getField(jpaAttributeName);
          Column column = field.getAnnotation(Column.class);
          if (column != null) {
            mapping.setJPAColumnName(column.name());
          }
        } catch (SecurityException e) {

        } catch (NoSuchFieldException e) {

        }
      }

    }
    ((Mapping) mapping).setInternalName(jpaAttributeName);
    view.getEdmSimpleProperty().setMapping((Mapping) mapping);
  }