use of org.sirix.api.Axis in project sirix by sirixdb.
the class ConcurrentAxisTest method testConcurrent.
/**
* Test concurrent.
*
* @throws SirixException
*
* @throws SirixXPathException
*/
// @Bench
@Test
public void testConcurrent() throws Exception {
/* query: //regions/africa//location */
final int resultNumber = 55;
final XdmNodeReadTrx firstConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
final XdmNodeReadTrx secondConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
final XdmNodeReadTrx thirdConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
final XdmNodeReadTrx firstRtx = holder.getResourceManager().beginNodeReadTrx();
final XdmNodeReadTrx secondRtx = holder.getResourceManager().beginNodeReadTrx();
final XdmNodeReadTrx thirdRtx = holder.getResourceManager().beginNodeReadTrx();
final Axis axis = new NestedAxis(new NestedAxis(new ConcurrentAxis(firstConcurrRtx, new FilterAxis(new DescendantAxis(firstRtx, IncludeSelf.YES), new NameFilter(firstRtx, "regions"))), new ConcurrentAxis(secondConcurrRtx, new FilterAxis(new ChildAxis(secondRtx), new NameFilter(secondRtx, "africa")))), new ConcurrentAxis(thirdConcurrRtx, new FilterAxis(new DescendantAxis(thirdRtx, IncludeSelf.YES), new NameFilter(thirdRtx, "location"))));
for (int i = 0; i < resultNumber; i++) {
assertEquals(true, axis.hasNext());
axis.next();
}
assertEquals(false, axis.hasNext());
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class NestedAxisTest method testNestedAxisTest3.
@Test
public void testNestedAxisTest3() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
// Find desceFndants starting from nodeKey 0L (root).
rtx.moveToDocumentRoot();
// XPath expression p:a/node():
// Part: /p:a
final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
// Part: /node()
final Axis childNode = new FilterAxis(new ChildAxis(rtx), new NodeFilter(rtx));
// Part: /p:a/node():
final Axis axis = new NestedAxis(childA, childNode);
AbsAxisTest.testIAxisConventions(axis, new long[] { 4L, 5L, 8L, 9L, 13L });
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class NestedAxisTest method testNestedAxisTest2.
@Test
public void testNestedAxisTest2() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
// Find descendants starting from nodeKey 0L (root).
rtx.moveToDocumentRoot();
// XPath expression /[:a/b/@p:x]
// Part: /p:a
final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
// Part: /b
final Axis childB = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "b"));
// Part: /@x
final Axis attributeX = new FilterAxis(new AttributeAxis(rtx), new NameFilter(rtx, "p:x"));
// Part: /p:a/b/@p:x
final Axis axis = new NestedAxis(new NestedAxis(childA, childB), attributeX);
AbsAxisTest.testIAxisConventions(axis, new long[] { 10L });
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method adaptSubtreeForMove.
/**
* Adapt subtree regarding the index-structures.
*
* @param toMove node which is moved (either before the move, or after the move)
* @param type the type of change (either deleted from the old position or inserted into the new
* position)
* @throws SirixIOException if an I/O exception occurs
*/
private void adaptSubtreeForMove(final Node node, final ChangeType type) throws SirixIOException {
assert type != null;
final long beforeNodeKey = getNode().getNodeKey();
moveTo(node.getNodeKey());
final Axis axis = new DescendantAxis(this, IncludeSelf.YES);
while (axis.hasNext()) {
axis.next();
for (int i = 0, attCount = getAttributeCount(); i < attCount; i++) {
moveToAttribute(i);
final ImmutableAttribute att = (ImmutableAttribute) getNode();
mIndexController.notifyChange(type, att, att.getPathNodeKey());
moveToParent();
}
for (int i = 0, nspCount = getNamespaceCount(); i < nspCount; i++) {
moveToAttribute(i);
final ImmutableNamespace nsp = (ImmutableNamespace) getNode();
mIndexController.notifyChange(type, nsp, nsp.getPathNodeKey());
moveToParent();
}
long pathNodeKey = -1;
if (getNode() instanceof ValueNode && getNode().getParentKey() != Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
final long nodeKey = getNode().getNodeKey();
pathNodeKey = moveToParent().get().getNameNode().getPathNodeKey();
moveTo(nodeKey);
} else if (getNode() instanceof NameNode) {
pathNodeKey = getNameNode().getPathNodeKey();
}
mIndexController.notifyChange(type, getNode(), pathNodeKey);
}
moveTo(beforeNodeKey);
}
use of org.sirix.api.Axis 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();
}
}
Aggregations