Search in sources :

Example 6 with Atomic

use of org.brackit.xquery.atomic.Atomic 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

Atomic (org.brackit.xquery.atomic.Atomic)6 QueryException (org.brackit.xquery.QueryException)4 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 BaseIter (org.brackit.xquery.sequence.BaseIter)2 LazySequence (org.brackit.xquery.sequence.LazySequence)2 Item (org.brackit.xquery.xdm.Item)2 Stream (org.brackit.xquery.xdm.Stream)2 Type (org.brackit.xquery.xdm.Type)2 AnyNodeType (org.brackit.xquery.xdm.type.AnyNodeType)2 AtomicType (org.brackit.xquery.xdm.type.AtomicType)2 SequenceType (org.brackit.xquery.xdm.type.SequenceType)2 IndexType (org.sirix.index.IndexType)2 SearchMode (org.sirix.index.SearchMode)2 PCRCollectorImpl (org.sirix.index.path.PCRCollectorImpl)2 SirixNodeKeyStream (org.sirix.xquery.stream.SirixNodeKeyStream)2 Iterator (java.util.Iterator)1