public T reload(String resourceName) { return reloadAt(resourcePath(resourceName)); }
public T reloadQuietly(String resourceName) { return reloadQuietlyAt(resourcePath(resourceName)); }
public void delete(String resName) throws IOException { Preconditions.checkArgument(resName != null); String path = resourcePath(resName); logger.debug("Deleting {} at {}", entityType.getSimpleName(), path); store.deleteResource(path); cache.remove(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); }
public T reloadAt(String path) { try { T entity = store.getResource(path, serializer); if (entity == null) { logger.warn("No " + entityType.getSimpleName() + " found at " + path + ", returning null"); cache.removeLocal(resourceName(path)); return null; } // mark cached object entity.setCachedAndShared(true); entity = initEntityAfterReload(entity, resourceName(path)); if (path.equals(resourcePath(entity.resourceName())) == false) throw new IllegalStateException("The entity " + entity + " read from " + path + " will save to a different path " + resourcePath(entity.resourceName())); cache.putLocal(entity.resourceName(), entity); return entity; } catch (Exception e) { throw new IllegalStateException("Error loading " + entityType.getSimpleName() + " at " + path, e); } }
public T reload(String resourceName) { return reloadAt(resourcePath(resourceName)); }
public T reloadQuietly(String resourceName) { return reloadQuietlyAt(resourcePath(resourceName)); }
public void delete(String resName) throws IOException { Preconditions.checkArgument(resName != null); String path = resourcePath(resName); logger.debug("Deleting {} at {}", entityType.getSimpleName(), path); store.deleteResource(path); cache.remove(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); }
public T reloadAt(String path) { try { T entity = store.getResource(path, serializer); if (entity == null) { logger.warn("No " + entityType.getSimpleName() + " found at " + path + ", returning null"); cache.removeLocal(resourceName(path)); return null; } // mark cached object entity.setCachedAndShared(true); entity = initEntityAfterReload(entity, resourceName(path)); if (path.equals(resourcePath(entity.resourceName())) == false) throw new IllegalStateException("The entity " + entity + " read from " + path + " will save to a different path " + resourcePath(entity.resourceName())); cache.putLocal(entity.resourceName(), entity); return entity; } catch (Exception e) { throw new IllegalStateException("Error loading " + entityType.getSimpleName() + " at " + path, e); } }