use of org.sirix.api.visitor.VisitResult in project sirix by sirixdb.
the class DeleteFMSEVisitor method visit.
@Override
public VisitResult visit(final ImmutableElement node) {
final Long partner = mMatching.partner(node.getNodeKey());
if (partner == null) {
VisitResult retVal = delete(node);
if (node.getNodeKey() == mStartKey) {
retVal = VisitResultType.TERMINATE;
}
return retVal;
} else {
mWtx.moveTo(node.getNodeKey());
final long nodeKey = node.getNodeKey();
final List<Long> keysToDelete = new ArrayList<>(mWtx.getAttributeCount() + mWtx.getNamespaceCount());
for (int i = 0, attCount = mWtx.getAttributeCount(); i < attCount; i++) {
mWtx.moveToAttribute(i);
final long attNodeKey = mWtx.getNodeKey();
if (mMatching.partner(attNodeKey) == null) {
keysToDelete.add(attNodeKey);
}
mWtx.moveTo(nodeKey);
}
for (int i = 0, nspCount = mWtx.getNamespaceCount(); i < nspCount; i++) {
mWtx.moveToNamespace(i);
final long namespNodeKey = mWtx.getNodeKey();
if (mMatching.partner(namespNodeKey) == null) {
keysToDelete.add(namespNodeKey);
}
mWtx.moveTo(nodeKey);
}
for (final long keyToDelete : keysToDelete) {
mWtx.moveTo(keyToDelete);
try {
mWtx.remove();
} catch (final SirixException e) {
LOGWRAPPER.error(e.getMessage(), e);
}
}
mWtx.moveTo(nodeKey);
return VisitResultType.CONTINUE;
}
}
use of org.sirix.api.visitor.VisitResult in project sirix by sirixdb.
the class VisitorDescendantAxis method nextKey.
@Override
protected long nextKey() {
// Visitor.
Optional<VisitResult> result = Optional.absent();
if (mVisitor.isPresent()) {
result = Optional.fromNullable(getTrx().acceptVisitor(mVisitor.get()));
}
// return false.
if (result.isPresent() && result.get() == VisitResultType.TERMINATE) {
return Fixed.NULL_NODE_KEY.getStandardProperty();
}
final XdmNodeReadTrx rtx = getTrx();
// Determines if first call to hasNext().
if (mFirst) {
mFirst = false;
return isSelfIncluded() == IncludeSelf.YES ? rtx.getNodeKey() : rtx.getFirstChildKey();
}
// If visitor is present and the the righ sibling stack must be adapted.
if (result.isPresent() && result.get() == LocalVisitResult.SKIPSUBTREEPOPSTACK) {
mRightSiblingKeyStack.pop();
}
// not present.
if ((result.isPresent() && result.get() != VisitResultType.SKIPSUBTREE && result.get() != LocalVisitResult.SKIPSUBTREEPOPSTACK) || !result.isPresent()) {
// Always follow first child if there is one.
if (rtx.hasFirstChild()) {
final long key = rtx.getFirstChildKey();
final long rightSiblNodeKey = rtx.getRightSiblingKey();
if (rtx.hasRightSibling() && (mRightSiblingKeyStack.isEmpty() || (!mRightSiblingKeyStack.isEmpty() && mRightSiblingKeyStack.peek() != rightSiblNodeKey))) {
mRightSiblingKeyStack.push(rightSiblNodeKey);
}
return key;
}
}
// visitor is not present.
if ((result.isPresent() && result.get() != VisitResultType.SKIPSIBLINGS) || !result.isPresent()) {
// Then follow right sibling if there is one.
if (rtx.hasRightSibling()) {
final long nextKey = rtx.getRightSiblingKey();
return hasNextNode(nextKey, rtx.getNodeKey());
}
}
// Then follow right sibling on stack.
if (mRightSiblingKeyStack.size() > 0) {
final long nextKey = mRightSiblingKeyStack.pop();
return hasNextNode(nextKey, rtx.getNodeKey());
}
return Fixed.NULL_NODE_KEY.getStandardProperty();
}
Aggregations