Package org.exist.xquery

Examples of org.exist.xquery.XQuery


   * @see org.exist.xupdate.Modification#process()
   */
  public long process(Txn transaction) throws PermissionDeniedException, LockException,
      EXistException, XPathException, TriggerException {
    LOG.debug("Processing xupdate:if ...");
    final XQuery xquery = broker.getXQueryService();
    final XQueryPool pool = xquery.getXQueryPool();
    final Source source = new StringSource(selectStmt);
    CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);
    XQueryContext context;
    if(compiled == null)
        {context = xquery.newContext(getAccessContext());}
    else
        {context = compiled.getContext();}

    //context.setBackwardsCompatibility(true);
    context.setStaticallyKnownDocuments(docs);
    declareNamespaces(context);
    declareVariables(context);
    if(compiled == null)
      try {
        compiled = xquery.compile(context, source);
      } catch (final IOException e) {
        throw new EXistException("An exception occurred while compiling the query: " + e.getMessage());
      }
   
    Sequence seq = null;
    try {
      seq = xquery.execute(compiled, null);
    } finally {
      pool.returnCompiledXQuery(source, compiled);
    }
    if(seq.effectiveBooleanValue()) {
      long mods = 0;
View Full Code Here


            assertNotNull(files);
           
            doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(files[files.length - 1].getName()), Lock.READ_LOCK);
            assertNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/'" + files[files.length - 1].getName() + " should not exist anymore", doc);
           
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence seq = xquery.execute("//SPEECH[ft:query(LINE, 'king')]", null, AccessContext.TEST);
            assertNotNull(seq);
            System.out.println("Found: " + seq.getItemCount());
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                String value = serializer.serialize((NodeValue) next);
View Full Code Here

            assertNotNull("Document '"+ TEST_COLLECTION_URI.append("test2/test.xml")+"' should not be null", doc);
            data = serializer.serialize(doc);
            System.out.println(data);
            doc.getUpdateLock().release(Lock.READ_LOCK);
           
            XQuery xquery = broker.getXQueryService();
            Sequence seq = xquery.execute("/products/product[last()]", null, AccessContext.TEST);
            System.out.println("Found: " + seq.getItemCount());
            for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
                Item next = i.nextItem();
                System.out.println(serializer.serialize((NodeValue) next));
            }
View Full Code Here

   
    public static long getCurrentRevision(DBBroker broker, XmldbURI docPath) throws XPathException, IOException, PermissionDeniedException {
        String docName = docPath.lastSegment().toString();
        XmldbURI collectionPath = docPath.removeLastSegment();
        XmldbURI path = VersioningTrigger.VERSIONS_COLLECTION.append(collectionPath);
        XQuery xquery = broker.getXQueryService();
        XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;
        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, GET_CURRENT_REV_SOURCE);
        if(compiled == null)
                context = xquery.newContext(AccessContext.VALIDATION_INTERNAL);
            else
                context = compiled.getContext();
        context.declareVariable("collection", path.toString());
        context.declareVariable("document", docName);
        if(compiled == null)
            compiled = xquery.compile(context, GET_CURRENT_REV_SOURCE);
        try {
            Sequence s = xquery.execute(compiled, Sequence.EMPTY_SEQUENCE);
            if (s.isEmpty())
                return 0;
            IntegerValue iv = (IntegerValue) s.itemAt(0);
            return iv.getLong();
        } finally {
View Full Code Here

    public static boolean newerRevisionExists(DBBroker broker, XmldbURI docPath, long baseRev, String key) throws XPathException, IOException, PermissionDeniedException {
        String docName = docPath.lastSegment().toString();
        XmldbURI collectionPath = docPath.removeLastSegment();
        XmldbURI path = VersioningTrigger.VERSIONS_COLLECTION.append(collectionPath);
        XQuery xquery = broker.getXQueryService();
        XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;
        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, GET_CONFLICTING_REV_SOURCE);
        if(compiled == null)
            context = xquery.newContext(AccessContext.VALIDATION_INTERNAL);
        else
            context = compiled.getContext();
        context.declareVariable("collection", path.toString());
        context.declareVariable("document", docName);
        context.declareVariable("base", new IntegerValue(baseRev));
        context.declareVariable("key", key);
        if(compiled == null)
            compiled = xquery.compile(context, GET_CONFLICTING_REV_SOURCE);
        try {
            Sequence s = xquery.execute(compiled, Sequence.EMPTY_SEQUENCE);
            return !s.isEmpty();
        } finally {
            pool.returnCompiledXQuery(GET_CONFLICTING_REV_SOURCE, compiled);
        }
    }
