/** * Creates a new {@link StoreAdapter} on top a the given {@code backend}. * * @param backend the backend * @param config the configuration of the store * * @return a new store */ @Nonnull private StoreAdapter createStore(Backend backend, ImmutableConfig config) { Store baseStore = StoreFactory.getInstance().createStore(backend, config); return new PersistentStoreAdapter(baseStore, this); }
/** * Copies all contents from this backend to the target using the direct copy. * * @param target the backend where to store the copied content */ private void defaultCopyTo(Backend target) { final DataCopier copier = ServiceProvider.getInstance() .load(DataCopier.class) .findFirst() .map(ServiceDefinition::get) .orElseThrow(() -> new UnsupportedOperationException("Unable to find any DataCopier implementation")); Store store = StoreFactory.getInstance().createStore(target, new BaseConfig<>().autoSave()); copier.copy(this, store); }
/** * Checks the setup of the default store, without any decorator ({@link NoopStore}). */ @Test void testNoStore() { ImmutableConfig config = new BaseConfig<>(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
@BeforeEach void setUp() { ImmutableConfig config = new BaseConfig<>().readOnly(); assertThat(config.isReadOnly()).isTrue(); store = StoreFactory.getInstance().createStore(mock(Backend.class), config); }
/** * Checks the setup of the {@link fr.inria.atlanmod.neoemf.data.store.listener.LoggingStoreListener}. */ @Test void testLogging() { ImmutableConfig config = new BaseConfig<>().log(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(ListeningStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
@Test void testNoStats() { ImmutableConfig config = new BaseConfig<>(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); // Do a call store.save(); assertThat(stats.methodInvocations()).isEmpty(); }
/** * Checks the setup of the {@link SizeCachingStore}. */ @Test void testSizeCaching() { ImmutableConfig config = new BaseConfig<>().cacheSizes(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(SizeCachingStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
/** * Checks the setup of the {@link FeatureCachingStore}. */ @Test void testFeatureCaching() { ImmutableConfig config = new BaseConfig<>().cacheFeatures(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(FeatureCachingStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
/** * Checks the setup of the {@link ContainerCachingStore}. */ @Test void testContainerCaching() { ImmutableConfig config = new BaseConfig<>().cacheContainers(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(ContainerCachingStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
/** * Checks the setup of the {@link ClassCachingStore}. */ @Test void testMetaclassCaching() { ImmutableConfig config = new BaseConfig<>().cacheMetaClasses(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(ClassCachingStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
Store baseStore = StoreFactory.getInstance().createStore(backend, config); return new TransientStoreAdapter(baseStore, resource);
/** * Checks the setup of the {@link AutoSavingStore} without chunk. */ @Test void testAutoSave() { ImmutableConfig config = new BaseConfig<>().autoSave(); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(AutoSavingStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
@BeforeEach void setUp() { stats = new StoreStats(); ImmutableConfig config = new BaseConfig<>().recordStats(stats); store = StoreFactory.getInstance().createStore(mock(Backend.class), config); }
/** * Checks the setup of the {@link RecordingStoreListener}. */ @Test void testStatsCaching() { ImmutableConfig config = new BaseConfig<>().recordStats(new StoreStats()); Store store = StoreFactory.getInstance().createStore(mock(Backend.class), config); assertThat(store).isInstanceOf(ListeningStore.class); store = getInnerStore(store); assertThat(store).isExactlyInstanceOf(NoopStore.class); }
/** * Creates a new {@link DataMapper} according to the specified options. * * @return a new {@link DataMapper} * * @see Context#config() * @see #defaultConfig() */ @Nonnull public DataMapper createMapper() { Backend backend = context.factory().createBackend(uri, defaultConfig()); return StoreFactory.getInstance().createStore(backend, defaultConfig()); } }
@BeforeEach void initStoreAdapter() { Store innerStore = StoreFactory.getInstance().createStore(new DefaultInMemoryBackend(), new BaseConfig<>()); store = new AbstractStoreAdapter(innerStore, null) { @Nonnull @Override protected Cache<Id, PersistentEObject> getCache() { return CacheBuilder.empty(); } }; store.updateInstanceOf(object); }
/** * 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); } } }