use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method remove.
@Override
public XdmNodeWriteTrx remove() throws SirixException {
checkAccessAndCommit();
acquireLock();
try {
if (getCurrentNode().getKind() == Kind.DOCUMENT) {
throw new SirixUsageException("Document root can not be removed.");
} else if (getCurrentNode() instanceof StructNode) {
final StructNode node = (StructNode) mNodeReader.getCurrentNode();
// Remove subtree.
for (final Axis axis = new PostOrderAxis(this); axis.hasNext(); ) {
axis.next();
// Remove name.
removeName();
// Remove namespaces and attributes.
removeNonStructural();
// Remove text value.
removeValue();
// Then remove node.
getPageTransaction().removeEntry(getCurrentNode().getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
// Adapt hashes and neighbour nodes as well as the name from the
// NamePage mapping if it's not a text node.
mNodeReader.setCurrentNode(node);
adaptHashesWithRemove();
adaptForRemove(node, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
// Remove the name of subtree-root.
if (node.getKind() == Kind.ELEMENT) {
removeName();
}
// of text merges.
if (mNodeReader.hasRightSibling() && moveTo(node.getRightSiblingKey()).hasMoved()) {
} else if (node.hasLeftSibling()) {
moveTo(node.getLeftSiblingKey());
} else {
moveTo(node.getParentKey());
}
} else if (getCurrentNode().getKind() == Kind.ATTRIBUTE) {
final ImmutableNode node = mNodeReader.getCurrentNode();
final ElementNode parent = (ElementNode) getPageTransaction().prepareEntryForModification(node.getParentKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
parent.removeAttribute(node.getNodeKey());
adaptHashesWithRemove();
getPageTransaction().removeEntry(node.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
removeName();
mIndexController.notifyChange(ChangeType.DELETE, getNode(), parent.getPathNodeKey());
moveToParent();
} else if (getCurrentNode().getKind() == Kind.NAMESPACE) {
final ImmutableNode node = mNodeReader.getCurrentNode();
final ElementNode parent = (ElementNode) getPageTransaction().prepareEntryForModification(node.getParentKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
parent.removeNamespace(node.getNodeKey());
adaptHashesWithRemove();
getPageTransaction().removeEntry(node.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
removeName();
moveToParent();
}
return this;
} finally {
unLock();
}
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class PathSummaryReader method moveTo.
@Override
public Move<? extends PathSummaryReader> moveTo(final long nodeKey) {
assertNotClosed();
// Remember old node and fetch new one.
final StructNode oldNode = mCurrentNode;
Optional<? extends StructNode> newNode;
try {
// Immediately return node from item list if node key negative.
@SuppressWarnings("unchecked") final Optional<? extends StructNode> node = (Optional<? extends StructNode>) mPageReadTrx.getRecord(nodeKey, PageKind.PATHSUMMARYPAGE, 0);
newNode = node;
} catch (final SirixIOException e) {
newNode = Optional.empty();
}
if (newNode.isPresent()) {
mCurrentNode = newNode.get();
return Move.moved(this);
} else {
mCurrentNode = oldNode;
return Move.notMoved();
}
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method getRightSiblingDeweyID.
@Override
public Optional<SirixDeweyID> getRightSiblingDeweyID() {
if (mResourceManager.getResourceConfig().mDeweyIDsStored) {
final StructNode node = getStructuralNode();
final long nodeKey = node.getNodeKey();
Optional<SirixDeweyID> deweyID = Optional.<SirixDeweyID>empty();
if (node.hasRightSibling()) {
// Right sibling node.
deweyID = moveTo(node.getRightSiblingKey()).get().getDeweyID();
}
moveTo(nodeKey);
return deweyID;
}
return Optional.<SirixDeweyID>empty();
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method getLastChildKind.
@Override
public Kind getLastChildKind() {
assertNotClosed();
if (mCurrentNode instanceof StructNode && hasLastChild()) {
final long nodeKey = mCurrentNode.getNodeKey();
moveToLastChild();
final Kind lastChildKind = mCurrentNode.getKind();
moveTo(nodeKey);
return lastChildKind;
}
return Kind.UNKNOWN;
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method moveToPrevious.
@Override
public Move<? extends XdmNodeReadTrx> moveToPrevious() {
assertNotClosed();
final StructNode node = getStructuralNode();
if (node.hasLeftSibling()) {
// Left sibling node.
Move<? extends XdmNodeReadTrx> leftSiblMove = moveTo(node.getLeftSiblingKey());
// Now move down to rightmost descendant node if it has one.
while (leftSiblMove.get().hasFirstChild()) {
leftSiblMove = leftSiblMove.get().moveToLastChild();
}
return leftSiblMove;
}
// Parent node.
return moveTo(node.getParentKey());
}
Aggregations