use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PathSummaryWriter method resetPath.
/**
* Reset the path node key of a node.
*
* @param newPathNodeKey path node key of new path node
* @param oldLevel old level of node
* @throws SirixIOException if an I/O error occurs
*/
private void resetPath(@Nonnegative final long newPathNodeKey, @Nonnegative final int oldLevel) throws SirixIOException {
// Search for new path entry.
mPathSummaryReader.moveTo(newPathNodeKey);
final Axis filterAxis = new FilterAxis(new LevelOrderAxis.Builder(mPathSummaryReader).includeSelf().build(), new NameFilter(mPathSummaryReader, Utils.buildName(mNodeRtx.getName())), new PathKindFilter(mPathSummaryReader, mNodeRtx.getKind()), new PathLevelFilter(mPathSummaryReader, oldLevel));
if (filterAxis.hasNext()) {
filterAxis.next();
// Set new path node.
final NameNode node = (NameNode) mPageWriteTrx.prepareEntryForModification(mNodeRtx.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
node.setPathNodeKey(mPathSummaryReader.getNodeKey());
} else {
throw new IllegalStateException();
}
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PathSummaryWriter method resetPathNodeKey.
/**
* Reset a path node key.
*
* @param nodeKey the nodeKey of the node to adapt
* @throws SirixException if anything fails
*/
private void resetPathNodeKey(@Nonnegative final long nodeKey) throws SirixException {
final NameNode currNode = (NameNode) mPageWriteTrx.prepareEntryForModification(nodeKey, PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
currNode.setPathNodeKey(mPathSummaryReader.getNodeKey());
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PathSummaryWriter method getPathNodeKey.
/**
* Insert a new path node or increment the counter of an existing node and return the path node
* key.
*
* @param name the name of the path node to search for
* @param pathKind the kind of the path node to search for
* @return a path node key of the found node, or the path node key of a new inserted node
* @throws SirixException if anything went wrong
*/
public long getPathNodeKey(final QNm name, final Kind pathKind) throws SirixException {
final Kind kind = mNodeRtx.getNode().getKind();
int level = 0;
if (kind == Kind.DOCUMENT) {
mPathSummaryReader.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
} else {
movePathSummary();
level = mPathSummaryReader.getLevel();
}
final long nodeKey = mPathSummaryReader.getNodeKey();
final Axis axis = new FilterAxis(new ChildAxis(mPathSummaryReader), new NameFilter(mPathSummaryReader, pathKind == Kind.NAMESPACE ? name.getPrefix() : Utils.buildName(name)), new PathKindFilter(mPathSummaryReader, pathKind));
long retVal = nodeKey;
if (axis.hasNext()) {
axis.next();
retVal = mPathSummaryReader.getNodeKey();
final PathNode pathNode = (PathNode) mPageWriteTrx.prepareEntryForModification(retVal, PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
pathNode.incrementReferenceCount();
} else {
assert nodeKey == mPathSummaryReader.getNodeKey();
insertPathAsFirstChild(name, pathKind, level + 1);
retVal = mPathSummaryReader.getNodeKey();
}
return retVal;
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class AVLTreeWriter method rotateLeft.
/**
* Left rotation.
*
* @param node node to be rotated
* @throws SirixIOException if an I/O error occurs
*/
@SuppressWarnings({ "unchecked" })
private void rotateLeft(AVLNode<K, V> node) throws SirixIOException {
moveTo(node.getNodeKey());
AVLNode<K, V> right = ((AVLTreeReader<K, V>) moveToLastChild().get()).getAVLNode();
node = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(node.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
node.setRightChildKey(right.getLeftChildKey());
if (right.hasLeftChild()) {
final AVLNode<K, V> rightLeftChild = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(right.getLeftChildKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
rightLeftChild.setParentKey(node.getNodeKey());
}
right = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(right.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
right.setParentKey(node.getParentKey());
if (node.getParentKey() == Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
final DocumentRootNode parent = (DocumentRootNode) mPageWriteTrx.prepareEntryForModification(Fixed.DOCUMENT_NODE_KEY.getStandardProperty(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
parent.setFirstChildKey(right.getNodeKey());
} else if (moveTo(node.getParentKey()).hasMoved() && mAVLTreeReader.getAVLNode().getLeftChildKey() == node.getNodeKey()) {
final AVLNode<K, V> parent = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(mAVLTreeReader.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
parent.setLeftChildKey(right.getNodeKey());
} else {
final AVLNode<K, V> parent = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(mAVLTreeReader.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
parent.setRightChildKey(right.getNodeKey());
}
right = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(right.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
right.setLeftChildKey(node.getNodeKey());
node = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(node.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
node.setParentKey(right.getNodeKey());
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method computeNewDeweyIDs.
/**
* Compute the new DeweyIDs.
*
* @throws SirixException if anything went wrong
*/
private void computeNewDeweyIDs() throws SirixException {
SirixDeweyID id = null;
if (hasLeftSibling() && hasRightSibling()) {
id = SirixDeweyID.newBetween(getLeftSiblingDeweyID().get(), getRightSiblingDeweyID().get());
} else if (hasLeftSibling()) {
id = SirixDeweyID.newBetween(getLeftSiblingDeweyID().get(), null);
} else if (hasRightSibling()) {
id = SirixDeweyID.newBetween(null, getRightSiblingDeweyID().get());
} else {
id = mNodeReader.getParentDeweyID().get().getNewChildID();
}
assert id != null;
final long nodeKey = mNodeReader.getCurrentNode().getNodeKey();
final StructNode root = (StructNode) getPageTransaction().prepareEntryForModification(nodeKey, PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
root.setDeweyID(Optional.of(id));
if (root.hasFirstChild()) {
final Node firstChild = (Node) getPageTransaction().prepareEntryForModification(root.getFirstChildKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
firstChild.setDeweyID(Optional.of(id.getNewChildID()));
int previousLevel = getDeweyID().get().getLevel();
mNodeReader.moveTo(firstChild.getNodeKey());
int attributeNr = 0;
int nspNr = 0;
for (@SuppressWarnings("unused") final long key : LevelOrderAxis.newBuilder(this).includeNonStructuralNodes().build()) {
Optional<SirixDeweyID> deweyID = Optional.<SirixDeweyID>empty();
if (isAttribute()) {
final long attNodeKey = mNodeReader.getNodeKey();
if (attributeNr == 0) {
deweyID = Optional.of(mNodeReader.getParentDeweyID().get().getNewAttributeID());
} else {
mNodeReader.moveTo(attributeNr - 1);
deweyID = Optional.of(SirixDeweyID.newBetween(mNodeReader.getNode().getDeweyID().get(), null));
}
mNodeReader.moveTo(attNodeKey);
attributeNr++;
} else if (isNamespace()) {
final long nspNodeKey = mNodeReader.getNodeKey();
if (nspNr == 0) {
deweyID = Optional.of(mNodeReader.getParentDeweyID().get().getNewNamespaceID());
} else {
mNodeReader.moveTo(nspNr - 1);
deweyID = Optional.of(SirixDeweyID.newBetween(mNodeReader.getNode().getDeweyID().get(), null));
}
mNodeReader.moveTo(nspNodeKey);
nspNr++;
} else {
attributeNr = 0;
nspNr = 0;
if (previousLevel + 1 == getDeweyID().get().getLevel()) {
if (mNodeReader.hasLeftSibling()) {
deweyID = Optional.of(SirixDeweyID.newBetween(getLeftSiblingDeweyID().get(), null));
} else {
deweyID = Optional.of(getParentDeweyID().get().getNewChildID());
}
} else {
previousLevel++;
deweyID = Optional.of(getParentDeweyID().get().getNewChildID());
}
}
final Node node = (Node) getPageTransaction().prepareEntryForModification(mNodeReader.getCurrentNode().getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
node.setDeweyID(deweyID);
}
mNodeReader.moveTo(nodeKey);
}
}
Aggregations