use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class VersioningTest method test2.
/**
* Test revisioning.
*
* @throws SirixException if anything in Sirix fails
*/
public void test2() throws SirixException {
try (final ResourceManager manager = mDatabase.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build())) {
XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.close();
try (final XdmNodeReadTrx rtx = manager.beginNodeReadTrx()) {
assertTrue(rtx.moveToFirstChild().hasMoved());
assertTrue(rtx.moveToFirstChild().hasMoved());
assertTrue(rtx.moveToFirstChild().hasMoved());
assertTrue(rtx.moveToFirstChild().hasMoved());
assertTrue(rtx.moveToFirstChild().hasMoved());
}
}
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class VersioningTest method setBaaaz.
/**
* Set the last {@link QNm} in the first node page.
*
* @param wtx {@link XdmNodeWriteTrx} instance
* @throws SirixException if inserting elements fails
*/
private void setBaaaz(final XdmNodeWriteTrx wtx) throws SirixException {
wtx.moveToDocumentRoot();
wtx.moveToFirstChild();
for (int i = 0; i < Constants.NDP_NODE_COUNT - 3; i++) {
wtx.moveToFirstChild();
}
wtx.setName(new QNm("baaaz"));
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method pi.
/**
* Processing instruction.
*
* @param target target PI
* @param content content of PI
* @param insert insertion location
* @throws SirixException if any unexpected error occurs
*/
private XdmNodeWriteTrx pi(final String target, final String content, final Insert insert) throws SirixException {
final byte[] targetBytes = getBytes(target);
if (!XMLToken.isNCName(checkNotNull(targetBytes))) {
throw new IllegalArgumentException("The target is not valid!");
}
if (content.contains("?>-")) {
throw new SirixUsageException("The content must not contain '?>-'");
}
acquireLock();
try {
if (getCurrentNode() instanceof StructNode) {
checkAccessAndCommit();
// Insert new processing instruction node.
final byte[] processingContent = getBytes(content);
long parentKey = 0;
long leftSibKey = 0;
long rightSibKey = 0;
InsertPos pos = InsertPos.ASFIRSTCHILD;
Optional<SirixDeweyID> id = Optional.<SirixDeweyID>empty();
switch(insert) {
case ASFIRSTCHILD:
parentKey = getCurrentNode().getNodeKey();
leftSibKey = Fixed.NULL_NODE_KEY.getStandardProperty();
rightSibKey = ((StructNode) getCurrentNode()).getFirstChildKey();
id = newFirstChildID();
break;
case ASRIGHTSIBLING:
parentKey = getCurrentNode().getParentKey();
leftSibKey = getCurrentNode().getNodeKey();
rightSibKey = ((StructNode) getCurrentNode()).getRightSiblingKey();
pos = InsertPos.ASRIGHTSIBLING;
id = newRightSiblingID();
break;
case ASLEFTSIBLING:
parentKey = getCurrentNode().getParentKey();
leftSibKey = ((StructNode) getCurrentNode()).getLeftSiblingKey();
rightSibKey = getCurrentNode().getNodeKey();
pos = InsertPos.ASLEFTSIBLING;
id = newLeftSiblingID();
break;
default:
throw new IllegalStateException("Insert location not known!");
}
final QNm targetName = new QNm(target);
final long pathNodeKey = mBuildPathSummary ? mPathSummaryWriter.getPathNodeKey(targetName, Kind.PROCESSING_INSTRUCTION) : 0;
final PINode node = mNodeFactory.createPINode(parentKey, leftSibKey, rightSibKey, targetName, processingContent, mCompression, pathNodeKey, id);
// Adapt local nodes and hashes.
mNodeReader.setCurrentNode(node);
adaptForInsert(node, pos, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
adaptHashesWithAdd();
return this;
} else {
throw new SirixUsageException("Current node must be a structural node!");
}
} finally {
unLock();
}
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class ModificationVisitor method modify.
/**
* Determines if a node must be modified. If yes, it is deleted and {@code true} is returned. If
* it must not be deleted {@code false} is returned. The transaction is moved accordingly in case
* of a remove-operation such that the {@link DescendantAxis} can move to the next node after a
* delete occurred.
*
* @param node the node to check and possibly delete
* @return {@code true} if node has been deleted, {@code false} otherwise
*/
private VisitResult modify(final ImmutableNode node) {
assert node != null;
if (mNodeIndex % MODIFY_EVERY == 0) {
mNodeIndex = 1;
try {
switch(mRandom.nextInt(4)) {
case 0:
final QNm insert = new QNm("testInsert");
final long key = mWtx.getNodeKey();
mWtx.insertElementAsLeftSibling(insert);
boolean moved = mWtx.moveTo(key).hasMoved();
assert moved;
return VisitResultType.CONTINUE;
case 1:
if (mWtx.getKind() == Kind.TEXT) {
mWtx.setValue("testUpdate");
} else if (mWtx.getKind() == Kind.ELEMENT) {
mWtx.setName(new QNm("testUpdate"));
}
return VisitResultType.CONTINUE;
case 2:
return delete();
case 3:
mWtx.replaceNode("<foo/>");
return VisitResultType.CONTINUE;
}
} catch (final SirixException | IOException | XMLStreamException e) {
LOGWRAPPER.error(e.getMessage(), e);
return VisitResultType.TERMINATE;
}
} else {
mNodeIndex++;
return VisitResultType.CONTINUE;
}
return VisitResultType.CONTINUE;
}
Aggregations