public void build()

in odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java [190:325]


    public void build() throws ODataJPAModelException, ODataJPARuntimeException {
      JPAEdmBuilder keyViewBuilder = null;
      properties = new ArrayList<Property>();

      List<Attribute<?, ?>> jpaAttributes = null;
      String currentEntityName = null;
      String targetEntityName = null;
      String entityTypeName = null;
      if (isBuildModeComplexType) {
        jpaAttributes = sortInAscendingOrder(complexTypeView.getJPAEmbeddableType().getAttributes());
        entityTypeName = complexTypeView.getJPAEmbeddableType().getJavaType().getSimpleName();
      } else {
        jpaAttributes = sortInAscendingOrder(entityTypeView.getJPAEntityType().getAttributes());
        entityTypeName = entityTypeView.getJPAEntityType().getName();
      }

      for (Object jpaAttribute : jpaAttributes) {
        currentAttribute = (Attribute<?, ?>) jpaAttribute;

        // Check for need to Exclude
        if (isExcluded((JPAEdmPropertyView) JPAEdmProperty.this, entityTypeName, currentAttribute.getName())) {
          continue;
        }

        PersistentAttributeType attributeType = currentAttribute.getPersistentAttributeType();

        switch (attributeType) {
        case BASIC:
          currentSimpleProperty = new SimpleProperty();
          properties.add(buildSimpleProperty(currentAttribute, currentSimpleProperty));
          if (((SingularAttribute<?, ?>) currentAttribute).isId()) {
            if (keyView == null) {
              keyView = new JPAEdmKey(JPAEdmProperty.this);
              keyViewBuilder = keyView.getBuilder();
            }
            keyViewBuilder.build();
          }
          break;
        case EMBEDDED:
          ComplexType complexType = complexTypeView.searchEdmComplexType(currentAttribute.getJavaType().getName());

          if (complexType == null) {
            JPAEdmComplexTypeView complexTypeViewLocal = new JPAEdmComplexType(schemaView, currentAttribute);
            complexTypeViewLocal.getBuilder().build();
            complexType = complexTypeViewLocal.getEdmComplexType();
            complexTypeView.addJPAEdmCompleTypeView(complexTypeViewLocal);
          }

          if (isBuildModeComplexType == false && entityTypeView.getJPAEntityType().getIdType().getJavaType()
              .equals(currentAttribute.getJavaType())) {

            if (keyView == null) {
              keyView = new JPAEdmKey(complexTypeView, JPAEdmProperty.this);
            }
            keyView.getBuilder().build();
            complexTypeView.expandEdmComplexType(complexType, properties, currentAttribute.getName());
          } else {
            currentComplexProperty = new ComplexProperty();
            if (isBuildModeComplexType) {
              JPAEdmNameBuilder.build((JPAEdmComplexPropertyView) JPAEdmProperty.this,
                  complexTypeView.getJPAEmbeddableType().getJavaType().getSimpleName());
            } else {
              JPAEdmNameBuilder
                  .build((JPAEdmComplexPropertyView) JPAEdmProperty.this, JPAEdmProperty.this, skipDefaultNaming);
            }
            currentComplexProperty
                .setType(new FullQualifiedName(schemaView.getEdmSchema().getNamespace(), complexType.getName()));

            properties.add(currentComplexProperty);
            if (!complexTypeView.isReferencedInKey(currentComplexProperty.getType().getName())) {
              complexTypeView.setReferencedInKey(currentComplexProperty.getType().getName());
            }
          }

          break;
        case MANY_TO_MANY:
        case ONE_TO_MANY:
        case ONE_TO_ONE:
        case MANY_TO_ONE:

          if (attributeType.equals(PersistentAttributeType.MANY_TO_ONE) || attributeType
              .equals(PersistentAttributeType.ONE_TO_ONE)) {
            addForeignKey(currentAttribute);
          }

          JPAEdmAssociationEndView associationEndView = new JPAEdmAssociationEnd(entityTypeView, JPAEdmProperty.this);
          associationEndView.getBuilder().build();
          JPAEdmAssociationView associationView = schemaView.getJPAEdmAssociationView();
          if (associationView.searchAssociation(associationEndView) == null) {
            int count = associationView.getNumberOfAssociationsWithSimilarEndPoints(associationEndView);
            JPAEdmAssociationView associationViewLocal =
                new JPAEdmAssociation(associationEndView, entityTypeView, JPAEdmProperty.this, count);
            associationViewLocal.getBuilder().build();
            associationView.addJPAEdmAssociationView(associationViewLocal, associationEndView);
          }

          if (attributeType.equals(PersistentAttributeType.MANY_TO_ONE) || attributeType
              .equals(PersistentAttributeType.ONE_TO_ONE)) {

            JPAEdmReferentialConstraintView refConstraintView =
                new JPAEdmReferentialConstraint(associationView, entityTypeView, JPAEdmProperty.this);
            refConstraintView.getBuilder().build();

            if (refConstraintView.isExists()) {
              associationView.addJPAEdmRefConstraintView(refConstraintView);
            }
          }
          if (navigationPropertyView == null) {
            navigationPropertyView = new JPAEdmNavigationProperty(schemaView);
          }
          currentEntityName = entityTypeView.getJPAEntityType().getName();

          if (currentAttribute.isCollection()) {
            targetEntityName =
                ((PluralAttribute<?, ?, ?>) currentAttribute).getElementType().getJavaType().getSimpleName();
          } else {
            targetEntityName = currentAttribute.getJavaType().getSimpleName();
          }
          Integer sequenceNumber = associationCount.get(currentEntityName + targetEntityName);
          if (sequenceNumber == null) {
            sequenceNumber = new Integer(1);
          } else {
            sequenceNumber = new Integer(sequenceNumber.intValue() + 1);
          }
          associationCount.put(currentEntityName + targetEntityName, sequenceNumber);
          JPAEdmNavigationPropertyView localNavigationPropertyView =
              new JPAEdmNavigationProperty(associationView, JPAEdmProperty.this, sequenceNumber.intValue());
          localNavigationPropertyView.getBuilder().build();
          navigationPropertyView.addJPAEdmNavigationPropertyView(localNavigationPropertyView);
          break;
        default:
          break;
        }
      }

    }