use of org.exist.source.ClassLoaderSource in project exist by eXist-db.
the class DatabaseResources method executeQuery.
public Sequence executeQuery(String queryPath, Map<String, String> params, Subject user) {
final String namespace = params.get(TARGETNAMESPACE);
final String publicId = params.get(PUBLICID);
final String catalogPath = params.get(CATALOG);
final String collection = params.get(COLLECTION);
if (logger.isDebugEnabled()) {
logger.debug("collection={} namespace={} publicId={} catalogPath={}", collection, namespace, publicId, catalogPath);
}
Sequence result = null;
try (final DBBroker broker = brokerPool.get(Optional.ofNullable(user))) {
final XQuery xquery = brokerPool.getXQueryService();
final XQueryContext context = new XQueryContext(brokerPool);
if (collection != null) {
context.declareVariable(COLLECTION, collection);
}
if (namespace != null) {
context.declareVariable(TARGETNAMESPACE, namespace);
}
if (publicId != null) {
context.declareVariable(PUBLICID, publicId);
}
if (catalogPath != null) {
context.declareVariable(CATALOG, catalogPath);
}
CompiledXQuery compiled = xquery.compile(context, new ClassLoaderSource(queryPath));
result = xquery.execute(broker, compiled, null);
} catch (final EXistException | XPathException | IOException | PermissionDeniedException ex) {
logger.error("Problem executing xquery", ex);
result = null;
}
return result;
}
use of org.exist.source.ClassLoaderSource in project exist by eXist-db.
the class XMLTestRunner method run.
@Override
public void run(final RunNotifier notifier) {
try {
final String pkgName = getClass().getPackage().getName().replace('.', '/');
final Source query = new ClassLoaderSource(pkgName + "/xml-test-runner.xq");
final List<java.util.function.Function<XQueryContext, Tuple2<String, Object>>> externalVariableDeclarations = Arrays.asList(context -> new Tuple2<>("doc", doc), context -> new Tuple2<>("id", Sequence.EMPTY_SEQUENCE), // set callback functions for notifying junit!
context -> new Tuple2<>("test-ignored-function", new FunctionReference(new FunctionCall(context, new ExtTestIgnoredFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-started-function", new FunctionReference(new FunctionCall(context, new ExtTestStartedFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-failure-function", new FunctionReference(new FunctionCall(context, new ExtTestFailureFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-assumption-failed-function", new FunctionReference(new FunctionCall(context, new ExtTestAssumptionFailedFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-error-function", new FunctionReference(new FunctionCall(context, new ExtTestErrorFunction(context, getSuiteName(), notifier)))), context -> new Tuple2<>("test-finished-function", new FunctionReference(new FunctionCall(context, new ExtTestFinishedFunction(context, getSuiteName(), notifier)))));
// NOTE: at this stage EXIST_EMBEDDED_SERVER_CLASS_INSTANCE in XSuite will be usable
final BrokerPool brokerPool = XSuite.EXIST_EMBEDDED_SERVER_CLASS_INSTANCE.getBrokerPool();
executeQuery(brokerPool, query, externalVariableDeclarations);
} catch (final DatabaseConfigurationException | IOException | EXistException | PermissionDeniedException | XPathException e) {
// TODO(AR) what to do here?
throw new RuntimeException(e);
}
}
use of org.exist.source.ClassLoaderSource in project exist by eXist-db.
the class XQueryTestRunner method run.
@Override
public void run(final RunNotifier notifier) {
try {
final String pkgName = getClass().getPackage().getName().replace('.', '/');
final Source query = new ClassLoaderSource(pkgName + "/xquery-test-runner.xq");
final URI testModuleUri = path.toAbsolutePath().toUri();
final String suiteName = getSuiteName();
final List<java.util.function.Function<XQueryContext, Tuple2<String, Object>>> externalVariableDeclarations = Arrays.asList(context -> new Tuple2<>("test-module-uri", new AnyURIValue(testModuleUri)), // set callback functions for notifying junit!
context -> new Tuple2<>("test-ignored-function", new FunctionReference(new FunctionCall(context, new ExtTestIgnoredFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-started-function", new FunctionReference(new FunctionCall(context, new ExtTestStartedFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-failure-function", new FunctionReference(new FunctionCall(context, new ExtTestFailureFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-assumption-failed-function", new FunctionReference(new FunctionCall(context, new ExtTestAssumptionFailedFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-error-function", new FunctionReference(new FunctionCall(context, new ExtTestErrorFunction(context, suiteName, notifier)))), context -> new Tuple2<>("test-finished-function", new FunctionReference(new FunctionCall(context, new ExtTestFinishedFunction(context, suiteName, notifier)))));
// NOTE: at this stage EXIST_EMBEDDED_SERVER_CLASS_INSTANCE in XSuite will be usable
final BrokerPool brokerPool = XSuite.EXIST_EMBEDDED_SERVER_CLASS_INSTANCE.getBrokerPool();
executeQuery(brokerPool, query, externalVariableDeclarations);
} catch (final DatabaseConfigurationException | IOException | EXistException | PermissionDeniedException | XPathException e) {
// TODO(AR) what to do here?
throw new RuntimeException(e);
}
}
Aggregations