Examples of XQueryPool


Examples of nux.xom.pool.XQueryPool

          return docPool.getDocument(URI.create(systemID));
        }
      };

      // prepare XQuery pool
      XQueryPool queryPool = new XQueryPool(
          new PoolConfig(), new XQueryFactory(null, resolver));
     
      ResultSequenceSerializer serializer = new ResultSequenceSerializer();
      serializer.setAlgorithm(algorithm);
      serializer.setEncoding(encoding);
      serializer.setIndent(indent);
     
      // now do the real work
      long runsStart = System.currentTimeMillis();
      for (int run=0; run < runs; run++) {
        if (isBench) {
          System.out.println("\n\n******************************************");
          System.out.println("run = " + run + ":");
        }
        for (int i=0; i < queries.size(); i++) {
          long start = System.currentTimeMillis();
          long serializationTime = 0;
          Object query = queries.get(i);
          XQuery xquery;
          if (query instanceof String) {
            xquery = queryPool.getXQuery((String)query, baseURI);
          } else if (query instanceof File) {
            xquery = queryPool.getXQuery((File)query, baseURI);
          } else {
            xquery = null; // disable XQuery for benchmarking
          }
         
          if (isBench) {
            System.out.println("query = " +query);
          }
          if (explain && run == 0 && xquery != null) {
            System.out.println("explain = \n" + xquery.explain());
          }
         
          XQuery morpher;
          if (update instanceof String) {
            morpher = queryPool.getXQuery((String)update, null);
          } else if (update instanceof File) {
            morpher = queryPool.getXQuery((File)update, null);
          } else {
            morpher = null;
          }
         
          int numSerials = 0;
View Full Code Here

Examples of org.exist.storage.XQueryPool

        }

        DBBroker broker = null;
        DocumentImpl resource = null;
        Source source = null;
        XQueryPool xqPool  = null;
        CompiledXQuery compiled = null;
        XQueryContext context = null;

        try {

            //get the xquery
            broker = pool.get(user);

            if(xqueryresource.indexOf(':') > 0) {
                source = SourceFactory.getSource(broker, "", xqueryresource, true);
            } else {
                final XmldbURI pathUri = XmldbURI.create(xqueryresource);
                resource = broker.getXMLResource(pathUri, Lock.READ_LOCK);

                if(resource != null) {
                    source = new DBSource(broker, (BinaryDocument)resource, true);
                }
            }

            if(source != null) {

                //execute the xquery
                final XQuery xquery = broker.getXQueryService();
                xqPool = xquery.getXQueryPool();

                //try and get a pre-compiled query from the pool
                compiled = xqPool.borrowCompiledXQuery(broker, source);

                if(compiled == null) {
                    context = xquery.newContext(AccessContext.REST); //TODO should probably have its own AccessContext.SCHEDULER
                } else {
                    context = compiled.getContext();
                }

                //TODO: don't hardcode this?
                if(resource != null) {
                    context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI.append(resource.getCollection().getURI()).toString());
                    context.setStaticallyKnownDocuments(new XmldbURI[] {
                        resource.getCollection().getURI()
                    });
                }

                if(compiled == null) {

                    try {
                        compiled = xquery.compile(context, source);
                    }
                    catch(final IOException e) {
                        abort("Failed to read query from " + xqueryresource);
                    }
                }

                //declare any parameters as external variables
                if(params != null) {
                    String bindingPrefix = params.getProperty("bindingPrefix");

                    if(bindingPrefix == null) {
                        bindingPrefix = "local";
                    }
                   

                    for(final Entry param : params.entrySet()) {
                        final String key = (String)param.getKey();
                        final String value = (String)param.getValue();
                        context.declareVariable( bindingPrefix + ":" + key, new StringValue(value));
                    }
                }

                xquery.execute(compiled, null);

            } else {
                LOG.warn("XQuery User Job not found: " + xqueryresource + ", job not scheduled");
            }
        } catch(final EXistException ee) {
            abort("Could not get DBBroker!");
        } catch(final PermissionDeniedException pde) {
            abort("Permission denied for the scheduling user: " + user.getName() + "!");
        } catch(final XPathException xpe) {
            abort("XPathException in the Job: " + xpe.getMessage() + "!", unschedule);
        } catch(final MalformedURLException e) {
            abort("Could not load XQuery: " + e.getMessage());
        } catch(final IOException e) {
            abort("Could not load XQuery: " + e.getMessage());
        } finally {

            if(context != null) {
                context.runCleanupTasks();
            }
           
            //return the compiled query to the pool
            if(xqPool != null && source != null && compiled != null) {
                xqPool.returnCompiledXQuery(source, compiled);
            }

            //release the lock on the xquery resource
            if(resource != null) {
                resource.getUpdateLock().release(Lock.READ_LOCK);
View Full Code Here

Examples of org.exist.storage.XQueryPool

   * @throws XPathException
   */
  protected NodeList select(DocumentSet docs)
    throws PermissionDeniedException, EXistException, XPathException {
    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.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 resultSeq = null;
    try {
      resultSeq = xquery.execute(compiled, null);
    } finally {
      pool.returnCompiledXQuery(source, compiled);
    }

    if (!(resultSeq.isEmpty() || Type.subTypeOf(resultSeq.getItemType(), Type.NODE)))
      {throw new EXistException("select expression should evaluate to a node-set; got " +
              Type.getTypeName(resultSeq.getItemType()));}
View Full Code Here

Examples of org.exist.storage.XQueryPool

   */
  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;
      for (final Modification modification : modifications) {
        mods += modification.process(transaction);
View Full Code Here

Examples of org.exist.storage.XQueryPool

    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 {
            pool.returnCompiledXQuery(GET_CURRENT_REV_SOURCE, compiled);
        }
    }
View Full Code Here

Examples of org.exist.storage.XQueryPool

    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

Examples of org.exist.storage.XQueryPool

    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();
        } finally {
            pool.returnCompiledXQuery(GET_BASE_REV_FOR_KEY_SOURCE, compiled);
        }
    }
View Full Code Here

Examples of org.exist.storage.XQueryPool

        DBBroker broker = null;
        try {
            broker = factory.getBrokerPool().get(user);
            final Source source = new StringSource(query);
            final XQuery xquery = broker.getXQueryService();
            final XQueryPool pool = xquery.getXQueryPool();
            CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, source);
            if(compiled == null)
                {compiled = compile(broker, source, parameters);}
            final StringWriter writer = new StringWriter();
            compiled.dump(writer);
            return writer.toString();
View Full Code Here

Examples of org.exist.storage.XQueryPool

     * @exception Exception if an error occurs
     */
    public HashMap<String, Object> compile(String query, HashMap<String, Object> parameters) throws EXistException, PermissionDeniedException {
        final HashMap<String, Object> ret = new HashMap<String, Object>();
        DBBroker broker = null;
        XQueryPool pool = null;
        CompiledXQuery compiled = null;
        final Source source = new StringSource(query);
        try {
            broker = factory.getBrokerPool().get(user);
            final XQuery xquery = broker.getXQueryService();
            pool = xquery.getXQueryPool();
            compiled = compile(broker, source, parameters);
           
        } catch (final XPathException e) {
            ret.put(RpcAPI.ERROR, e.getMessage());
            if(e.getLine() != 0) {
                ret.put(RpcAPI.LINE, Integer.valueOf(e.getLine()));
                ret.put(RpcAPI.COLUMN, Integer.valueOf(e.getColumn()));
            }

        } catch (final Throwable e) {
            handleException(e);

        } finally {
            factory.getBrokerPool().release(broker);
            if(compiled != null && pool != null)
                {pool.returnCompiledXQuery(source, compiled);}
        }
        return ret;
    }
View Full Code Here

Examples of org.exist.storage.XQueryPool

     */
    protected QueryResult doQuery(DBBroker broker, CompiledXQuery compiled,
            NodeSet contextSet, HashMap<String, Object> parameters)
            throws Exception {
        final XQuery xquery = broker.getXQueryService();
        final XQueryPool pool = xquery.getXQueryPool();
       
        checkPragmas(compiled.getContext(), parameters);
        LockedDocumentMap lockedDocuments = null;
        try {
            final long start = System.currentTimeMillis();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.