package oasis.jongo;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import oasis.model.annotations.Id;

public class OasisIdHelper {
  private static final Map<Class<?>, Field> oasisFieldCache = new HashMap<>();

  public static void updateOasisIdField(Object target) {
    Field idField = OasisIdHelper.findOasisIdField(target.getClass());
    if (idField != null) {
      if (!idField.getType().equals(String.class)) {
        throw new IllegalArgumentException("Unable to set Oasis Id on class: " + target.getClass() + " (id field is not a String)");
      }

      idField.setAccessible(true);
      try {
        if (idField.get(target) == null) {
          idField.set(target, UUID.randomUUID().toString());
        }
      } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Unable to set Oasis Id on class: " + target.getClass() + " (id field is not accessible)");
      }
    }
  }

  static Field findOasisIdField(Class<?> clazz) {
    if (oasisFieldCache.containsKey(clazz)) {
      return oasisFieldCache.get(clazz);
    }

    while (!Object.class.equals(clazz)) {
      for (Field f : clazz.getDeclaredFields()) {
        if (f.isAnnotationPresent(Id.class)) {
          oasisFieldCache.put(clazz, f);
          return f;
        }
      }
      clazz = clazz.getSuperclass();
    }
    return null;
  }
}

@@ -64,20 +64,16 @@
 va.util.
-Hash
 Map;%0Aimp
@@ -78,35 +78,36 @@
 mport java.util.
-Map
+UUID
 ;%0Aimport java.ut
@@ -109,20 +109,44 @@
 va.util.
-UUID
+concurrent.ConcurrentHashMap
 ;%0A%0Aimpor
@@ -271,16 +271,26 @@
 e = new 
+Concurrent
 HashMap%3C

Use a ConcurrentHashMap in OasisIdHelper