private void persistIndexersMap(final SetMultimap<String, Indexer<?>> indexNameToIndexers, final MapDBTransaction tx) { checkNotNull(indexNameToIndexers, "Precondition violation - argument 'indexNameToIndexers' must not be NULL!"); checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); // Kryo doesn't like to convert the SetMultimap class directly, so we transform // it into a regular hash map with sets as values. Map<String, Set<Indexer<?>>> persistentMap = Maps.newHashMap(); // we need to transform the multimap into an internal representation using a normal hash map. for (Entry<String, Indexer<?>> entry : indexNameToIndexers.entries()) { Set<Indexer<?>> set = persistentMap.get(entry.getKey()); if (set == null) { set = Sets.newHashSet(); } set.add(entry.getValue()); persistentMap.put(entry.getKey(), set); } // first, serialize the indexers map to a binary format byte[] serialForm = this.serializeObject(persistentMap); // store the binary format in the database Var<byte[]> variable = this.getIndexersMapVariable(tx); variable.set(serialForm); }
@Override public void updateChronosVersionTo(final ChronosVersion chronosVersion) { checkNotNull(chronosVersion, "Precondition violation - argument 'chronosVersion' must not be NULL!"); try (MapDBTransaction tx = this.openTransaction()) { Var<String> variable = tx.atomicVar(VARIABLE_NAME__CHRONOS_BUILD_VERSION); variable.set(chronosVersion.toString()); tx.commit(); } }
@Override public NodeInfo createRootNodeIfNotExists(String name, String nodePseudoClass) { NodeInfo rootNodeInfo = rootNodeVar.get(); if (rootNodeInfo == null) { rootNodeInfo = createNode(null, name, nodePseudoClass, "", 0, new NodeGenericMetadata()); rootNodeVar.set(rootNodeInfo); } return rootNodeInfo; }
@Override public void persistIndexDirtyStates(final Map<String, Boolean> indices) { try (MapDBTransaction tx = this.getOwningDB().openTransaction()) { byte[] serializedForm = this.serializeObject(indices); this.getIndexDirtyMapVariable(tx).set(serializedForm); tx.commit(); } }
@Override protected void performWriteAheadLog(final WriteAheadLogToken token) { try (MapDBTransaction tx = this.getOwningDB().openTransaction()) { Var<byte[]> var = tx.atomicVar(this.getBranchName() + "." + WRITE_AHEAD_LOG_VAR_NAME); var.set(this.getOwningDB().getSerializationManager().serialize(token)); tx.commit(); } }
@Override public void set(T var) { this.var.set(var); }
/** {@inheritDoc} */ @Override public <T extends Serializable> void saveObject(String name, T serializableObject) { assertConnectionOpen(); DB storage = openStorage(StorageType.PRIMARY_STORAGE); Atomic.Var<T> atomicVar = storage.getAtomicVar(name); Map<String, Object> objRefs = preSerializer(serializableObject); atomicVar.set(serializableObject); storage.commit(); postSerializer(serializableObject, objRefs); }