@Test public void testSave() throws IOException { CachedCrudAssist<TestEntity> crudAssist = new CachedCrudAssist<TestEntity>(getStore() , "/test" , TestEntity.class , new CaseInsensitiveStringCache<TestEntity>(getTestConfig(), "test")) { @Override protected TestEntity initEntityAfterReload(TestEntity entity, String resourceName) { return entity; } }; TestEntity entity = new TestEntity(); Assert.assertNull(entity.getUuid()); crudAssist.save(entity); Assert.assertNotNull(entity.getUuid()); }
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); cache.put(resName, entity); return reload(resName); }
CachedCrudAssist { 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); cache.put(resName, entity); return reload(resName); } }
CachedCrudAssist { 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); cache.put(resName, entity); return reload(resName); } CachedCrudAssist(ResourceStore store, String resourceRootPath, Class<T> entityType,
            SingleValueCache<String, T> cache);  CachedCrudAssist(ResourceStore store, String resourceRootPath, String resourcePathSuffix,
            Class<T> entityType, SingleValueCache<String, T> cache, boolean compact); }
CachedCrudAssist { 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); cache.put(resName, entity); return reload(resName); } CachedCrudAssist(ResourceStore store, String resourceRootPath, Class<T> entityType,
            SingleValueCache<String, T> cache);  CachedCrudAssist(ResourceStore store, String resourceRootPath, String resourcePathSuffix,
            Class<T> entityType, SingleValueCache<String, T> cache, boolean compact); Serializer<DataModelDesc> getSerializer(); void setCheckCopyOnWrite(boolean check); T copyForWrite(T entity); void reloadAll(); T reload(String resourceName); T reloadQuietly(String resourceName); List<String> getLoadFailedEntities(); T reloadAt(String path); T save(T entity); void delete(T entity); void delete(String resName); }
CachedCrudAssist { 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); cache.put(resName, entity); return reload(resName); } CachedCrudAssist(ResourceStore store, String resourceRootPath, Class<T> entityType,
            SingleValueCache<String, T> cache);  CachedCrudAssist(ResourceStore store, String resourceRootPath, String resourcePathSuffix,
            Class<T> entityType, SingleValueCache<String, T> cache, boolean compact); Serializer<DataModelDesc> getSerializer(); void setCheckCopyOnWrite(boolean check); T copyForWrite(T entity); void reloadAll(); T reload(String resourceName); T reloadQuietly(String resourceName); List<String> getLoadFailedEntities(); T reloadAt(String path); T save(T entity); void delete(T entity); void delete(String resName);  }