@Test public void testSameDataOnlySavedOnce() throws Exception { store.start(); store.save(ImmutableMap.of("clustered", "1.3")); EntityVersion persistedVersion; try (ODatabaseDocumentTx db = database.getInstance().connect()) { ClusteredModelVersions versions = entityAdapter.get(db); persistedVersion = versions.getEntityMetadata().getVersion(); } store.stop(); store.start(); store.save(ImmutableMap.of("clustered", "1.3")); try (ODatabaseDocumentTx db = database.getInstance().connect()) { ClusteredModelVersions versions = entityAdapter.get(db); assertThat(versions.getEntityMetadata().getVersion(), is(persistedVersion)); } }
@Guarded(by = STARTED) public synchronized void save(Map<String, String> modelVersions) { checkNotNull(modelVersions); save(modelVersions, upgradeManager.getLocalModels(), localModelVersions::setProperty); save(modelVersions, upgradeManager.getClusteredModels(), clusteredModelVersions::put); try { localModelVersions.store(); if (clusteredModelVersions.isDirty()) { inTxRetry(databaseInstance).run(db -> entityAdapter.set(db, clusteredModelVersions)); clusteredModelVersions.clearDirty(); } } catch (IOException e) { throw new RuntimeException("Could not save upgraded model versions: " + modelVersions, e); } }
ModelVersionStore extends StateGuardLifecycleSupport { @Guarded(by = STARTED) public synchronized void save(Map<String, String> modelVersions) { checkNotNull(modelVersions); save(modelVersions, upgradeManager.getLocalModels(), localModelVersions::setProperty); save(modelVersions, upgradeManager.getClusteredModels(), clusteredModelVersions::put); try { localModelVersions.store(); if (clusteredModelVersions.isDirty()) { inTxRetry(databaseInstance).run(db -> entityAdapter.set(db, clusteredModelVersions)); clusteredModelVersions.clearDirty(); } } catch (IOException e) { throw new RuntimeException("Could not save upgraded model versions: " + modelVersions, e); } } }
ModelVersionStore extends StateGuardLifecycleSupport { @Guarded(by = STARTED) public synchronized void save(Map<String, String> modelVersions) { checkNotNull(modelVersions); save(modelVersions, upgradeManager.getLocalModels(), localModelVersions::setProperty); save(modelVersions, upgradeManager.getClusteredModels(), clusteredModelVersions::put); try { localModelVersions.store(); if (clusteredModelVersions.isDirty()) { inTxRetry(databaseInstance).run(db -> entityAdapter.set(db, clusteredModelVersions)); clusteredModelVersions.clearDirty(); } } catch (IOException e) { throw new RuntimeException("Could not save upgraded model versions: " + modelVersions, e); } } @Inject  ModelVersionStore(final UpgradeManager upgradeManager,
                           @Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                           final ClusteredModelVersionsEntityAdapter entityAdapter,
                           final ApplicationDirectories applicationDirectories); }
ModelVersionStore extends StateGuardLifecycleSupport { @Guarded(by = STARTED) public synchronized void save(Map<String, String> modelVersions) { checkNotNull(modelVersions); save(modelVersions, upgradeManager.getLocalModels(), localModelVersions::setProperty); save(modelVersions, upgradeManager.getClusteredModels(), clusteredModelVersions::put); try { localModelVersions.store(); if (clusteredModelVersions.isDirty()) { inTxRetry(databaseInstance).run(db -> entityAdapter.set(db, clusteredModelVersions)); clusteredModelVersions.clearDirty(); } } catch (IOException e) { throw new RuntimeException("Could not save upgraded model versions: " + modelVersions, e); } } @Inject  ModelVersionStore(final UpgradeManager upgradeManager,
                           @Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                           final ClusteredModelVersionsEntityAdapter entityAdapter,
                           final ApplicationDirectories applicationDirectories); @Guarded(by = STARTED) boolean isNewInstance(); @Guarded(by = STARTED) synchronized Map<String, String> load(); @Guarded(by = STARTED) synchronized void save(Map<String, String> modelVersions); }
ModelVersionStore extends StateGuardLifecycleSupport { @Guarded(by = STARTED) public synchronized void save(Map<String, String> modelVersions) { checkNotNull(modelVersions); save(modelVersions, upgradeManager.getLocalModels(), localModelVersions::setProperty); save(modelVersions, upgradeManager.getClusteredModels(), clusteredModelVersions::put); try { localModelVersions.store(); if (clusteredModelVersions.isDirty()) { inTxRetry(databaseInstance).run(db -> entityAdapter.set(db, clusteredModelVersions)); clusteredModelVersions.clearDirty(); } } catch (IOException e) { throw new RuntimeException("Could not save upgraded model versions: " + modelVersions, e); } } @Inject  ModelVersionStore(final UpgradeManager upgradeManager,
                           @Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                           final ClusteredModelVersionsEntityAdapter entityAdapter,
                           final ApplicationDirectories applicationDirectories); @Guarded(by = STARTED) boolean isNewInstance(); @Guarded(by = STARTED) synchronized Map<String, String> load(); @Guarded(by = STARTED) synchronized void save(Map<String, String> modelVersions);  }