Search in sources :

Example 1 with MetaElementState

use of com.torodb.core.transaction.metainf.MetaElementState in project torodb by torodb.

the class SnapshotMerger method merge.

@SuppressWarnings("checkstyle:LineLength")
private void merge(MetaDatabase newDb, MetaDatabase oldDb, MutableMetaCollection newStructure, ImmutableMetaCollection oldStructure, ImmutableMetaCollection.Builder parentBuilder, MutableMetaDocPart changed) throws UnmergeableException {
    ImmutableMetaDocPart byRef = oldStructure.getMetaDocPartByTableRef(changed.getTableRef());
    ImmutableMetaDocPart byId = oldStructure.getMetaDocPartByIdentifier(changed.getIdentifier());
    if (byRef != byId) {
        throw createUnmergeableException(oldDb, oldStructure, changed, byRef, byId);
    }
    if (byRef == null && byId == null) {
        parentBuilder.put(changed.immutableCopy());
        return;
    }
    assert byRef != null;
    assert byId != null;
    ImmutableMetaDocPart.Builder childBuilder = new ImmutableMetaDocPart.Builder(byId);
    for (ImmutableMetaField addedMetaField : changed.getAddedMetaFields()) {
        merge(oldDb, newStructure, oldStructure, changed, byId, childBuilder, addedMetaField);
    }
    for (ImmutableMetaScalar addedMetaScalar : changed.getAddedMetaScalars()) {
        merge(oldDb, oldStructure, byId, childBuilder, addedMetaScalar);
    }
    for (Tuple2<ImmutableMetaIdentifiedDocPartIndex, MetaElementState> addedMetaDocPartIndex : changed.getModifiedMetaDocPartIndexes()) {
        merge(oldDb, newStructure, oldStructure, changed, byId, childBuilder, addedMetaDocPartIndex.v1(), addedMetaDocPartIndex.v2());
    }
    parentBuilder.put(childBuilder);
}
Also used : ImmutableMetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.ImmutableMetaIdentifiedDocPartIndex) ImmutableMetaDocPart(com.torodb.core.transaction.metainf.ImmutableMetaDocPart) MetaElementState(com.torodb.core.transaction.metainf.MetaElementState) ImmutableMetaField(com.torodb.core.transaction.metainf.ImmutableMetaField) ImmutableMetaScalar(com.torodb.core.transaction.metainf.ImmutableMetaScalar)

Aggregations

ImmutableMetaDocPart (com.torodb.core.transaction.metainf.ImmutableMetaDocPart)1 ImmutableMetaField (com.torodb.core.transaction.metainf.ImmutableMetaField)1 ImmutableMetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.ImmutableMetaIdentifiedDocPartIndex)1 ImmutableMetaScalar (com.torodb.core.transaction.metainf.ImmutableMetaScalar)1 MetaElementState (com.torodb.core.transaction.metainf.MetaElementState)1