use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class PathSummaryTest method testSetQNmFourth.
/**
* Test setQNm on test document (finds no corresponding path summary after rename -- after
* references dropped to 0).
*
* @throws SirixException if Sirix fails
*/
@Test
public void testSetQNmFourth() throws SirixException {
wtx.moveTo(1);
wtx.insertElementAsFirstChild(new QNm("b"));
wtx.moveTo(5);
wtx.setName(new QNm("d"));
PathSummaryReader pathSummary = wtx.getPathSummary();
pathSummary.moveToDocumentRoot();
testSetQNmFourthHelper(pathSummary);
wtx.commit();
wtx.close();
pathSummary = holder.getResourceManager().openPathSummary();
testSetQNmFourthHelper(pathSummary);
pathSummary.close();
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class UpdateTest method testNodeTransactionIsolation.
@Test
public void testNodeTransactionIsolation() throws SirixException {
XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
wtx.insertElementAsFirstChild(new QNm(""));
testNodeTransactionIsolation(wtx);
wtx.commit();
testNodeTransactionIsolation(wtx);
XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
testNodeTransactionIsolation(rtx);
wtx.moveToFirstChild();
wtx.insertElementAsFirstChild(new QNm(""));
testNodeTransactionIsolation(rtx);
wtx.commit();
testNodeTransactionIsolation(rtx);
rtx.close();
wtx.close();
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class UpdateTest method testInsertChild.
@Test
public void testInsertChild() throws SirixException {
XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.close();
XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
assertEquals(1L, rtx.getRevisionNumber());
rtx.close();
// Insert 100 children.
for (int i = 1; i <= 50; i++) {
wtx = holder.getResourceManager().beginNodeWriteTrx();
wtx.moveToDocumentRoot();
wtx.moveToFirstChild();
wtx.insertElementAsFirstChild(new QNm("bar"));
wtx.insertTextAsRightSibling(Integer.toString(i));
wtx.commit();
wtx.close();
rtx = holder.getResourceManager().beginNodeReadTrx();
rtx.moveToDocumentRoot();
rtx.moveToFirstChild();
rtx.moveToFirstChild();
rtx.moveToRightSibling();
assertEquals(Integer.toString(i), rtx.getValue());
assertEquals(i + 1, rtx.getRevisionNumber());
rtx.close();
}
rtx = holder.getResourceManager().beginNodeReadTrx();
rtx.moveToDocumentRoot();
rtx.moveToFirstChild();
rtx.moveToFirstChild();
rtx.moveToRightSibling();
assertEquals("50", rtx.getValue());
assertEquals(51L, rtx.getRevisionNumber());
rtx.close();
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class HashTest method testSetter.
@Ignore
private void testSetter(final XdmNodeWriteTrx wtx) throws SirixException {
// Testing node inheritance
wtx.insertElementAsFirstChild(new QNm(NAME1));
wtx.insertElementAsFirstChild(new QNm(NAME1));
wtx.insertElementAsFirstChild(new QNm(NAME1));
wtx.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
wtx.moveTo(wtx.getFirstChildKey());
final long hashRoot1 = wtx.getHash();
wtx.moveTo(wtx.getFirstChildKey());
wtx.moveTo(wtx.getFirstChildKey());
final long hashLeaf1 = wtx.getHash();
wtx.setName(new QNm(NAME2));
final long hashLeaf2 = wtx.getHash();
wtx.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
wtx.moveTo(wtx.getFirstChildKey());
final long hashRoot2 = wtx.getHash();
assertFalse(hashRoot1 == hashRoot2);
assertFalse(hashLeaf1 == hashLeaf2);
wtx.moveTo(wtx.getFirstChildKey());
wtx.moveTo(wtx.getFirstChildKey());
wtx.setName(new QNm(NAME1));
final long hashLeaf3 = wtx.getHash();
assertEquals(hashLeaf1, hashLeaf3);
wtx.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
wtx.moveTo(wtx.getFirstChildKey());
final long hashRoot3 = wtx.getHash();
assertEquals(hashRoot1, hashRoot3);
// Testing root inheritance
wtx.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
wtx.moveTo(wtx.getFirstChildKey());
wtx.setName(new QNm(NAME2));
final long hashRoot4 = wtx.getHash();
assertFalse(hashRoot4 == hashRoot2);
assertFalse(hashRoot4 == hashRoot1);
assertFalse(hashRoot4 == hashRoot3);
assertFalse(hashRoot4 == hashLeaf1);
assertFalse(hashRoot4 == hashLeaf2);
assertFalse(hashRoot4 == hashLeaf3);
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class HashTest method testHashTreeWithInsertAndRemove.
/**
* Inserting nodes and removing them.
*
* <pre>
* -a (1)
* '-test (5)
* '-a (6)
* '-attr(7)
* '-a (8)
* '-attr (9)
* '-text (2)
* '-a (3(x))
* '-attr(4(x))
* </pre>
*
* @param wtx
* @throws TTException
*/
@Ignore
private void testHashTreeWithInsertAndRemove(final XdmNodeWriteTrx wtx) throws SirixException {
// inserting a element as root
wtx.insertElementAsFirstChild(new QNm(NAME1));
final long rootKey = wtx.getNodeKey();
final long firstRootHash = wtx.getHash();
// inserting a text as second child of root
wtx.moveTo(rootKey);
wtx.insertTextAsFirstChild(NAME1);
wtx.moveTo(wtx.getParentKey());
final long secondRootHash = wtx.getHash();
// inserting a second element on level 2 under the only element
wtx.moveTo(wtx.getFirstChildKey());
wtx.insertElementAsRightSibling(new QNm(NAME2));
wtx.insertAttribute(new QNm(NAME2), NAME1);
wtx.moveTo(rootKey);
final long thirdRootHash = wtx.getHash();
// Checking that all hashes are different
assertFalse(firstRootHash == secondRootHash);
assertFalse(firstRootHash == thirdRootHash);
assertFalse(secondRootHash == thirdRootHash);
// removing the second element
wtx.moveTo(wtx.getFirstChildKey());
wtx.moveTo(wtx.getRightSiblingKey());
wtx.remove();
wtx.moveTo(rootKey);
assertEquals(secondRootHash, wtx.getHash());
// adding additional element for showing that hashes are computed
// incrementilly
wtx.insertTextAsFirstChild(NAME1);
wtx.insertElementAsRightSibling(new QNm(NAME1));
wtx.insertAttribute(new QNm(NAME1), NAME2);
wtx.moveToParent();
wtx.insertElementAsFirstChild(new QNm(NAME1));
wtx.insertAttribute(new QNm(NAME2), NAME1);
wtx.moveTo(rootKey);
wtx.moveToFirstChild();
wtx.remove();
wtx.remove();
wtx.moveTo(rootKey);
assertEquals(firstRootHash, wtx.getHash());
}
Aggregations