DataStore implements Closeable { @SuppressWarnings("unchecked") public <Model> void inject(@NotNull Model model) { try { for (Class type = model.getClass(); type != null && type != Object.class && type != Enum.class; type = type.getSuperclass()) { for (Field field : type.getDeclaredFields()) { injectField(model, field); } } } catch (IllegalAccessException e) { throw new AssertionError(e); } } DataStore(@NotNull final Chronicle chronicle, @NotNull ModelMode mode); @SuppressWarnings("unchecked") void inject(@NotNull Model model); void injectField(Model model, @NotNull Field field); void start(); void start(final long lastEvent); void startAtEnd(); void add(String name, Wrapper wrapper); @NotNull Excerpt startExcerpt(int capacity, @NotNull String name); boolean enumeratedClass(@NotNull Class eClass); void checkWritable(); long events(); void close(); boolean nextEvent();  }
@Test public void testInject() throws IOException { String name = TMP + "/inject"; ChronicleTools.deleteOnExit(name); for (int i = 0; i < 10; i++) { ExampleDataModel model = new ExampleDataModel(); Chronicle chronicle = new IndexedChronicle(name); DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER); dataStore.inject(model); final AtomicInteger map2Count = new AtomicInteger(); model.map2.addListener(new AbstractMapListener<Date, ExampleDataModel.MyType>() { @Override public void update(Date key, ExampleDataModel.MyType oldValue, ExampleDataModel.MyType newValue) { map2Count.incrementAndGet(); } }); final AtomicInteger list2Count = new AtomicInteger(); model.list2.addListener(new AbstractCollectionListener<ExampleDataModel.MyType>() { @Override public void add(ExampleDataModel.MyType element) { list2Count.incrementAndGet(); } }); final AtomicInteger set2Count = new AtomicInteger(); model.set2.addListener(new AbstractCollectionListener<ExampleDataModel.MyType>() { @Override public void add(ExampleDataModel.MyType element) { set2Count.incrementAndGet(); } }); dataStore.start(); model.map.put(new Date(i * 1000), new ExampleDataModel.MyType()); model.map2.put(new Date(i * 1000), new ExampleDataModel.MyType()); model.list.add(new ExampleDataModel.MyType()); model.list2.add(new ExampleDataModel.MyType()); model.set.add(new ExampleDataModel.MyType()); model.set2.add(new ExampleDataModel.MyType()); assertEquals(i + 1, model.map.size()); assertEquals(i + 1, map2Count.get()); assertEquals(i + 1, model.list.size()); assertEquals(i + 1, list2Count.get()); assertEquals(i + 1, model.set.size()); assertEquals(i + 1, set2Count.get()); MyAnnotation annotation = model.map2.getAnnotation(MyAnnotation.class); assertNotNull(annotation); assertEquals("My text", annotation.value()); chronicle.close(); } }