Search in sources :

Example 1 with DBCollection

use of org.sirix.xquery.node.DBCollection in project sirix by sirixdb.

the class Load 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 resources = args[2];
        if (resources == null)
            throw new QueryException(new QNm("No sequence of resources 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();
        DBCollection coll;
        if (createNew) {
            coll = (DBCollection) create(store, collName, resName, resources);
        } else {
            try {
                coll = (DBCollection) store.lookup(collName);
                add(store, coll, resName, resources);
            } catch (DocumentException e) {
                // collection does not exist
                coll = (DBCollection) create(store, collName, resName, resources);
            }
        }
        return coll;
    } catch (final Exception e) {
        throw new QueryException(new QNm(e.getMessage()), e);
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DBCollection(org.sirix.xquery.node.DBCollection) QueryException(org.brackit.xquery.QueryException) DocumentException(org.brackit.xquery.xdm.DocumentException) Sequence(org.brackit.xquery.xdm.Sequence) DBStore(org.sirix.xquery.node.DBStore) QueryException(org.brackit.xquery.QueryException) DocumentException(org.brackit.xquery.xdm.DocumentException) IOException(java.io.IOException)

Example 2 with DBCollection

use of org.sirix.xquery.node.DBCollection 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);
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) DBCollection(org.sirix.xquery.node.DBCollection) QueryException(org.brackit.xquery.QueryException) DocumentException(org.brackit.xquery.xdm.DocumentException) Sequence(org.brackit.xquery.xdm.Sequence) DBStore(org.sirix.xquery.node.DBStore) QueryException(org.brackit.xquery.QueryException) DocumentException(org.brackit.xquery.xdm.DocumentException) IOException(java.io.IOException)

Example 3 with DBCollection

use of org.sirix.xquery.node.DBCollection 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)

Aggregations

QueryException (org.brackit.xquery.QueryException)3 QNm (org.brackit.xquery.atomic.QNm)3 DBCollection (org.sirix.xquery.node.DBCollection)3 IOException (java.io.IOException)2 DocumentException (org.brackit.xquery.xdm.DocumentException)2 Sequence (org.brackit.xquery.xdm.Sequence)2 DBStore (org.sirix.xquery.node.DBStore)2 Str (org.brackit.xquery.atomic.Str)1