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