Search in sources :

Example 1 with Int32

use of org.brackit.xquery.atomic.Int32 in project sirix by sirixdb.

the class FindCASIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode doc = (DBNode) args[0];
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final QNm name = new QNm(Namespaces.XS_NSURI, ((Str) args[1]).stringValue());
    final Type type = sctx.getTypes().resolveAtomicType(name);
    final Path<QNm> path = Path.parse(((Str) args[2]).stringValue());
    final Optional<IndexDef> indexDef = controller.getIndexes().findCASIndex(path, type);
    if (indexDef.isPresent())
        return new Int32(indexDef.get().getID());
    return new Int32(-1);
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) Type(org.brackit.xquery.xdm.Type) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Int32(org.brackit.xquery.atomic.Int32) IndexController(org.sirix.access.IndexController) IndexDef(org.sirix.index.IndexDef)

Example 2 with Int32

use of org.brackit.xquery.atomic.Int32 in project sirix by sirixdb.

the class FindPathIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode doc = (DBNode) args[0];
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final Path<QNm> path = Path.parse(((Str) args[1]).stringValue());
    final Optional<IndexDef> indexDef = controller.getIndexes().findPathIndex(path);
    if (indexDef.isPresent())
        return new Int32(indexDef.get().getID());
    return new Int32(-1);
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Int32(org.brackit.xquery.atomic.Int32) IndexController(org.sirix.access.IndexController) IndexDef(org.sirix.index.IndexDef)

Example 3 with Int32

use of org.brackit.xquery.atomic.Int32 in project sirix by sirixdb.

the class FindNameIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode doc = (DBNode) args[0];
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final QNm qnm = (QNm) Cast.cast(sctx, (Atomic) args[1], Type.QNM, false);
    final Optional<IndexDef> indexDef = controller.getIndexes().findNameIndex(qnm);
    if (indexDef.isPresent())
        return new Int32(indexDef.get().getID());
    return new Int32(-1);
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Int32(org.brackit.xquery.atomic.Int32) IndexController(org.sirix.access.IndexController) Atomic(org.brackit.xquery.atomic.Atomic) IndexDef(org.sirix.index.IndexDef)

Aggregations

QueryException (org.brackit.xquery.QueryException)3 Int32 (org.brackit.xquery.atomic.Int32)3 QNm (org.brackit.xquery.atomic.QNm)3 IndexController (org.sirix.access.IndexController)3 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 IndexDef (org.sirix.index.IndexDef)3 DBNode (org.sirix.xquery.node.DBNode)3 Atomic (org.brackit.xquery.atomic.Atomic)1 Type (org.brackit.xquery.xdm.Type)1