Search in sources :

Example 21 with StringSource

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);
}
Also used : CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) XQueryContext(org.exist.xquery.XQueryContext) StringSource(org.exist.source.StringSource)

Example 22 with 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);
}
Also used : StringSource(org.exist.source.StringSource)

Example 23 with StringSource

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);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) StringSource(org.exist.source.StringSource) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

Example 24 with StringSource

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);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) StringSource(org.exist.source.StringSource)

Example 25 with StringSource

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);
            }
        };
    }
}
Also used : XQueryPool(org.exist.storage.XQueryPool) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) ManagedCollectionLock(org.exist.storage.lock.ManagedCollectionLock) StringInputSource(org.exist.util.StringInputSource) org.exist.xquery.value(org.exist.xquery.value) IOException(java.io.IOException) ExistEmbeddedServer(org.exist.test.ExistEmbeddedServer) MimeType(org.exist.util.MimeType) Source(org.exist.source.Source) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream) DBBroker(org.exist.storage.DBBroker) Collection(org.exist.collections.Collection) XmldbURI(org.exist.xmldb.XmldbURI) Optional(java.util.Optional) XQueryPool(org.exist.storage.XQueryPool) Lock(org.exist.storage.lock.Lock) ClassRule(org.junit.ClassRule) XQueryContext(org.exist.xquery.XQueryContext) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) DBBroker(org.exist.storage.DBBroker) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQueryContext(org.exist.xquery.XQueryContext) StringSource(org.exist.source.StringSource) StringSource(org.exist.source.StringSource) StringInputSource(org.exist.util.StringInputSource) Source(org.exist.source.Source) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

StringSource (org.exist.source.StringSource)59 Source (org.exist.source.Source)53 Txn (org.exist.storage.txn.Txn)41 BrokerPool (org.exist.storage.BrokerPool)40 DBBroker (org.exist.storage.DBBroker)40 Sequence (org.exist.xquery.value.Sequence)40 Test (org.junit.Test)37 StringInputSource (org.exist.util.StringInputSource)32 Collection (org.exist.collections.Collection)8 DBSource (org.exist.source.DBSource)8 IOException (java.io.IOException)7 Map (java.util.Map)7 EXistException (org.exist.EXistException)7 XmldbURI (org.exist.xmldb.XmldbURI)7 Element (org.w3c.dom.Element)7 InputSource (org.xml.sax.InputSource)7 Diff (org.xmlunit.diff.Diff)7 XQueryPool (org.exist.storage.XQueryPool)6 XQueryContext (org.exist.xquery.XQueryContext)6 IntegerValue (org.exist.xquery.value.IntegerValue)6