use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.
the class UpdateTest method testFirstMoveToFirstChild.
@Test
public void testFirstMoveToFirstChild() throws SirixException {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.moveTo(7);
wtx.moveSubtreeToFirstChild(6);
testFirstMoveToFirstChild(wtx);
wtx.commit();
testFirstMoveToFirstChild(wtx);
wtx.close();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
testFirstMoveToFirstChild(rtx);
rtx.moveToDocumentRoot();
final Builder<SirixDeweyID> builder = ImmutableSet.<SirixDeweyID>builder();
final ImmutableSet<SirixDeweyID> ids = builder.add(new SirixDeweyID("1")).add(new SirixDeweyID("1.3")).add(new SirixDeweyID("1.3.0.3")).add(new SirixDeweyID("1.3.1.3")).add(new SirixDeweyID("1.3.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.5.5.3")).add(new SirixDeweyID("1.3.7")).add(new SirixDeweyID("1.3.9")).add(new SirixDeweyID("1.3.9.1.3")).add(new SirixDeweyID("1.3.9.3")).add(new SirixDeweyID("1.3.9.5")).add(new SirixDeweyID("1.3.11")).build();
test(ids.iterator(), new NonStructuralWrapperAxis(new DescendantAxis(rtx, IncludeSelf.YES)));
rtx.close();
}
use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.
the class UpdateTest method testFirstMoveSubtreeToRightSibling.
@Test
public void testFirstMoveSubtreeToRightSibling() throws SirixException {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.moveToDocumentRoot();
for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
System.out.println(nodeKey + ": " + wtx.getDeweyID());
}
wtx.moveTo(7);
wtx.moveSubtreeToRightSibling(6);
testFirstMoveSubtreeToRightSibling(wtx);
wtx.moveToDocumentRoot();
for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
System.out.println(nodeKey + ": " + wtx.getDeweyID());
}
wtx.commit();
wtx.moveToDocumentRoot();
for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
System.out.println(nodeKey + ": " + wtx.getDeweyID());
}
testFirstMoveSubtreeToRightSibling(wtx);
wtx.close();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
testFirstMoveSubtreeToRightSibling(rtx);
rtx.moveToDocumentRoot();
final Builder<SirixDeweyID> builder = ImmutableSet.<SirixDeweyID>builder();
final ImmutableSet<SirixDeweyID> ids = builder.add(new SirixDeweyID("1")).add(new SirixDeweyID("1.3")).add(new SirixDeweyID("1.3.0.3")).add(new SirixDeweyID("1.3.1.3")).add(new SirixDeweyID("1.3.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.5.7")).add(new SirixDeweyID("1.3.7")).add(new SirixDeweyID("1.3.9")).add(new SirixDeweyID("1.3.9.1.3")).add(new SirixDeweyID("1.3.9.3")).add(new SirixDeweyID("1.3.9.5")).add(new SirixDeweyID("1.3.11")).build();
test(ids.iterator(), new NonStructuralWrapperAxis(new DescendantAxis(rtx, IncludeSelf.YES)));
rtx.close();
}
use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method getFirstChildDeweyID.
@Override
public Optional<SirixDeweyID> getFirstChildDeweyID() {
if (mResourceManager.getResourceConfig().mDeweyIDsStored) {
final StructNode node = getStructuralNode();
final long nodeKey = node.getNodeKey();
Optional<SirixDeweyID> deweyID = Optional.<SirixDeweyID>empty();
if (node.hasFirstChild()) {
// Right sibling node.
deweyID = moveTo(node.getFirstChildKey()).get().getDeweyID();
}
moveTo(nodeKey);
return deweyID;
}
return Optional.<SirixDeweyID>empty();
}
use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method getLeftSiblingDeweyID.
@Override
public Optional<SirixDeweyID> getLeftSiblingDeweyID() {
assertNotClosed();
if (mResourceManager.getResourceConfig().mDeweyIDsStored) {
final StructNode node = getStructuralNode();
final long nodeKey = node.getNodeKey();
Optional<SirixDeweyID> deweyID = Optional.<SirixDeweyID>empty();
if (node.hasLeftSibling()) {
// Left sibling node.
deweyID = moveTo(node.getLeftSiblingKey()).get().getDeweyID();
}
moveTo(nodeKey);
return deweyID;
}
return Optional.<SirixDeweyID>empty();
}
use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method insertTextAsFirstChild.
@Override
public XdmNodeWriteTrx insertTextAsFirstChild(final String value) throws SirixException {
checkNotNull(value);
acquireLock();
try {
if (getCurrentNode() instanceof StructNode && !value.isEmpty()) {
checkAccessAndCommit();
final long pathNodeKey = getCurrentNode().getNodeKey();
final long parentKey = getCurrentNode().getNodeKey();
final long leftSibKey = Fixed.NULL_NODE_KEY.getStandardProperty();
final long rightSibKey = ((StructNode) getCurrentNode()).getFirstChildKey();
// Update value in case of adjacent text nodes.
if (hasNode(rightSibKey)) {
moveTo(rightSibKey);
if (getCurrentNode().getKind() == Kind.TEXT) {
setValue(new StringBuilder(value).append(getValue()).toString());
adaptHashedWithUpdate(getCurrentNode().getHash());
return this;
}
moveTo(parentKey);
}
// Insert new text node if no adjacent text nodes are found.
final byte[] textValue = getBytes(value);
final Optional<SirixDeweyID> id = newFirstChildID();
final TextNode node = mNodeFactory.createTextNode(parentKey, leftSibKey, rightSibKey, textValue, mCompression, id);
// Adapt local nodes and hashes.
mNodeReader.setCurrentNode(node);
adaptForInsert(node, InsertPos.ASFIRSTCHILD, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
adaptHashesWithAdd();
// Index text value.
mIndexController.notifyChange(ChangeType.INSERT, node, pathNodeKey);
return this;
} else {
throw new SirixUsageException("Insert is not allowed if current node is not an ElementNode or TextNode!");
}
} finally {
unLock();
}
}
Aggregations