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 2015/08/19 10:53:43 UTC

olingo-odata4 git commit: [OLINGO-659] Improved DataProvider

Repository: olingo-odata4
Updated Branches:
  refs/heads/master a1731b7ef -> f2ca7119e


[OLINGO-659] Improved DataProvider


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

Branch: refs/heads/master
Commit: f2ca7119e144727103782d6e8bd8ce3150c887ac
Parents: a1731b7
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Aug 19 10:39:54 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Aug 19 10:53:33 2015 +0200

----------------------------------------------------------------------
 .../olingo/server/tecsvc/data/DataProvider.java | 28 +++++++++++---------
 1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f2ca7119/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index 95cdf9a..0dd530e 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -28,6 +28,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.Entity;
@@ -58,6 +60,10 @@ import org.apache.olingo.server.api.uri.UriResourceEntitySet;
 public class DataProvider {
 
   protected static final String MEDIA_PROPERTY_NAME = "$value";
+  private AtomicInteger KEY_INT_16 = new AtomicInteger(0);
+  private AtomicInteger KEY_INT_32 = new AtomicInteger(0);
+  private AtomicLong KEY_INT_64 = new AtomicLong(0);
+  private AtomicLong KEY_STRING = new AtomicLong(0);
 
   private Map<String, EntityCollection> data;
   private Edm edm;
@@ -163,42 +169,40 @@ public class DataProvider {
     
     return data.get(edmEntitySet.getName());
   }
-    
+
   private Map<String, Object> findFreeComposedKey(final List<Entity> entities, final EdmEntityType entityType)
       throws DataProviderException {
     // Weak key construction
     final HashMap<String, Object> keys = new HashMap<String, Object>();
     for (final String keyName : entityType.getKeyPredicateNames()) {
       final FullQualifiedName typeName = entityType.getProperty(keyName).getType().getFullQualifiedName();
-      Object newValue = null;
+      Object newValue;
       
       if (EdmPrimitiveTypeKind.Int16.getFullQualifiedName().equals(typeName)) {
-         newValue = Short.valueOf((short) 1);
+         newValue = (short) KEY_INT_16.incrementAndGet();
          
          while(!isFree(newValue, keyName, entities)) {
-           newValue = (short) (((Short) newValue) + 1);
+           newValue = (short) KEY_INT_16.incrementAndGet();
          }
       } else if (EdmPrimitiveTypeKind.Int32.getFullQualifiedName().equals(typeName)) {
-        newValue = Integer.valueOf((short) 1);
+        newValue = KEY_INT_32.incrementAndGet();
         
         while(!isFree(newValue, keyName, entities)) {
-          newValue = ((Integer) newValue) + 1;
+          newValue = KEY_INT_32.incrementAndGet();
         }
       } else if(EdmPrimitiveTypeKind.Int64.getFullQualifiedName().equals(typeName)) {
         // Integer keys
-        newValue = Long.valueOf(1);
+        newValue = KEY_INT_64.incrementAndGet();
 
         while (!isFree(newValue, keyName, entities)) {
-          newValue = (long) (((Long) newValue) + 1L);
+          newValue = KEY_INT_64.incrementAndGet();
         }
       } else if (EdmPrimitiveTypeKind.String.getFullQualifiedName().equals(typeName)) {
         // String keys
-        newValue = String.valueOf(1);
-        int i = 0;
+        newValue = String.valueOf(KEY_STRING.incrementAndGet());
 
         while (!isFree(newValue, keyName, entities)) {
-          newValue = String.valueOf(i);
-          i++;
+          newValue = String.valueOf(KEY_STRING.incrementAndGet());
         }
       } else {
         throw new DataProviderException("Key type not supported", HttpStatusCode.NOT_IMPLEMENTED);