use of org.sirix.node.interfaces.NameNode in project sirix by sirixdb.
the class NameIndexListener method listen.
@Override
public void listen(ChangeType type, @Nonnull ImmutableNode node, long pathNodeKey) throws SirixIOException {
if (node instanceof NameNode) {
final NameNode nameNode = (NameNode) node;
final QNm name = nameNode.getName();
final boolean included = (mIncludes.isEmpty() || mIncludes.contains(name));
final boolean excluded = (!mExcludes.isEmpty() && mExcludes.contains(name));
if (!included || excluded) {
return;
}
switch(type) {
case INSERT:
final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(name, SearchMode.EQUAL);
if (textReferences.isPresent()) {
setNodeReferences(node, textReferences.get(), name);
} else {
setNodeReferences(node, new NodeReferences(), name);
}
break;
case DELETE:
mAVLTreeWriter.remove(name, node.getNodeKey());
break;
default:
}
}
}
use of org.sirix.node.interfaces.NameNode in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method moveSubtreeToFirstChild.
@Override
public XdmNodeWriteTrx moveSubtreeToFirstChild(@Nonnegative final long fromKey) throws SirixException, IllegalArgumentException {
acquireLock();
try {
Preconditions.checkArgument(fromKey >= 0 && fromKey <= getMaxNodeKey(), "Argument must be a valid node key!");
Preconditions.checkArgument(fromKey != getCurrentNode().getNodeKey(), "Can't move itself to right sibling of itself!");
@SuppressWarnings("unchecked") final Optional<? extends Node> node = (Optional<? extends Node>) getPageTransaction().getRecord(fromKey, PageKind.RECORDPAGE, -1);
if (!node.isPresent()) {
throw new IllegalStateException("Node to move must exist!");
}
final Node nodeToMove = node.get();
if (nodeToMove instanceof StructNode && getCurrentNode().getKind() == Kind.ELEMENT) {
// Safe to cast (because IStructNode is a subtype of INode).
checkAncestors(nodeToMove);
checkAccessAndCommit();
final ElementNode nodeAnchor = (ElementNode) getCurrentNode();
// Check that it's not already the first child.
if (nodeAnchor.getFirstChildKey() != nodeToMove.getNodeKey()) {
final StructNode toMove = (StructNode) nodeToMove;
// Adapt index-structures (before move).
adaptSubtreeForMove(toMove, ChangeType.DELETE);
// Adapt hashes.
adaptHashesForMove(toMove);
// Adapt pointers and merge sibling text nodes.
adaptForMove(toMove, nodeAnchor, InsertPos.ASFIRSTCHILD);
mNodeReader.moveTo(toMove.getNodeKey());
adaptHashesWithAdd();
// Adapt path summary.
if (mBuildPathSummary && toMove instanceof NameNode) {
final NameNode moved = (NameNode) toMove;
mPathSummaryWriter.adaptPathForChangedNode(moved, getName(), moved.getURIKey(), moved.getPrefixKey(), moved.getLocalNameKey(), OPType.MOVED);
}
// Adapt index-structures (after move).
adaptSubtreeForMove(toMove, ChangeType.INSERT);
// Compute and assign new DeweyIDs.
if (mDeweyIDsStored) {
computeNewDeweyIDs();
}
}
return this;
} else {
throw new SirixUsageException("Move is not allowed if moved node is not an ElementNode and the node isn't inserted at an element node!");
}
} finally {
unLock();
}
}
use of org.sirix.node.interfaces.NameNode in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method removeName.
/**
* Remove a name from the {@link NamePage} reference and the path summary if needed.
*
* @throws SirixException if Sirix fails
*/
private void removeName() throws SirixException {
if (getCurrentNode() instanceof NameNode) {
final NameNode node = ((NameNode) getCurrentNode());
final Kind nodeKind = node.getKind();
final NamePage page = ((NamePage) getPageTransaction().getActualRevisionRootPage().getNamePageReference().getPage());
page.removeName(node.getPrefixKey(), nodeKind);
page.removeName(node.getLocalNameKey(), nodeKind);
page.removeName(node.getURIKey(), Kind.NAMESPACE);
assert nodeKind != Kind.DOCUMENT;
if (mBuildPathSummary) {
mPathSummaryWriter.remove(node, nodeKind, page);
}
}
}
use of org.sirix.node.interfaces.NameNode in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method moveSubtreeToRightSibling.
@Override
public XdmNodeWriteTrx moveSubtreeToRightSibling(@Nonnegative final long fromKey) throws SirixException {
acquireLock();
try {
if (fromKey < 0 || fromKey > getMaxNodeKey()) {
throw new IllegalArgumentException("Argument must be a valid node key!");
}
if (fromKey == getCurrentNode().getNodeKey()) {
throw new IllegalArgumentException("Can't move itself to first child of itself!");
}
// Save: Every node in the "usual" node page is of type Node.
@SuppressWarnings("unchecked") final Optional<? extends Node> node = (Optional<? extends Node>) getPageTransaction().getRecord(fromKey, PageKind.RECORDPAGE, -1);
if (!node.isPresent()) {
throw new IllegalStateException("Node to move must exist!");
}
final Node nodeToMove = node.get();
if (nodeToMove instanceof StructNode && getCurrentNode() instanceof StructNode) {
final StructNode toMove = (StructNode) nodeToMove;
checkAncestors(toMove);
checkAccessAndCommit();
final StructNode nodeAnchor = (StructNode) getCurrentNode();
if (nodeAnchor.getRightSiblingKey() != nodeToMove.getNodeKey()) {
final long parentKey = toMove.getParentKey();
// Adapt hashes.
adaptHashesForMove(toMove);
// Adapt pointers and merge sibling text nodes.
adaptForMove(toMove, nodeAnchor, InsertPos.ASRIGHTSIBLING);
mNodeReader.moveTo(toMove.getNodeKey());
adaptHashesWithAdd();
// Adapt path summary.
if (mBuildPathSummary && toMove instanceof NameNode) {
final NameNode moved = (NameNode) toMove;
final OPType type = moved.getParentKey() == parentKey ? OPType.MOVEDSAMELEVEL : OPType.MOVED;
mPathSummaryWriter.adaptPathForChangedNode(moved, getName(), moved.getURIKey(), moved.getPrefixKey(), moved.getLocalNameKey(), type);
}
// Recompute DeweyIDs if they are used.
if (mDeweyIDsStored) {
computeNewDeweyIDs();
}
}
return this;
} else {
throw new SirixUsageException("Move is not allowed if moved node is not an ElementNode or TextNode and the node isn't inserted at an ElementNode or TextNode!");
}
} finally {
unLock();
}
}
Aggregations