public T save(T entity) throws IOException { Preconditions.checkArgument(entity != null); completeUuidIfNeeded(entity); Preconditions.checkArgument(entityType.isInstance(entity)); String resName = entity.resourceName(); Preconditions.checkArgument(resName != null && resName.length() > 0); if (checkCopyOnWrite) { if (entity.isCachedAndShared() || cache.get(resName) == entity) { throw new IllegalStateException("Copy-on-write violation! The updating entity " + entity + " is a shared object in " + entityType.getSimpleName() + " cache, which should not be."); } } String path = resourcePath(resName); logger.debug("Saving {} at {}", entityType.getSimpleName(), path); store.checkAndPutResource(path, entity, serializer); // just to trigger the event broadcast, the entity won't stay in cache cache.put(resName, entity); // keep the pass-in entity out of cache, the caller may use it for further update // return a reloaded new object return reload(resName); }
public T save(T entity) throws IOException { Preconditions.checkArgument(entity != null); completeUuidIfNeeded(entity); Preconditions.checkArgument(entityType.isInstance(entity)); String resName = entity.resourceName(); Preconditions.checkArgument(resName != null && resName.length() > 0); if (checkCopyOnWrite) { if (entity.isCachedAndShared() || cache.get(resName) == entity) { throw new IllegalStateException("Copy-on-write violation! The updating entity " + entity + " is a shared object in " + entityType.getSimpleName() + " cache, which should not be."); } } String path = resourcePath(resName); logger.debug("Saving {} at {}", entityType.getSimpleName(), path); store.checkAndPutResource(path, entity, serializer); // just to trigger the event broadcast, the entity won't stay in cache cache.put(resName, entity); // keep the pass-in entity out of cache, the caller may use it for further update // return a reloaded new object return reload(resName); }