Search in sources :

Example 16 with SequenceIterator

use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.

the class IndexerTest2 method executeQuery.

private String executeQuery() throws EXistException, PermissionDeniedException, SAXException, XPathException, IOException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final StringWriter out = new StringWriter()) {
        final XQuery xquery = broker.getBrokerPool().getXQueryService();
        final Sequence result = xquery.execute(broker, XQUERY, null);
        final Properties props = new Properties();
        props.setProperty(OutputKeys.INDENT, "yes");
        final SAXSerializer serializer = new SAXSerializer(out, props);
        serializer.startDocument();
        for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
            final Item next = i.nextItem();
            next.toSAX(broker, serializer, props);
        }
        serializer.endDocument();
        return out.toString();
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) StringWriter(java.io.StringWriter) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) Properties(java.util.Properties) SAXSerializer(org.exist.util.serializer.SAXSerializer) BrokerPool(org.exist.storage.BrokerPool)

Example 17 with SequenceIterator

use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.

the class IndexerTest method store_and_retrieve_ws_mixed_content_value.

private String store_and_retrieve_ws_mixed_content_value(final boolean preserve, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
    store_preserve_ws_mixed_content_value(preserve, typeXml);
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final XQuery xquery = pool.getXQueryService();
        final Sequence result = xquery.execute(broker, typeXquery, null);
        try (final StringWriter out = new StringWriter()) {
            final Properties props = new Properties();
            props.setProperty(OutputKeys.INDENT, "yes");
            final SAXSerializer serializer = new SAXSerializer(out, props);
            serializer.startDocument();
            for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
                final Item next = i.nextItem();
                next.toSAX(broker, serializer, props);
            }
            serializer.endDocument();
            return out.toString();
        }
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) StringWriter(java.io.StringWriter) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) Properties(java.util.Properties) SAXSerializer(org.exist.util.serializer.SAXSerializer) BrokerPool(org.exist.storage.BrokerPool)

Example 18 with SequenceIterator

use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.

the class IndexerTest3 method store_and_retrieve_suppress_type.

private String store_and_retrieve_suppress_type(final String type, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
    store_suppress_type(type, typeXml);
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final StringWriter out = new StringWriter()) {
        final XQuery xquery = pool.getXQueryService();
        final Sequence result = xquery.execute(broker, typeXquery, null);
        final Properties props = new Properties();
        props.setProperty(OutputKeys.INDENT, "no");
        final SAXSerializer serializer = new SAXSerializer(out, props);
        serializer.startDocument();
        for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
            final Item next = i.nextItem();
            next.toSAX(broker, serializer, props);
        }
        serializer.endDocument();
        return out.toString();
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) StringWriter(java.io.StringWriter) SequenceIterator(org.exist.xquery.value.SequenceIterator) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) Properties(java.util.Properties) SAXSerializer(org.exist.util.serializer.SAXSerializer) BrokerPool(org.exist.storage.BrokerPool)

Example 19 with SequenceIterator

use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.

the class RangeSequenceTest method iterate_skip_loop.

@Test
public void iterate_skip_loop() {
    final SequenceIterator it = rangeSequence.iterate();
    assertEquals(99, it.skippable());
    assertEquals(10, it.skip(10));
    assertEquals(89, it.skippable());
    int count = 0;
    while (it.hasNext()) {
        it.nextItem();
        count++;
    }
    assertEquals(89, count);
}
Also used : SequenceIterator(org.exist.xquery.value.SequenceIterator) Test(org.junit.Test)

Example 20 with SequenceIterator

use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.

the class RangeSequenceTest method iterateInReverse_loop.

@Test
public void iterateInReverse_loop() {
    final SequenceIterator it = rangeSequence.iterateInReverse();
    int count = 0;
    while (it.hasNext()) {
        it.nextItem();
        count++;
    }
    assertEquals(99, count);
}
Also used : SequenceIterator(org.exist.xquery.value.SequenceIterator) Test(org.junit.Test)

Aggregations

SequenceIterator (org.exist.xquery.value.SequenceIterator)75 Sequence (org.exist.xquery.value.Sequence)40 Item (org.exist.xquery.value.Item)35 XPathException (org.exist.xquery.XPathException)19 ValueSequence (org.exist.xquery.value.ValueSequence)16 Test (org.junit.Test)16 SAXException (org.xml.sax.SAXException)11 XQuery (org.exist.xquery.XQuery)10 Collator (com.ibm.icu.text.Collator)9 AtomicValue (org.exist.xquery.value.AtomicValue)9 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)8 DBBroker (org.exist.storage.DBBroker)8 NumericValue (org.exist.xquery.value.NumericValue)8 Properties (java.util.Properties)7 StringWriter (java.io.StringWriter)6 EXistException (org.exist.EXistException)6 NodeProxy (org.exist.dom.persistent.NodeProxy)6 NodeSet (org.exist.dom.persistent.NodeSet)6 BrokerPool (org.exist.storage.BrokerPool)6 IOException (java.io.IOException)5