Search in sources :

Example 6 with Str

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

the class Doc method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    if (args.length < 2 || args.length > 4) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBCollection col = (DBCollection) ctx.getStore().lookup(((Str) args[0]).stringValue());
    if (col == null) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final String expResName = ((Str) args[1]).stringValue();
    final int revision = FunUtil.getInt(args, 2, "revision", -1, null, false);
    final boolean updatable = FunUtil.getBoolean(args, 3, "updatable", false, false);
    return col.getDocument(revision, expResName, updatable);
}
Also used : Str(org.brackit.xquery.atomic.Str) QNm(org.brackit.xquery.atomic.QNm) DBCollection(org.sirix.xquery.node.DBCollection) QueryException(org.brackit.xquery.QueryException)

Example 7 with Str

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

the class CreateCASIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, 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()));
    }
    Type type = null;
    if (args.length > 1 && args[1] != null) {
        final QNm name = new QNm(Namespaces.XS_NSURI, ((Str) args[1]).stringValue());
        type = sctx.getTypes().resolveAtomicType(name);
    }
    final Set<Path<QNm>> paths = new HashSet<>();
    if (args.length == 3 && 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.createCASIdxDef(false, Optional.fromNullable(type), paths, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.CAS));
    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) Type(org.brackit.xquery.xdm.Type) IndexType(org.sirix.index.IndexType) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) HashSet(java.util.HashSet)

Example 8 with Str

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

Aggregations

Str (org.brackit.xquery.atomic.Str)8 QueryException (org.brackit.xquery.QueryException)4 SirixIOException (org.sirix.exception.SirixIOException)4 QNm (org.brackit.xquery.atomic.QNm)3 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 CASValue (org.sirix.index.avltree.keyvalue.CASValue)3 DBNode (org.sirix.xquery.node.DBNode)3 HashSet (java.util.HashSet)2 Path (org.brackit.xquery.util.path.Path)2 PathException (org.brackit.xquery.util.path.PathException)2 Item (org.brackit.xquery.xdm.Item)2 Iter (org.brackit.xquery.xdm.Iter)2 IndexController (org.sirix.access.IndexController)2 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)2 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)2 IndexDef (org.sirix.index.IndexDef)2 NodeReferences (org.sirix.index.avltree.keyvalue.NodeReferences)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1