Package org.exist.xquery

Examples of org.exist.xquery.XQuery


        DBBroker broker = null;
        try {
            pool = BrokerPool.getInstance();
            assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            String query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:transform((//gml:Polygon)[1], 'EPSG:4326')";
            Sequence seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:getWKT((//gml:Polygon)[1])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:buffer((//gml:Polygon)[1], 100)";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:buffer((//gml:Polygon)[1], 100, 1)";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:getBbox((//gml:Polygon)[1])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:convexHull((//gml:Polygon)[1])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:boundary((//gml:Polygon)[1])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:intersection((//gml:Polygon)[1], (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:union((//gml:Polygon)[1], (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:difference((//gml:Polygon)[1], (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:symetricDifference((//gml:Polygon)[1], (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
           
            //Tests with empty sequences
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:transform((), 'EPSG:4326')";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:getWKT(())";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:buffer((), 100)";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:buffer((), 100, 1)";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:getBbox(())";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:convexHull(())";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:boundary(())"
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:union((), ())"
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:union((//gml:Polygon)[1], ())";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 1);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:union((), (//gml:Polygon)[1])"
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 1);

            //In-memory tests
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:transform(" + IN_MEMORY_GML + ", 'EPSG:4326')";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:buffer(" + IN_MEMORY_GML + ", 100)";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:buffer(" + IN_MEMORY_GML + ", 100, 1)";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:getBbox(" + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:convexHull(" + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:boundary(" + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:intersection(" + IN_MEMORY_GML + ", (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:union(" + IN_MEMORY_GML + ", (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:difference(" + IN_MEMORY_GML + ", (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:symetricDifference(" + IN_MEMORY_GML + ", (//gml:Polygon)[2])";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:intersection((//gml:Polygon)[1]," + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:union((//gml:Polygon)[1]," + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:difference((//gml:Polygon)[1]," + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "spatial:symetricDifference((//gml:Polygon)[1]," + IN_MEMORY_GML + ")";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() > 0);
           
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here


        DBBroker broker = null;
        try {
            pool = BrokerPool.getInstance();
            assertNotNull(pool);
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            String query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "(# exist:force-index-use #) { " +
                "spatial:getArea((//gml:Polygon)[1]) " +
                "}";
            Sequence seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);   
            assertTrue(seq.getItemCount() == 1);
            String area1 = seq.toString();
            query =  "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "update value (//gml:Polygon)[1]/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates " +
                "(: strip decimals :) " +
                "with fn:replace((//gml:Polygon)[1], '(\\d+).(\\d+)', '$1')";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 0);
            query = "import module namespace spatial='http://exist-db.org/xquery/spatial' " +
                "at 'java:org.exist.examples.indexing.spatial.module.SpatialModule'; " +
                "declare namespace gml = 'http://www.opengis.net/gml'; " +
                "(# exist:force-index-use #) { " +
                "spatial:getArea((//gml:Polygon)[1])" +
                "}";
            seq = xquery.execute(query, null, AccessContext.TEST);
            assertNotNull(seq);
            assertTrue(seq.getItemCount() == 1);
            String area2 = seq.toString();
            assertFalse(area1.equals(area2));
        } catch (Exception e) {
View Full Code Here

                LOG.info("pathURI " + pathUri );
                return true;
            }


            XQuery xquery = broker.getXQueryService();

            if (xquery == null) {
                LOG.error("broker unable to retrieve XQueryService");
                return false;
            }

            XQueryContext context = xquery.newContext(AccessContext.REST);

            CompiledXQuery compiled = xquery.compile(context, source);

            Properties outputProperties = new Properties();

            Sequence result = xquery.execute(compiled, null, outputProperties);
            LOG.info("XQuery execution results: " + result.toString());

        } catch (Exception e) {
            LOG.error("Exception while executing OpenID registration script for " + principal.getMetadataValue(AXSchemaType.ALIAS_USERNAME), e);
            return false;
View Full Code Here

            assertNotNull(broker);

            checkIndex(docs, broker, new QName[] { new QName("head", "") }, "TITLE", 1);
            checkIndex(docs, broker, new QName[] { new QName("p", "") }, "uppercase", 1);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("/section[ft:query(p, 'UPPERCASE')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            seq = xquery.execute("/section[ft:query(head, 'TITLE')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            seq = xquery.execute("/section[ft:query(head, 'title')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(0, seq.getItemCount());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
View Full Code Here

            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//LINE[ft:query(., 'bark')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(6, seq.getItemCount());

            System.out.println("Removing document r_and_j.xml");
            root.removeXMLResource(transaction, broker, XmldbURI.create("r_and_j.xml"));
            transact.commit(transaction);

            seq = xquery.execute("//LINE[ft:query(., 'bark')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(3, seq.getItemCount());

            transaction = transact.beginTransaction();
            assertNotNull(transaction);
            System.out.println("Removing document hamlet.xml");
            root.removeXMLResource(transaction, broker, XmldbURI.create("hamlet.xml"));
            transact.commit(transaction);

            seq = xquery.execute("//LINE[ft:query(., 'bark')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            System.out.println("Test PASSED.");
        } catch (Exception e) {
View Full Code Here

            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//SPEECH[ft:query(LINE, 'love')]", null, AccessContext.TEST);
            assertNotNull(seq);
            System.out.println("Found: " + seq.getItemCount());
            assertEquals(166, seq.getItemCount());

            System.out.println("Removing collection");
View Full Code Here

            checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 1);
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);
            checkIndex(docs, broker, new QName[] { new QName("condition", "") }, null, 2);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
View Full Code Here

            Occurrences occur[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 1);
            assertEquals("chair", occur[0].getTerm());
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            // Append to root node
            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
View Full Code Here

            Occurrences occur[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 1);
            assertEquals("chair", occur[0].getTerm());
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            // Update element content
            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
View Full Code Here

            Occurrences occur[] = checkIndex(docs, broker, new QName[] { new QName("description", "") }, "chair", 1);
            assertEquals("chair", occur[0].getTerm());
            checkIndex(docs, broker, new QName[] { new QName("item", "") }, null, 5);

            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//item[ft:query(description, 'chair')]", null, AccessContext.TEST);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());

            XUpdateProcessor proc = new XUpdateProcessor(broker, docs, AccessContext.TEST);
            assertNotNull(proc);
View Full Code Here

TOP

Related Classes of org.exist.xquery.XQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.