Search in sources :

Example 16 with QueryException

use of org.brackit.xquery.QueryException in project sirix by sirixdb.

the class CreateNameIndex method execute.

@Override
public Sequence execute(final StaticContext sctx, final QueryContext ctx, final Sequence[] args) throws QueryException {
    if (args.length != 2 && args.length != 3) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBNode doc = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getWtxIndexController(rtx.getRevisionNumber() - 1);
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final Set<QNm> include = new HashSet<>();
    if (args.length > 1 && args[1] != null) {
        final Iter it = args[1].iterate();
        Item next = it.next();
        while (next != null) {
            include.add((QNm) next);
            next = it.next();
        }
    }
    final IndexDef idxDef = IndexDefs.createSelectiveNameIdxDef(include, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.NAME));
    try {
        controller.createIndexes(ImmutableSet.of(idxDef), (XdmNodeWriteTrx) doc.getTrx());
    } catch (final SirixIOException e) {
        throw new QueryException(new QNm("I/O exception: " + e.getMessage()), e);
    }
    return idxDef.materialize();
}
Also used : DBNode(org.sirix.xquery.node.DBNode) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) Item(org.brackit.xquery.xdm.Item) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IndexController(org.sirix.access.IndexController) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) SirixIOException(org.sirix.exception.SirixIOException) HashSet(java.util.HashSet)

Example 17 with QueryException

use of org.brackit.xquery.QueryException in project sirix by sirixdb.

the class CreatePathIndex method execute.

@Override
public Sequence execute(final StaticContext sctx, final QueryContext ctx, final Sequence[] args) throws QueryException {
    if (args.length != 2 && args.length != 3) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBNode doc = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getWtxIndexController(rtx.getRevisionNumber() - 1);
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    final Set<Path<QNm>> paths = new HashSet<>();
    if (args.length > 2 && args[2] != null) {
        final Iter it = args[2].iterate();
        Item next = it.next();
        while (next != null) {
            paths.add(Path.parse(((Str) next).stringValue()));
            next = it.next();
        }
    }
    final IndexDef idxDef = IndexDefs.createPathIdxDef(paths, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.PATH));
    try {
        controller.createIndexes(ImmutableSet.of(idxDef), (XdmNodeWriteTrx) doc.getTrx());
    } catch (final SirixIOException e) {
        throw new QueryException(new QNm("I/O exception: " + e.getMessage()), e);
    }
    return idxDef.materialize();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Path(org.brackit.xquery.util.path.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IndexController(org.sirix.access.IndexController) SirixIOException(org.sirix.exception.SirixIOException) DBNode(org.sirix.xquery.node.DBNode) Str(org.brackit.xquery.atomic.Str) QNm(org.brackit.xquery.atomic.QNm) Item(org.brackit.xquery.xdm.Item) QueryException(org.brackit.xquery.QueryException) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) HashSet(java.util.HashSet)

Example 18 with QueryException

use of org.brackit.xquery.QueryException in project sirix by sirixdb.

the class SelectNode method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode node = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = node.getTrx();
    final long nodeKey = FunUtil.getLong(args, 1, "nodeKey", 0, null, true);
    if (rtx.moveTo(nodeKey).hasMoved()) {
        return new DBNode(rtx, node.getCollection());
    } else {
        throw new QueryException(new QNm("Couldn't select node."));
    }
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Aggregations

QueryException (org.brackit.xquery.QueryException)18 QNm (org.brackit.xquery.atomic.QNm)15 DBNode (org.sirix.xquery.node.DBNode)13 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)11 IndexDef (org.sirix.index.IndexDef)11 IndexController (org.sirix.access.IndexController)10 Item (org.brackit.xquery.xdm.Item)8 Atomic (org.brackit.xquery.atomic.Atomic)4 BaseIter (org.brackit.xquery.sequence.BaseIter)4 LazySequence (org.brackit.xquery.sequence.LazySequence)4 Sequence (org.brackit.xquery.xdm.Sequence)4 Stream (org.brackit.xquery.xdm.Stream)4 Type (org.brackit.xquery.xdm.Type)4 SirixNodeKeyStream (org.sirix.xquery.stream.SirixNodeKeyStream)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Int32 (org.brackit.xquery.atomic.Int32)3 Str (org.brackit.xquery.atomic.Str)3 Iter (org.brackit.xquery.xdm.Iter)3 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)3