@Test public void delete() throws Exception { TestObject to1 = new TestObject("1", "456"); TestObject to2 = new TestObject("2", "abc"); TestObject to3 = new TestObject("3", "xyz"); service.save(to1); service.save(to2); service.save(to3); service.delete("1", TestObject.class); service.delete("3", TestObject.class); Collection<TestObject> results = service.getAll(TestObject.class); assertEquals(1, results.size()); assertFalse(results.contains(to1)); assertTrue(results.contains(to2)); assertFalse(results.contains(to3)); }
public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } protected  StorageService(DB db);  StorageService(String name); }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } protected  StorageService(DB db);  StorageService(String name); void close(); void delete(String id, Class<T> clazz); byte[] get(byte[] key); Collection<T> getAll(Class<T> clazz); T load(String id, Class<T> clazz); void put(byte[] key, byte[] value); void save(Object entity); }
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); db.delete(bytes(key + "!" + field.getName())); } } protected  StorageService(DB db);  StorageService(String name); void close(); void delete(String id, Class<T> clazz); byte[] get(byte[] key); Collection<T> getAll(Class<T> clazz); T load(String id, Class<T> clazz); void put(byte[] key, byte[] value); void save(Object entity);  }