use of com.torodb.core.transaction.metainf.ImmutableMetaIdentifiedDocPartIndex 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);
}
use of com.torodb.core.transaction.metainf.ImmutableMetaIdentifiedDocPartIndex in project torodb by torodb.
the class SnapshotMerger method merge.
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
private void merge(MetaDatabase oldDb, MutableMetaCollection newCol, ImmutableMetaCollection oldCol, MetaDocPart newStructure, ImmutableMetaDocPart oldStructure, ImmutableMetaDocPart.Builder parentBuilder, ImmutableMetaIdentifiedDocPartIndex changed, MetaElementState newState) throws UnmergeableException {
ImmutableMetaIdentifiedDocPartIndex byId = oldStructure.getMetaDocPartIndexByIdentifier(changed.getIdentifier());
ImmutableMetaIdentifiedDocPartIndex bySameColumns = oldStructure.streamIndexes().filter(oldDocPartIndex -> oldDocPartIndex.hasSameColumns(changed)).findAny().orElse(null);
switch(newState) {
default:
case NOT_CHANGED:
case NOT_EXISTENT:
throw new AssertionError("A modification was expected, but the new state is " + newState);
case ADDED:
case MODIFIED:
{
Optional<? extends MetaIndex> anyRelatedIndex = newCol.getAnyRelatedIndex(oldCol, newStructure, changed);
if (!anyRelatedIndex.isPresent()) {
throw createUnmergeableExceptionForOrphan(oldDb, oldCol, oldStructure, changed);
}
if (byId == null) {
parentBuilder.put(changed);
return;
}
assert byId != null;
ImmutableMetaIdentifiedDocPartIndex.Builder childBuilder = new ImmutableMetaIdentifiedDocPartIndex.Builder(byId);
Iterator<ImmutableMetaDocPartIndexColumn> indexColumnIterator = changed.iteratorColumns();
while (indexColumnIterator.hasNext()) {
ImmutableMetaDocPartIndexColumn indexColumn = indexColumnIterator.next();
merge(oldDb, oldCol, oldStructure, byId, childBuilder, indexColumn);
}
parentBuilder.put(childBuilder);
break;
}
case REMOVED:
{
Optional<? extends MetaIndex> oldMissedIndex = newCol.getAnyMissedIndex(oldCol, changed);
if (oldMissedIndex.isPresent()) {
throw createUnmergeableExceptionForMissing(oldDb, oldCol, oldStructure, changed, oldMissedIndex.get());
}
if (byId == null || bySameColumns == null) {
/*
* it has been removed on another transaction or created and removed on the current one.
* No change must be done
*/
return;
}
assert byId != null;
assert bySameColumns != null;
/*
* In this case, we can delegate on the backend transaction check. If it thinks everything
* is fine, we can remove the element. If it thinks there is an error, then we have to
* rollback the transaction.
*/
parentBuilder.remove(byId);
}
}
}
Aggregations