Package org.exist.xquery

Examples of org.exist.xquery.XQueryContext$CleanupTask


            List<QName> qnlist = new ArrayList<QName>(qn.length);
            for (int i = 0; i < qn.length; i++)
                qnlist.add(qn[i]);
            hints.put(QNamedKeysIndex.QNAMES_KEY, qnlist);
        }
        XQueryContext context = new XQueryContext(broker.getBrokerPool(), AccessContext.TEST);
        Occurrences[] occur = index.scanIndex(context, docs, null, hints);
        if (occur != null && expected != occur.length) {
            for (int i = 0; i < occur.length; i++) {
                System.out.println("term: " + occur[i].getTerm());
            }
View Full Code Here


                final DocumentMetadata metadata = document.getMetadata();
                if(metadata.getMimeType().equals(XQUERY_MIME_TYPE)){
           
                    //compile the query
                    final XQuery xquery = broker.getXQueryService();
                    final XQueryContext context = xquery.newContext(AccessContext.REST);
                    final Source source = new DBSource(broker, (BinaryDocument)document, true);

                    //set the module load path for any module imports that are relative
                    context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + ((XmldbURI)source.getKey()).removeLastSegment());
                   
                    return broker.getXQueryService().compile(context, source);
                } else {
                    throw new RestXqServiceCompilationException("Invalid mimetype '" +  metadata.getMimeType() + "' for XQuery: "  + document.getURI().toString().toString());
                }
View Full Code Here

    }

    //TODO : could be replaced by an XQuery call to index-keys(). See above
    private void checkIndex(DBBroker broker, DocumentSet docs, String term, int count) {
        NGramIndexWorker index = (NGramIndexWorker) broker.getIndexController().getWorkerByIndexId(NGramIndex.ID);
        XQueryContext context = new XQueryContext(broker.getBrokerPool(), AccessContext.TEST);
        Occurrences[] occurrences = index.scanIndex(context, docs, null, null);
        int found = 0;
        for (int i = 0; i < occurrences.length; i++) {
            Occurrences occurrence = occurrences[i];
            if (occurrence.getTerm().compareTo(term) == 0)
View Full Code Here

            xquery = cache.getCompiledQuery(broker, resourceFunction.getXQueryLocation());
           
            //find the function that we will execute
            final UserDefinedFunction fn = findFunction(xquery, resourceFunction.getFunctionSignature());
           
            final XQueryContext xqueryContext = xquery.getContext();
           
            //set the request object - can later be used by the EXQuery Request Module
            xqueryContext.setAttribute(EXQ_REQUEST_ATTR, request);
           
            //TODO this is a workaround?
            declareVariables(xqueryContext);
           
            //START workaround: evaluate global variables in modules, as they are reset by XQueryContext.reset()
            final Expression rootExpr = xqueryContext.getRootExpression();
            for(int i = 0; i < rootExpr.getSubExpressionCount(); i++) {
                final Expression subExpr = rootExpr.getSubExpression(i);
                if(subExpr instanceof VariableDeclaration) {
                    subExpr.eval(null);
                }
            }
            //END workaround
           
            //setup monitoring
            processMonitor = broker.getBrokerPool().getProcessMonitor();
            xqueryContext.getProfiler().traceQueryStart();
            processMonitor.queryStarted(xqueryContext.getWatchDog());
           
            //create a function call
            final FunctionReference fnRef = new FunctionReference(new FunctionCall(xqueryContext, fn));
           
            //convert the arguments
View Full Code Here

//                "declare variable $xslt external;\n" +
//                "transform:transform($xml, $xslt, ())\n";
       
    DBBroker broker = null;
    try {
      XQueryContext context;
//      XQuery xquery;
//     
      broker = db.get(db.getSecurityManager().getSystemSubject());
//        xquery = broker.getXQueryService();
//
View Full Code Here

    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);
View Full Code Here

    }

    public void killQuery(int id) {
        final XQueryWatchDog[] watchdogs = processMonitor.getRunningXQueries();
        for (XQueryWatchDog watchdog : watchdogs) {
            final XQueryContext context = watchdog.getContext();

            if( id == context.hashCode() ) {
                if( !watchdog.isTerminating() ) {
                    watchdog.kill(1000);
                }
                break;
            }
View Full Code Here

    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);
View Full Code Here

   
    variables.put(name, result);
  }
 
  private Sequence processQuery(String select) throws SAXException {
        XQueryContext context = null;
        try {
      context = new XQueryContext(broker.getBrokerPool(), accessCtx);
      context.setStaticallyKnownDocuments(documentSet);
      Map.Entry<String, String> namespaceEntry;
      for (final Iterator<Map.Entry<String, String>> i = namespaces.entrySet().iterator(); i.hasNext();) {
        namespaceEntry = (Map.Entry<String, String>) i.next();
        context.declareNamespace(
          namespaceEntry.getKey(),
          namespaceEntry.getValue());
      }
      Map.Entry<String, Object> entry;
      for (final Iterator<Map.Entry<String, Object>> i = variables.entrySet().iterator(); i.hasNext(); ) {
        entry = (Map.Entry<String, Object>) i.next();
        context.declareVariable(entry.getKey().toString(), entry.getValue());
      }
      // TODO(pkaminsk2): why replicate XQuery.compile here?
      final XQueryLexer lexer = new XQueryLexer(context, new StringReader(select));
      final XQueryParser parser = new XQueryParser(lexer);
      final XQueryTreeParser treeParser = new XQueryTreeParser(context);
      parser.xpath();
      if (parser.foundErrors()) {
        throw new SAXException(parser.getErrorMessage());
      }

      final AST ast = parser.getAST();
     
      if (LOG.isDebugEnabled())
        {LOG.debug("generated AST: " + ast.toStringTree());}

      final PathExpr expr = new PathExpr(context);
      treeParser.xpath(ast, expr);
      if (treeParser.foundErrors()) {
        throw new SAXException(treeParser.getErrorMessage());
      }
      expr.analyze(new AnalyzeContextInfo());
      final Sequence seq = expr.eval(null, null);
      return seq;
    } catch (final RecognitionException e) {
      LOG.warn("error while creating variable", e);
      throw new SAXException(e);
    } catch (final TokenStreamException e) {
      LOG.warn("error while creating variable", e);
      throw new SAXException(e);
    } catch (final XPathException e) {
      throw new SAXException(e);
    } finally {
            if (context != null)
                {context.reset(false);}
        }
  }
View Full Code Here

  //*
  //***************************************************************************/
 
  private XQueryContext getForeignContext( long id ) throws XPathException
  {
    XQueryContext   foreignContext = null;
     
    if( !context.getUser().hasDbaRole() ) {
      throw( new XPathException( this, "Permission denied, calling user '" + context.getUser().getName() + "' must be a DBA to access foreign contexts" ) );
    }
   
    if( id != 0 ) {
            XQueryWatchDog watchdogs[] = getContext().getBroker().getBrokerPool().getProcessMonitor().getRunningXQueries();
     
            for( int i = 0; i < watchdogs.length; i++ ) {
            XQueryContext ctx = watchdogs[i].getContext();
           
            if( id == ctx.hashCode() ) {
              if( !watchdogs[i].isTerminating() ) {
                foreignContext = ctx;
               }
              break;
            }
View Full Code Here

TOP

Related Classes of org.exist.xquery.XQueryContext$CleanupTask

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.