Search in sources :

Example 21 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class XQueryTestRunner method extractTestInfo.

private static XQueryTestInfo extractTestInfo(final Path path) throws InitializationError {
    try {
        final Configuration config = getConfiguration();
        final XQueryContext xqueryContext = new XQueryContext(config);
        final Source xquerySource = new FileSource(path, UTF_8, false);
        final XQuery xquery = new XQuery();
        final CompiledXQuery compiledXQuery = xquery.compile(xqueryContext, xquerySource);
        String moduleNsPrefix = null;
        String moduleNsUri = null;
        final List<XQueryTestInfo.TestFunctionDef> testFunctions = new ArrayList<>();
        final Iterator<UserDefinedFunction> localFunctions = compiledXQuery.getContext().localFunctions();
        while (localFunctions.hasNext()) {
            final UserDefinedFunction localFunction = localFunctions.next();
            final FunctionSignature localFunctionSignature = localFunction.getSignature();
            String testName = null;
            boolean isTest = false;
            final Annotation[] annotations = localFunctionSignature.getAnnotations();
            if (annotations != null) {
                for (final Annotation annotation : annotations) {
                    final QName annotationName = annotation.getName();
                    if (annotationName.getNamespaceURI().equals(XQSUITE_NAMESPACE)) {
                        if (annotationName.getLocalPart().startsWith("assert")) {
                            isTest = true;
                            if (testName != null) {
                                break;
                            }
                        } else if (annotationName.getLocalPart().equals("name")) {
                            final LiteralValue[] annotationValues = annotation.getValue();
                            if (annotationValues != null && annotationValues.length > 0) {
                                testName = annotationValues[0].getValue().getStringValue();
                                if (isTest) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (isTest) {
                if (testName == null) {
                    testName = localFunctionSignature.getName().getLocalPart();
                }
                if (moduleNsPrefix == null) {
                    moduleNsPrefix = localFunctionSignature.getName().getPrefix();
                }
                if (moduleNsUri == null) {
                    moduleNsUri = localFunctionSignature.getName().getNamespaceURI();
                }
                testFunctions.add(new XQueryTestInfo.TestFunctionDef(testName));
            }
        }
        return new XQueryTestInfo(moduleNsPrefix, moduleNsUri, testFunctions);
    } catch (final DatabaseConfigurationException | IOException | PermissionDeniedException | XPathException e) {
        throw new InitializationError(e);
    }
}
Also used : Configuration(org.exist.util.Configuration) InitializationError(org.junit.runners.model.InitializationError) ClassLoaderSource(org.exist.source.ClassLoaderSource) Source(org.exist.source.Source) FileSource(org.exist.source.FileSource) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) QName(org.exist.dom.QName) FileSource(org.exist.source.FileSource) IOException(java.io.IOException) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 22 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class SymbolTableTest method createSymbolTable.

private final SymbolTable createSymbolTable(final Path dir) throws BrokerPoolServiceException {
    final SymbolTable symbolTable = new SymbolTable();
    final Configuration configuration = createMock(Configuration.class);
    expect(configuration.getProperty(BrokerPool.PROPERTY_DATA_DIR)).andReturn(dir);
    replay(configuration);
    symbolTable.configure(configuration);
    symbolTable.prepare(null);
    return symbolTable;
}
Also used : Configuration(org.exist.util.Configuration)

Example 23 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class XQueryWatchDog method configureDefaults.

private void configureDefaults() {
    final Configuration conf = context.getConfiguration();
    Object option = conf.getProperty(PROPERTY_QUERY_TIMEOUT);
    if (option != null) {
        timeout = (Long) option;
    }
    if (timeout <= 0) {
        timeout = Long.MAX_VALUE;
    }
    option = conf.getProperty(PROPERTY_OUTPUT_SIZE_LIMIT);
    if (option != null) {
        maxNodesLimit = (Integer) option;
    }
}
Also used : Configuration(org.exist.util.Configuration)

Example 24 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class ExportGUI method startDB.

protected boolean startDB() {
    if (pool != null) {
        return true;
    }
    final Path confFile = Paths.get(dbConfig.getText()).normalize();
    if (!(Files.exists(confFile) && Files.isReadable(confFile))) {
        JOptionPane.showMessageDialog(this, "The selected database configuration file " + confFile.toAbsolutePath().toString() + " does not exist or is not readable.", "Configuration Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    try {
        final Configuration config = new Configuration(confFile.toAbsolutePath().toString(), Optional.empty());
        BrokerPool.configure(1, 5, config);
        pool = BrokerPool.getInstance();
        return true;
    } catch (final Exception e) {
        JOptionPane.showMessageDialog(this, "Could not start the database instance. Please remember\n" + "that this tool tries to launch an embedded db instance. No other db instance should\n" + "be running on the same data.", "DB Error", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        System.err.println("ERROR: Failed to open database: " + e.getMessage());
    }
    return false;
}
Also used : Path(java.nio.file.Path) Configuration(org.exist.util.Configuration) PermissionDeniedException(org.exist.security.PermissionDeniedException) StartException(org.exist.start.StartException) TerminatedException(org.exist.xquery.TerminatedException) EXistException(org.exist.EXistException) IOException(java.io.IOException)

Example 25 with Configuration

use of org.exist.util.Configuration in project exist by eXist-db.

the class ExportMain method startDB.

protected static BrokerPool startDB(final Optional<Path> configFile) {
    try {
        final Configuration config;
        if (configFile.isPresent()) {
            config = new Configuration(configFile.get().toAbsolutePath().toString(), Optional.empty());
        } else {
            config = new Configuration();
        }
        config.setProperty(BrokerPool.PROPERTY_EXPORT_ONLY, Boolean.TRUE);
        BrokerPool.configure(1, 5, config);
        return (BrokerPool.getInstance());
    } catch (final DatabaseConfigurationException | EXistException e) {
        System.err.println("ERROR: Failed to open database: " + e.getMessage());
    }
    return (null);
}
Also used : Configuration(org.exist.util.Configuration) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) EXistException(org.exist.EXistException)

Aggregations

Configuration (org.exist.util.Configuration)30 Test (org.junit.Test)10 Path (java.nio.file.Path)9 EXistException (org.exist.EXistException)8 IOException (java.io.IOException)7 BrokerPool (org.exist.storage.BrokerPool)6 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)6 InputStream (java.io.InputStream)4 Scheduler (org.exist.scheduler.Scheduler)4 DBBroker (org.exist.storage.DBBroker)4 Paths (java.nio.file.Paths)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 Subject (org.exist.security.Subject)3 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 Database (org.exist.Database)2 AuthenticationException (org.exist.security.AuthenticationException)2 SecurityManager (org.exist.security.SecurityManager)2 Ignore (org.junit.Ignore)2