use of com.torodb.core.transaction.metainf.ImmutableMetaDocPartIndexColumn in project torodb by torodb.
the class SnapshotMerger method merge.
private void merge(MetaDatabase db, MetaCollection col, MetaDocPart docPart, ImmutableMetaIdentifiedDocPartIndex oldStructure, ImmutableMetaIdentifiedDocPartIndex.Builder parentBuilder, ImmutableMetaDocPartIndexColumn changed) throws UnmergeableException {
ImmutableMetaDocPartIndexColumn byIdentifier = oldStructure.getMetaDocPartIndexColumnByIdentifier(changed.getIdentifier());
ImmutableMetaDocPartIndexColumn byPosition = oldStructure.getMetaDocPartIndexColumnByPosition(changed.getPosition());
if (byIdentifier != byPosition) {
throw createUnmergeableException(db, col, docPart, oldStructure, changed, byIdentifier, byPosition);
}
if (byIdentifier == null && byPosition == null) {
parentBuilder.add(changed);
}
}
use of com.torodb.core.transaction.metainf.ImmutableMetaDocPartIndexColumn 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