Search in sources :

Example 1 with ClassLoaderSource

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;
}
Also used : ClassLoaderSource(org.exist.source.ClassLoaderSource) DBBroker(org.exist.storage.DBBroker) XPathException(org.exist.xquery.XPathException) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQueryContext(org.exist.xquery.XQueryContext) PermissionDeniedException(org.exist.security.PermissionDeniedException) Sequence(org.exist.xquery.value.Sequence) EXistException(org.exist.EXistException) IOException(java.io.IOException)

Example 2 with ClassLoaderSource

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);
    }
}
Also used : ClassLoaderSource(org.exist.source.ClassLoaderSource) XPathException(org.exist.xquery.XPathException) IOException(java.io.IOException) EXistException(org.exist.EXistException) ClassLoaderSource(org.exist.source.ClassLoaderSource) Source(org.exist.source.Source) InputSource(org.xml.sax.InputSource) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) FunctionReference(org.exist.xquery.value.FunctionReference) PermissionDeniedException(org.exist.security.PermissionDeniedException) FunctionCall(org.exist.xquery.FunctionCall) BrokerPool(org.exist.storage.BrokerPool)

Example 3 with ClassLoaderSource

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);
    }
}
Also used : URI(java.net.URI) ClassLoaderSource(org.exist.source.ClassLoaderSource) Source(org.exist.source.Source) FileSource(org.exist.source.FileSource) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) FunctionReference(org.exist.xquery.value.FunctionReference) ClassLoaderSource(org.exist.source.ClassLoaderSource) AnyURIValue(org.exist.xquery.value.AnyURIValue) IOException(java.io.IOException) EXistException(org.exist.EXistException) java.util(java.util) PermissionDeniedException(org.exist.security.PermissionDeniedException) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

IOException (java.io.IOException)3 EXistException (org.exist.EXistException)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 ClassLoaderSource (org.exist.source.ClassLoaderSource)3 Source (org.exist.source.Source)2 BrokerPool (org.exist.storage.BrokerPool)2 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)2 XPathException (org.exist.xquery.XPathException)2 FunctionReference (org.exist.xquery.value.FunctionReference)2 URI (java.net.URI)1 java.util (java.util)1 FileSource (org.exist.source.FileSource)1 DBBroker (org.exist.storage.DBBroker)1 CompiledXQuery (org.exist.xquery.CompiledXQuery)1 FunctionCall (org.exist.xquery.FunctionCall)1 XQuery (org.exist.xquery.XQuery)1 XQueryContext (org.exist.xquery.XQueryContext)1 AnyURIValue (org.exist.xquery.value.AnyURIValue)1 Sequence (org.exist.xquery.value.Sequence)1 InputSource (org.xml.sax.InputSource)1