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);
}
}
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);
}
}
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);
}
Aggregations