@Test public void getAll() 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); Collection<TestObject> results = service.getAll(TestObject.class); assertEquals(3, results.size()); assertTrue(results.contains(to1)); assertTrue(results.contains(to2)); assertTrue(results.contains(to3)); }
public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } protected  StorageService(DB db);  StorageService(String name); }
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } 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> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new String(it.next().getKey()); String[] tokens = key.split("!"); String id = tokens[0]; String className = tokens[1]; if (!id.equals(prevId)) { if (clazz.getName().equals(className)) { ids.put(id, className); } prevId = id; } } for (Map.Entry<String, String> id : ids.entrySet()) { T o = (T) load(id.getKey(), Class.forName(id.getValue())); c.add(o); } } return c; } 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);  }