use of org.exist.source.StringSource in project exist by eXist-db.
the class LowLevelTextTest method setUp.
@Before
public void setUp() throws DatabaseConfigurationException, EXistException, XPathException, PermissionDeniedException, IOException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
xqueryPool = pool.getXQueryPool();
stringSource = new StringSource(TEST_XQUERY_SOURCE);
final XQuery xquery = pool.getXQueryService();
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
preCompiledXQuery = xquery.compile(context, stringSource);
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class LowLevelTextTest method borrowCompiledXQueryNewStringSource2.
/**
* test with a new StringSource object having same content
*/
@Test
public void borrowCompiledXQueryNewStringSource2() throws PermissionDeniedException {
xqueryPool.returnCompiledXQuery(stringSource, preCompiledXQuery);
StringSource localStringSource = new StringSource(TEST_XQUERY_SOURCE);
callAndTestBorrowCompiledXQuery(localStringSource);
callAndTestBorrowCompiledXQuery(localStringSource);
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class ConstructedNodesRecoveryTest method constructedNodeQuery.
/**
* Performs a query against constructed nodes, with the option of forcefully corrupting the database
*
* @param forceCorruption Should the database be forcefully corrupted
*/
private void constructedNodeQuery(boolean forceCorruption) throws EXistException, DatabaseConfigurationException, LockException, SAXException, PermissionDeniedException, IOException, XPathException {
BrokerPool.FORCE_CORRUPTION = forceCorruption;
BrokerPool pool = startDb();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
TransactionManager transact = pool.getTransactionManager();
assertNotNull(transact);
// only store the documents the first time
// store a first test document
storeTestDocument(broker, transact, "testcr1.xml");
// store a second test document
storeTestDocument(broker, transact, "testcr2.xml");
// create some child collections in TEMP collection
createTempChildCollection(broker, transact, "testchild1");
createTempChildCollection(broker, transact, "testchild2");
// execute an xquery
XQuery service = pool.getXQueryService();
assertNotNull(service);
CompiledXQuery compiled = service.compile(new XQueryContext(pool), new StringSource(xquery));
assertNotNull(compiled);
Sequence result = service.execute(broker, compiled, null);
assertNotNull(result);
assertEquals(expectedResults.length, result.getItemCount());
for (int i = 0; i < result.getItemCount(); i++) {
assertEquals(expectedResults[i], (String) result.itemAt(i).getStringValue());
}
// read the first test document
testDocumentIsValid(broker, transact, "testcr1.xml");
// read the second test document
testDocumentIsValid(broker, transact, "testcr1.xml");
// test the child collections exist
testTempChildCollectionExists(broker, transact, "testchild1");
testTempChildCollectionExists(broker, transact, "testchild2");
pool.getJournalManager().get().flush(true, false);
}
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class DBUtils method xquery.
public static ResourceSet xquery(final Collection collection, final String xquery) throws XMLDBException {
final EXistXQueryService service = getXQueryService(collection);
final Source source = new StringSource(xquery);
return service.execute(source);
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class EmbeddedBinariesTest method executeXQuery.
@Override
protected QueryResultAccessor<Sequence, IOException> executeXQuery(final String query) throws Exception {
final Source source = new StringSource(query);
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
final XQueryPool pool = brokerPool.getXQueryPool();
final XQuery xquery = brokerPool.getXQueryService();
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()))) {
final CompiledXQuery existingCompiled = pool.borrowCompiledXQuery(broker, source);
final XQueryContext context;
final CompiledXQuery compiled;
if (existingCompiled == null) {
context = new XQueryContext(brokerPool);
compiled = xquery.compile(context, source);
} else {
context = existingCompiled.getContext();
context.prepareForReuse();
compiled = existingCompiled;
}
final Sequence results = xquery.execute(broker, compiled, null);
return consumer2E -> {
try {
// context.runCleanupTasks(); //TODO(AR) shows the ordering issue with binary values (see comment below)
consumer2E.accept(results);
} finally {
// TODO(AR) performing #runCleanupTasks causes the stream to be closed, so if we do so before we are finished with the results, serialization fails.
context.runCleanupTasks();
pool.returnCompiledXQuery(source, compiled);
}
};
}
}
Aggregations