use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class Store method execute.
@Override
public Sequence execute(final StaticContext sctx, final QueryContext ctx, final Sequence[] args) throws QueryException {
try {
final String collName = FunUtil.getString(args, 0, "collName", "collection", null, true);
final Sequence nodes = args[2];
if (nodes == null)
throw new QueryException(new QNm("No sequence of nodes specified!"));
final boolean createNew = args.length == 4 ? args[3].booleanValue() : true;
final String resName = FunUtil.getString(args, 1, "resName", "resource", null, createNew ? false : true);
final DBStore store = (DBStore) ctx.getStore();
if (createNew) {
create(store, collName, resName, nodes);
} else {
try {
final DBCollection coll = (DBCollection) store.lookup(collName);
add(store, coll, resName, nodes);
} catch (DocumentException e) {
// collection does not exist
create(store, collName, resName, nodes);
}
}
return null;
} catch (final Exception e) {
throw new QueryException(new QNm(e.getMessage()), e);
}
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class Rollback method execute.
@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
final DBNode doc = ((DBNode) args[0]);
if (doc.getTrx() instanceof XdmNodeWriteTrx) {
final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) doc.getTrx();
final long revision = wtx.getRevisionNumber();
wtx.rollback();
return new Int64(revision);
} else {
throw new QueryException(new QNm("The transaction is not a write transaction!"));
}
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class TestNodeWrapperXPath method test.
/**
* XPath tests.
*
* @param expressions
* Expressions, which are used.
* @param doc
* The test document.
* @param expectedResults
* Expected result for each expression.
* @param result
* Array with the result types for each expression.
* @param xpathConstants
* XPathConstants for each expression.
* @param namespaces
* Array of boolean values for each expression.
* @param namespace
* The namespace Context, which is used.
* @throws Exception
* Any Exception which maybe occurs.
*/
@SuppressWarnings("unchecked")
@Ignore("Not a test, utility method only")
public void test(final String[] expressions, final Object doc, final Object[] expectedResults, Object[] result, final QName[] xpathConstants, final boolean[] namespaces, final Object namespace) throws Exception {
// For every expected result.
for (int i = 0; i < expectedResults.length; i++) {
// If namespace is required.
if (namespaces[i]) {
xpe.setNamespaceContext((NamespaceContext) namespace);
}
final XPathExpression findLine = xpe.compile(expressions[i]);
// Cast the evaluated value.
if (xpathConstants[i].equals(XPathConstants.NODESET)) {
result[i] = findLine.evaluate(doc, xpathConstants[i]);
} else if (xpathConstants[i].equals(XPathConstants.STRING)) {
result[i] = (String) findLine.evaluate(doc, xpathConstants[i]);
} else if (xpathConstants[i].equals(XPathConstants.NUMBER)) {
result[i] = Double.parseDouble(findLine.evaluate(doc, xpathConstants[i]).toString());
} else {
throw new IllegalStateException("Unknown XPathConstant!");
}
assertNotNull(result);
if (xpathConstants[i].equals(XPathConstants.NODESET)) {
final ArrayList<NodeWrapper> test = (ArrayList<NodeWrapper>) result[i];
final String res = (String) expectedResults[i];
final String[] expRes = res.split(" ");
// compare it.
for (int j = 0; j < test.size(); j++) {
final NodeWrapper item = test.get(j);
mHolder.getRtx().moveTo(item.getKey());
final QNm qName = mHolder.getRtx().getName();
if (mHolder.getRtx().getKind() == Kind.ELEMENT) {
assertEquals(expRes[j], qName.getPrefix() + ":" + qName.getLocalName());
} else if (mHolder.getRtx().getKind() == Kind.TEXT) {
assertEquals(expRes[j], mHolder.getRtx().getValue());
}
}
} else {
assertEquals(expectedResults[i], result[i]);
}
}
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class PathSummaryTest method testSetQNmSecond.
/**
* Test setQNm on test document (finds a corresponding path summary after rename).
*
* @throws SirixException if Sirix fails
*/
@Test
public void testSetQNmSecond() throws SirixException {
wtx.moveTo(9);
wtx.setName(new QNm("d"));
wtx.setName(new QNm("b"));
PathSummaryReader pathSummary = wtx.getPathSummary();
pathSummary.moveToDocumentRoot();
testSetQNmSecondHelper(pathSummary);
wtx.commit();
wtx.close();
pathSummary = holder.getResourceManager().openPathSummary();
testSetQNmSecondHelper(pathSummary);
pathSummary.close();
}
use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.
the class PathSummaryTest method testSetQNmThird.
/**
* 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 testSetQNmThird() throws SirixException {
wtx.moveTo(9);
wtx.setName(new QNm("d"));
wtx.moveTo(5);
wtx.setName(new QNm("t"));
PathSummaryReader pathSummary = wtx.getPathSummary();
pathSummary.moveToDocumentRoot();
testSetQNmThirdHelper(pathSummary);
wtx.commit();
wtx.close();
pathSummary = holder.getResourceManager().openPathSummary();
testSetQNmThirdHelper(pathSummary);
pathSummary.close();
}
Aggregations