olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject git commit: Implementation for 'create/update/delete'
Date Wed, 13 Nov 2013 07:52:55 GMT
Updated Branches:
  refs/heads/PocEdmAnnotationsExtension 0169bfc38 -> d641fd163


Implementation for 'create/update/delete'


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/d641fd16
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d641fd16
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d641fd16

Branch: refs/heads/PocEdmAnnotationsExtension
Commit: d641fd1632b7c226a89413d64f417fa2d80ef2b7
Parents: 0169bfc
Author: Michael Bolz <mibo@apache.org>
Authored: Wed Nov 13 08:52:39 2013 +0100
Committer: Michael Bolz <mibo@apache.org>
Committed: Wed Nov 13 08:52:39 2013 +0100

----------------------------------------------------------------------
 .../annotation/ds/AnnotationInMemoryDs.java     | 43 ++++++++++++++++----
 1 file changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d641fd16/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
index 0a467fa..a07765d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
@@ -71,9 +71,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
   public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
           ODataNotFoundException, EdmException, ODataApplicationException {
 
-    final String name = entitySet.getEntityType().getName();
-
-    DataStore<Object> holder = dataStores.get(name);
+    DataStore<Object> holder = getDataStore(entitySet);
     if (holder != null) {
       return new ArrayList(holder.read());
     }
@@ -84,9 +82,8 @@ public class AnnotationInMemoryDs implements ListsDataSource {
   @Override
   public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
           throws ODataNotFoundException, EdmException, ODataApplicationException {
-    final String name = entitySet.getEntityType().getName();
 
-    DataStore<Object> store = dataStores.get(name);
+    DataStore<Object> store = getDataStore(entitySet);
     if (store != null) {
       Object keyInstance = store.createInstance();
       ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
@@ -166,6 +163,12 @@ public class AnnotationInMemoryDs implements ListsDataSource {
   @Override
   public Object newDataObject(EdmEntitySet entitySet)
           throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+    DataStore<Object> dataStore = getDataStore(entitySet);
+    if (dataStore != null) {
+      return dataStore.createInstance();
+    }
+
     throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
   }
 
@@ -179,15 +182,18 @@ public class AnnotationInMemoryDs implements ListsDataSource {
   @Override
   public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
           throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException
{
-    throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
-
+    DataStore<Object> dataStore = getDataStore(entitySet);
+    Object keyInstance = dataStore.createInstance();
+    ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
+    dataStore.delete(keyInstance);
   }
 
   @Override
   public void createData(EdmEntitySet entitySet, Object data)
           throws ODataNotImplementedException, EdmException, ODataApplicationException {
-    throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
 
+    DataStore<Object> dataStore = getDataStore(entitySet);
+    dataStore.create(data);
   }
 
   @Override
@@ -195,7 +201,6 @@ public class AnnotationInMemoryDs implements ListsDataSource {
           Map<String, Object> targetKeys)
           throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException
{
     throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
-
   }
 
   @Override
@@ -205,6 +210,26 @@ public class AnnotationInMemoryDs implements ListsDataSource {
     throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
   }
 
+
+  /**
+   * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
+   * ODataRuntimeException is thrown.
+   * Never returns NULL.
+   * 
+   * @param entitySet for which the corresponding DataStore is returned
+   * @return a DataStore object 
+   * @throws EdmException 
+   * @throws  ODataRuntimeException if no DataStore is found
+   */
+  private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException
{
+    final String name = entitySet.getEntityType().getName();
+    DataStore<Object> dataStore = dataStores.get(name);
+    if(dataStore == null) {
+      throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet +
"'.");
+    }
+    return dataStore;
+  }
+
   private Object getValue(Field field, Object instance) {
     try {
       boolean access = field.isAccessible();


Mime
View raw message