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 2013/12/06 17:52:52 UTC
[10/50] [abbrv] git commit: Implementation for 'create/update/delete'
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/f6b68c93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f6b68c93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f6b68c93
Branch: refs/heads/ODataServlet
Commit: f6b68c935cd5779372e8b787a4b66fe1ffa3f071
Parents: 8aceb95
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Nov 13 08:52:39 2013 +0100
Committer: Tamara Boehm <ta...@sap.com>
Committed: Fri Dec 6 17:49:22 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/f6b68c93/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();