You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2014/01/02 13:46:51 UTC
[04/47] git commit: [OLINGO-28] Support EDM Extension
[OLINGO-28] Support EDM Extension
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/ecdc476c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/ecdc476c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/ecdc476c
Branch: refs/heads/ODataServlet
Commit: ecdc476c1b2d7abce675c3307e7c1ed72ea84eed
Parents: 636eed2
Author: Chandan V A <ch...@sap.com>
Authored: Mon Dec 23 17:56:09 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Mon Dec 23 17:56:09 2013 +0530
----------------------------------------------------------------------
.../api/jpa/model/JPAEdmComplexTypeView.java | 21 ++++++++++
.../api/jpa/model/JPAEdmSchemaView.java | 5 ---
.../core/jpa/model/JPAEdmComplexType.java | 18 ++++++++-
.../core/jpa/model/JPAEdmEntityContainer.java | 9 -----
.../core/jpa/model/JPAEdmFunctionImport.java | 28 ++++++++++---
.../core/jpa/model/JPAEdmProperty.java | 5 +--
.../processor/core/jpa/model/JPAEdmSchema.java | 36 ++++++++---------
.../core/jpa/model/JPAEdmPropertyTest.java | 6 +--
.../core/jpa/model/JPAEdmTestModelView.java | 20 ++++++----
.../jpa/processor/ref/extension/OrderValue.java | 42 ++++++++++++++++++++
.../extension/SalesOrderHeaderProcessor.java | 18 +++++++++
.../SalesOrderProcessingExtension.java | 34 +++++++++++++++-
12 files changed, 186 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
index bbee5e4..9ec27c4 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
@@ -83,6 +83,8 @@ public interface JPAEdmComplexTypeView extends JPAEdmBaseView {
* The method add a JPA EDM complex type view to the container.
*
* @param view
+ * @param isReferencedInKey
+ * is the complex type referenced in an Entity as a key property
* is an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}
*/
public void addJPAEdmCompleTypeView(JPAEdmComplexTypeView view);
@@ -113,4 +115,23 @@ public interface JPAEdmComplexTypeView extends JPAEdmBaseView {
public void expandEdmComplexType(ComplexType complexType, List<Property> expandedPropertyList,
String embeddablePropertyName);
+ /**
+ * The method checks if the given EDM complex type is referenced as a Key property in any Entity
+ * @param complexTypeName
+ * EDM complex type name
+ * @return
+ * <ul><li><b>true</b> : if the complex type is referenced as an entity's key property</li>
+ * <li><b>false</b> : if the complex type is not referenced as an entity's key property</li>
+ * </ul>
+ *
+ */
+ public boolean isReferencedInKey(String complexTypeName);
+
+ /**
+ * The method sets the given EDM complex type as referenced in an Entity as a key property
+ * @param complexTypeName
+ * EDM complex Type name
+ */
+ public void setReferencedInKey(String complexTypeName);
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
index d52d9a3..0400271 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
@@ -19,7 +19,6 @@
package org.apache.olingo.odata2.processor.api.jpa.model;
import java.util.HashMap;
-import java.util.List;
import org.apache.olingo.odata2.api.edm.provider.Schema;
@@ -109,8 +108,4 @@ public interface JPAEdmSchemaView extends JPAEdmBaseView {
*/
public HashMap<Class<?>, String[]> getRegisteredOperations();
- public List<String> getNonKeyComplexTypeList();
-
- public void addNonKeyComplexName(String complexTypeName);
-
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
index ad25a1b..31831dd 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
@@ -52,11 +52,15 @@ public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmCompl
private List<ComplexType> consistentComplextTypes = null;
private boolean directBuild;
private EmbeddableType<?> nestedComplexType = null;
+ private List<String> nonKeyComplexList = null;
public JPAEdmComplexType(final JPAEdmSchemaView view) {
super(view);
schemaView = view;
directBuild = true;
+ if (nonKeyComplexList == null) {
+ nonKeyComplexList = new ArrayList<String>();
+ }
}
public JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute) {
@@ -69,6 +73,19 @@ public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmCompl
}
}
directBuild = false;
+ if (nonKeyComplexList == null) {
+ nonKeyComplexList = new ArrayList<String>();
+ }
+ }
+
+ @Override
+ public boolean isReferencedInKey(final String complexTypeName) {
+ return nonKeyComplexList.contains(complexTypeName);
+ }
+
+ @Override
+ public void setReferencedInKey(final String complexTypeName) {
+ nonKeyComplexList.add(complexTypeName);
}
@Override
@@ -151,7 +168,6 @@ public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmCompl
JPAEdmMapping oldMapping = (JPAEdmMapping) mapping;
newMapping.setJPAColumnName(oldMapping.getJPAColumnName());
newMapping.setInternalName(embeddablePropertyName + "." + mapping.getInternalName());
- newMapping.setMimeType(mapping.getMimeType());
newMapping.setObject(mapping.getObject());
newMapping.setJPAType(oldMapping.getJPAType());
newSimpleProperty.setMapping(newMapping);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
index fee40c2..1bb60be 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
@@ -28,7 +28,6 @@ import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeExcep
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmFunctionImportView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
@@ -137,14 +136,6 @@ public class JPAEdmEntityContainer extends JPAEdmBaseViewImpl implements JPAEdmE
}
JPAEdmNameBuilder.build(JPAEdmEntityContainer.this);
- if (schemaView.getJPAEdmExtension() != null) {
- JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(schemaView);
- functionImportView.getBuilder().build();
- if (functionImportView.getConsistentFunctionImportList() != null) {
- currentEntityContainer.setFunctionImports(functionImportView.getConsistentFunctionImportList());
- }
- }
-
consistentEntityContainerList.add(currentEntityContainer);
isConsistent = true;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
index b64f61c..464b548 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
@@ -289,15 +289,33 @@ public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFu
break;
case COMPLEX:
+ String embeddableTypeName = null;
ComplexType complexType = null;
+ boolean exists = false;
+
if (returnType.isCollection() == false) {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(methodReturnType.getName());
+ embeddableTypeName = methodReturnType.getName();
} else {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(getReturnTypeName(method));
+ embeddableTypeName = getReturnTypeName(method);
}
- if (complexType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+
+ complexType = jpaEdmComplexTypeView.searchEdmComplexType(embeddableTypeName);
+
+ if (complexType == null) {// This could occure of non JPA Embeddable Types : Extension Scenario
+ List<ComplexType> complexTypeList = schemaView.getEdmSchema().getComplexTypes();
+ String[] complexTypeNameParts = embeddableTypeName.split("\\.");
+ String complexTypeName = complexTypeNameParts[complexTypeNameParts.length - 1];
+ for (ComplexType complexType1 : complexTypeList) {
+ if (complexType1.getName().equals(complexTypeName)) {
+ complexType = complexType1;
+ exists = true;
+ break;
+ }
+ }
+ if (exists == false) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
+ .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+ }
}
functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
break;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
index b34a71d..edd1c6e 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
@@ -264,10 +264,9 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
complexType.getName()));
properties.add(currentComplexProperty);
- List<String> nonKeyComplexTypes = schemaView.getNonKeyComplexTypeList();
- if (!nonKeyComplexTypes.contains(currentComplexProperty.getType().getName()))
+ if (!complexTypeView.isReferencedInKey(currentComplexProperty.getType().getName()))
{
- schemaView.addNonKeyComplexName(currentComplexProperty.getType().getName());
+ complexTypeView.setReferencedInKey(currentComplexProperty.getType().getName());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
index b9ded8b..c6f543a 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
@@ -35,6 +35,8 @@ import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
+import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmFunctionImportView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
@@ -45,24 +47,10 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
private JPAEdmComplexTypeView complexTypeView;
private JPAEdmEntityContainerView entityContainerView;
private JPAEdmAssociationView associationView = null;
- private List<String> nonKeyComplexList = null;
private HashMap<Class<?>, String[]> customOperations = null;
public JPAEdmSchema(final JPAEdmModelView modelView) {
super(modelView);
- if (nonKeyComplexList == null) {
- nonKeyComplexList = new ArrayList<String>();
- }
- }
-
- @Override
- public List<String> getNonKeyComplexTypeList() {
- return nonKeyComplexList;
- }
-
- @Override
- public void addNonKeyComplexName(final String complexTypeName) {
- nonKeyComplexList.add(complexTypeName);
}
@Override
@@ -127,10 +115,6 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
complexTypeView = new JPAEdmComplexType(JPAEdmSchema.this);
complexTypeView.getBuilder().build();
- if (getJPAEdmExtension() != null) {
- getJPAEdmExtension().extendWithOperation(JPAEdmSchema.this);
- }
-
entityContainerView = new JPAEdmEntityContainer(JPAEdmSchema.this);
entityContainerView.getBuilder().build();
schema.setEntityContainers(entityContainerView.getConsistentEdmEntityContainerList());
@@ -146,7 +130,8 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
List<ComplexType> complexTypes = complexTypeView.getConsistentEdmComplexTypes();
List<ComplexType> existingComplexTypes = new ArrayList<ComplexType>();
for (ComplexType complexType : complexTypes) {
- if (complexType != null && nonKeyComplexList.contains(complexType.getName())) {// null check for exclude
+ if (complexType != null && complexTypeView.isReferencedInKey(complexType.getName())) {// null check for
+ // exclude
existingComplexTypes.add(complexType);
}
}
@@ -190,6 +175,19 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
}
}
+ JPAEdmExtension edmExtension = getJPAEdmExtension();
+ if (edmExtension != null) {
+ edmExtension.extendJPAEdmSchema(JPAEdmSchema.this);
+ edmExtension.extendWithOperation(JPAEdmSchema.this);
+
+ JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(JPAEdmSchema.this);
+ functionImportView.getBuilder().build();
+ if (functionImportView.getConsistentFunctionImportList() != null) {
+ entityContainerView.getEdmEntityContainer().setFunctionImports(
+ functionImportView.getConsistentFunctionImportList());
+ }
+
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
index 633459f..a0bcbce 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
@@ -24,9 +24,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import javax.persistence.metamodel.Attribute;
@@ -178,8 +176,8 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
}
@Override
- public List<String> getNonKeyComplexTypeList() {
- return new ArrayList<String>();
+ public boolean isReferencedInKey(final String complexType) {
+ return false;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
index cf96ac7..1b15b75 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
@@ -323,14 +323,6 @@ public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAsso
}
@Override
- public List<String> getNonKeyComplexTypeList() {
- return null;
- }
-
- @Override
- public void addNonKeyComplexName(final String complexTypeName) {}
-
- @Override
public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
return null;
}
@@ -393,4 +385,16 @@ public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAsso
return false;
}
+ @Override
+ public boolean isReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java
new file mode 100644
index 0000000..9dde58f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.ref.extension;
+
+public class OrderValue {
+
+ private double amount;
+ private String currency;
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+
+ public String getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
index 0ff659b..72a8fbd 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
@@ -112,4 +112,22 @@ public class SalesOrderHeaderProcessor {
}
}
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX))
+ public OrderValue getOrderValue(
+ @EdmFunctionImportParameter(name = "SoId", facets = @EdmFacets(nullable = false)) final Long soID) {
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ + soID + "l");
+ @SuppressWarnings("unchecked")
+ List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
+ .getResultList();
+ OrderValue orderValue = new OrderValue();
+ if (!soList.isEmpty()) {
+
+ orderValue.setAmount(soList.get(0).getNetAmount());
+ orderValue.setCurrency(soList.get(0).getCurrencyCode());
+ }
+ return orderValue;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
index 6b82899..3dacd7e 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
@@ -18,15 +18,45 @@
******************************************************************************/
package org.apache.olingo.odata2.jpa.processor.ref.extension;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
public class SalesOrderProcessingExtension implements JPAEdmExtension {
@Override
- public void extendJPAEdmSchema(final JPAEdmSchemaView arg0) {
- // TODO Auto-generated method stub
+ public void extendJPAEdmSchema(final JPAEdmSchemaView view) {
+ Schema edmSchema = view.getEdmSchema();
+ edmSchema.getComplexTypes().add(getComplexType());
+ }
+ private ComplexType getComplexType() {
+ ComplexType complexType = new ComplexType();
+
+ List<Property> properties = new ArrayList<Property>();
+ SimpleProperty property = new SimpleProperty();
+
+ property.setName("Amount");
+ property.setType(EdmSimpleTypeKind.Double);
+ properties.add(property);
+
+ property = new SimpleProperty();
+ property.setName("Currency");
+ property.setType(EdmSimpleTypeKind.String);
+ properties.add(property);
+
+ complexType.setName("OrderValue");
+ complexType.setProperties(properties);
+
+ return complexType;
+
}
@Override