View Full Code Here

    public static long getBaseRevision(DBBroker broker, XmldbURI docPath, long baseRev, String sessionKey) throws XPathException, IOException, PermissionDeniedException {
        String docName = docPath.lastSegment().toString();
        XmldbURI collectionPath = docPath.removeLastSegment();
        XmldbURI path = VersioningTrigger.VERSIONS_COLLECTION.append(collectionPath);
        XQuery xquery = broker.getXQueryService();
        XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;
        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, GET_BASE_REV_FOR_KEY_SOURCE);
        if(compiled == null)
            context = xquery.newContext(AccessContext.VALIDATION_INTERNAL);
        else
            context = compiled.getContext();
        context.declareVariable("collection", path.toString());
        context.declareVariable("document", docName);
        context.declareVariable("base", new IntegerValue(baseRev));
        context.declareVariable("key", sessionKey);

        if(compiled == null)
            compiled = xquery.compile(context, GET_BASE_REV_FOR_KEY_SOURCE);
        try {
            Sequence s = xquery.execute(compiled, Sequence.EMPTY_SEQUENCE);
            if (s.isEmpty())
                return 0;

            IntegerValue iv = (IntegerValue) s.itemAt(0);
            return iv.getLong();
View Full Code Here

    //BUG: need to be released!
    broker = brokerPool.get(brokerPool.getSecurityManager().getSystemSubject());
    pool = new XQueryPool(configuration);
    stringSource = new StringSource(TEST_XQUERY_SOURCE);

    XQuery xquery = broker.getXQueryService();
    XQueryContext context = new XQueryContext(broker.getBrokerPool(), AccessContext.TEST);
    preCompiledXQuery = xquery.compile(context, stringSource);
    System.out.println("pre-compiled XQuery: " + preCompiledXQuery);
  }
View Full Code Here

                } catch (SAXException e) {
                    System.err.println("Error found while parsing document: " + f.getName() + ": " + e.getMessage());
                }
            }
           
            XQuery xquery = broker.getXQueryService();
            assertNotNull(xquery);
            Sequence result = xquery.execute("//SPEECH[ft:query(LINE, 'love')]", Sequence.EMPTY_SEQUENCE, AccessContext.TEST);
            assertNotNull(result);
            assertEquals(result.getItemCount(), 160);
           
            transact.commit(transaction);
            System.out.println("Transaction commited ...");
View Full Code Here

            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Chair"), 1);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Table892.25"), 1);
            checkIndex(broker, docs, ITEM_QNAME, new StringValue("Cabinet1525.00"), 1);

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

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

        // try to acquire a broker. If the db is deadlocked or not responsive,
        // this will block forever.
        broker = pool.get(pool.getSecurityManager().getGuestSubject());
       
        if (checkQueryEngine) {
          final XQuery xquery = broker.getXQueryService();
          final XQueryPool xqPool = xquery.getXQueryPool();
          CompiledXQuery compiled = xqPool.borrowCompiledXQuery(broker, TEST_XQUERY);
          if (compiled == null) {
            final XQueryContext context = xquery.newContext(AccessContext.TEST);
            compiled = xquery.compile(context, TEST_XQUERY);
          }
        try {
          xquery.execute(compiled, null);
        } finally {
          xqPool.returnCompiledXQuery(TEST_XQUERY, compiled);
        }
        }
      } catch (final Exception e) {
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.