You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/05/18 07:06:53 UTC

[25/38] git commit: [OLINGO-245] Fix for names of foreign key names. Properties representing foreign key are prefixed with FK

[OLINGO-245] Fix for names of foreign key names. 
Properties representing foreign key are prefixed with FK


Signed-off-by: Chandan V A <ch...@sap.com>

Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/2dd0181d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/2dd0181d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/2dd0181d

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 2dd0181d4fce203d6cf4e67367b25ffe54540340
Parents: 74dff0f
Author: Chandan V A <ch...@sap.com>
Authored: Sat Apr 19 16:07:44 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sat Apr 19 16:07:44 2014 +0530

----------------------------------------------------------------------
 .../jpa/processor/core/access/model/JPAEdmNameBuilder.java  | 6 +++++-
 .../odata2/jpa/processor/core/model/JPAEdmProperty.java     | 9 +++++----
 .../processor/core/access/model/JPAEdmNameBuilderTest.java  | 4 ++--
 3 files changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2dd0181d/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
index 9c22364..1f0e152 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
@@ -58,6 +58,7 @@ public class JPAEdmNameBuilder {
   private static final String ASSOCIATIONSET_SUFFIX = "Set";
   private static final String NAVIGATION_NAME = "Details";
   private static final String UNDERSCORE = "_";
+  private static final String FK_PREFIX = "FK";
 
   public static FullQualifiedName build(final JPAEdmBaseView view, final String name) {
     FullQualifiedName fqName = new FullQualifiedName(buildNamespace(view), name);
@@ -124,7 +125,7 @@ public class JPAEdmNameBuilder {
    * ************************************************************************
    */
   public static void build(final JPAEdmPropertyView view, final boolean isComplexMode,
-      final boolean skipDefaultNaming) {
+      final boolean skipDefaultNaming, final boolean isForeignKey) {
     Attribute<?, ?> jpaAttribute = view.getJPAAttribute();
     String jpaAttributeName = jpaAttribute.getName();
     String propertyName = null;
@@ -145,6 +146,9 @@ public class JPAEdmNameBuilder {
       propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
     } else if (propertyName == null) {
       propertyName = jpaAttributeName;
+      if (isForeignKey == true) {
+        propertyName = FK_PREFIX + UNDERSCORE + propertyName;
+      }
     }
 
     view.getEdmSimpleProperty().setName(propertyName);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2dd0181d/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
index e23f3b1..8ea02f7 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
@@ -210,7 +210,7 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
         switch (attributeType) {
         case BASIC:
           currentSimpleProperty = new SimpleProperty();
-          properties.add(buildSimpleProperty(currentAttribute, currentSimpleProperty));
+          properties.add(buildSimpleProperty(currentAttribute, currentSimpleProperty, false));
           if (((SingularAttribute<?, ?>) currentAttribute).isId()) {
             if (keyView == null) {
               keyView = new JPAEdmKey(JPAEdmProperty.this);
@@ -321,12 +321,13 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
 
     }
 
-    private SimpleProperty buildSimpleProperty(final Attribute<?, ?> jpaAttribute, final SimpleProperty simpleProperty)
+    private SimpleProperty buildSimpleProperty(final Attribute<?, ?> jpaAttribute, final SimpleProperty simpleProperty,
+        final boolean isFK)
         throws ODataJPAModelException,
         ODataJPARuntimeException {
 
       JPAEdmNameBuilder
-          .build((JPAEdmPropertyView) JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming);
+          .build((JPAEdmPropertyView) JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming, isFK);
       EdmSimpleTypeKind simpleTypeKind = JPATypeConvertor
           .convertToEdmSimpleType(jpaAttribute
               .getJavaType(), jpaAttribute);
@@ -360,7 +361,7 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
               if (referencedColumn != null && referencedColumn.name().equals((joinColumn.referencedColumnName()))) {
                 currentRefAttribute = referencedAttribute;
                 currentSimpleProperty = new SimpleProperty();
-                properties.add(buildSimpleProperty(currentRefAttribute, currentSimpleProperty));
+                properties.add(buildSimpleProperty(currentRefAttribute, currentSimpleProperty, true));
                 break;
               }
             }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2dd0181d/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
index 542d37f..aebea64 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
@@ -49,7 +49,7 @@ public class JPAEdmNameBuilderTest {
     EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
     EasyMock.replay(propertyView);
 
-    JPAEdmNameBuilder.build(propertyView, false, false);
+    JPAEdmNameBuilder.build(propertyView, false, false,false);
     assertEquals("Id", simpleProperty.getName());
   }
 
@@ -69,7 +69,7 @@ public class JPAEdmNameBuilderTest {
     EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
     EasyMock.replay(propertyView);
 
-    JPAEdmNameBuilder.build(propertyView, false, true);
+    JPAEdmNameBuilder.build(propertyView, false, true,false);
     assertEquals("id", simpleProperty.getName());
   }