@Nonnull @Override public Backend backend() { return next().backend(); }
@Override public void copyTo(DataMapper target) { checkNotNull(target, "target"); if (isDistributed()) { Log.warn("Copy of a distributed back-end may lead to unexpected errors"); } Backend targetBackend; if (target instanceof Backend) { targetBackend = (Backend) target; } else if (target instanceof Store) { final Store targetStore = (Store) target; targetBackend = targetStore.backend(); } else { throw new IllegalStateException(String.format("Unable to copy a DataMapper of type %s", target.getClass())); } copyTo(targetBackend); }
@Override public void save(ImmutableConfig config) { if (!isLoaded || !eStore.store().backend().isPersistent()) { mergeStore(config); Optional.ofNullable(setLoaded(true)).ifPresent(this::eNotify); } eStore.save(); logState("saved"); }
/** * Defines the new store of this object, and copies the content from the existing store if necessary. * * @param newStore the store of this object * * @see #resource() */ private void refreshStore(StoreAdapter newStore) { checkNotNull(newStore, "newStore"); if (lazyStore.isLoaded()) { StoreAdapter currentStore = lazyStore.get(); if (!Objects.equals(currentStore.store().backend(), newStore.store().backend())) { // Copy if the resource is not being unloaded if (nonNull(resource)) { new ContentsCopier(this).copy(currentStore, newStore); } // If the resource is persistent, it will close its store if (!PersistentResource.isPersistent(currentStore.resource())) { currentStore.close(); } } } lazyStore.update(newStore); }
/** * Check the creation of chaining between the default {@link Store}s and a {@link InMemoryBackend}. */ @Test public void testCreateTransientStore() throws IOException { try (Backend backend = new InMemoryBackendFactory().createBackend(new InMemoryUriFactory().createLocalUri(currentTempFile()), new InMemoryConfig())) { try (Store store = StoreFactory.getInstance().createStore(backend, context().config())) { assertThat(store).isInstanceOf(NoopStore.class); assertThat(store.backend()).isSameAs(backend); } } }
/** * Check the creation of chaining between the default {@link Store}s and a {@link Backend}. */ @Test public void testCreatePersistentStore() throws IOException { try (Backend backend = context().factory().createBackend(context().createUri(currentTempFile()), context().config())) { try (Store store = StoreFactory.getInstance().createStore(backend, context().config())) { assertThat(store).isInstanceOf(NoopStore.class); assertThat(store.backend()).isSameAs(backend); } } }