Package org.exist.xquery

Examples of org.exist.xquery.XQueryContext$SavedState


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


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

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

    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

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

    public void when_prefix_is_known_in_context_dont_use_if_namespace_equals_default_namespace() throws SAXException {
       
        final String entry_name = "entry";
        final String id_name = "id";
       
        XQueryContext mockContext = EasyMock.createMock(XQueryContext.class);
       
        expect(mockContext.getDatabase()).andReturn(null);
        expect(mockContext.getSharedNamePool()).andReturn(new NamePool());
        //expect(mockContext.getPrefixForURI(ATOM_NS)).andReturn(ATOM_PREFIX).times(2);
       
        replay(mockContext);
       
        MemTreeBuilder builder = new MemTreeBuilder(mockContext);
View Full Code Here

        }
        // TODO(pkaminsk2): why replicate XQuery.compile here?
        DBBroker broker = null;
        try {
            broker = pool.get(user);
            final XQueryContext context = new XQueryContext(pool, accessCtx);
            final XQueryLexer lexer = new XQueryLexer(context, new StringReader(sortExpr));
            final XQueryParser parser = new XQueryParser(lexer);
            final XQueryTreeParser treeParser = new XQueryTreeParser(context);
            parser.xpath();
            if (parser.foundErrors()) {
View Full Code Here

        // ignored
    }
   
    public QName checkNS(boolean isElement, QName qname) {
        if(checkNS) {
            final XQueryContext context = builder.getContext();
            if(qname.getPrefix() == null) {
              if (qname.getNamespaceURI() == null || qname.getNamespaceURI().isEmpty()) {
                return qname;
             
              } else if (isElement) {
                  return qname;

              } else {
                  final String prefix = generatePrfix(context, context.getInScopePrefix(qname.getNamespaceURI()));

                  context.declareInScopeNamespace(prefix, qname.getNamespaceURI());
                  qname.setPrefix(prefix);
                  return qname;
              }
            }
          if(qname.getPrefix().isEmpty() && qname.getNamespaceURI() == null)
                {return qname;}

            final String inScopeNamespace = context.getInScopeNamespace(qname.getPrefix());
            if(inScopeNamespace == null) {
                context.declareInScopeNamespace(qname.getPrefix(), qname.getNamespaceURI());
               
            } else if(!inScopeNamespace.equals(qname.getNamespaceURI())) {
               
                final String prefix = generatePrfix(context, context.getInScopePrefix(qname.getNamespaceURI()));

                context.declareInScopeNamespace(prefix, qname.getNamespaceURI());
                qname.setPrefix(prefix);
            }
        }
        return qname;
    }
View Full Code Here

        // fixme! - hook for debugger here /ljo

        final Sequence sequence = null;

        final XQuery xqueryService = evalContext.getBroker().getXQueryService();
        final XQueryContext innerContext;
        if (contextInit != null) {
            // eval-with-context: initialize a new context
            innerContext = xqueryService.newContext(evalContext.getAccessContext());
            initContextSequence = initContext(contextInit.getNode(), innerContext);
        } else {
            // use the existing outer context
            // TODO: check if copying the static context would be sufficient???
            innerContext = evalContext.copyContext();
            innerContext.setShared(true);
            //innerContext = context;
        }
       
        //set module load path
        if(Type.subTypeOf(expr.getType(), Type.ANY_URI)) {
            String uri = null;
            final Object key = querySource.getKey();
           
            if(key instanceof XmldbURI) {
                uri = XmldbURI.EMBEDDED_SERVER_URI.append(((XmldbURI)key).removeLastSegment()).toString();
//          } else if (key instanceof URL) {
//              TODO: uri = ((URL) key).getParent()
            } else if (key instanceof String && querySource instanceof FileSource) {
                uri = ((FileSource) querySource).getFile().getParent();
            }
         
            if (uri != null) {
                innerContext.setModuleLoadPath(uri);
            }
        }

        //bind external vars?
        if(isCalledAs("eval") && getArgumentCount() == 3) {
            if(!args[2].isEmpty()) {
                final Sequence externalVars = args[2];
                for(int i = 0; i < externalVars.getItemCount(); i++) {
                    final Item varName = externalVars.itemAt(i);
                    if(varName.getType() == Type.QNAME) {
                        final Item varValue = externalVars.itemAt(++i);
                        innerContext.declareVariable(((QNameValue)varName).getQName(), varValue);
                    }
                }
            }
        }
View Full Code Here

    private CompiledXQuery compileXQuery(DBBroker broker, Source xqSource, XmldbURI[] staticallyKnownDocuments, XmldbURI xqwsCollectionUri, HttpServletRequest request, HttpServletResponse response) throws XPathException, PermissionDeniedException
    {
      //Get the xquery service
        final XQuery xquery = broker.getXQueryService();
    final XQueryPool pool = xquery.getXQueryPool();
        XQueryContext context;
       
        //try and get pre-compiled XQuery from the cache
        CompiledXQuery compiled = pool.borrowCompiledXQuery(broker, xqSource);
       
        //Create the context and set a header to indicate cache status
        if(compiled == null)
        {
          context = xquery.newContext(AccessContext.REST);
          //response.setHeader("X-XQuery-Cached", "false");
      }
        else
      {
          context = compiled.getContext();
          //response.setHeader("X-XQuery-Cached", "true");
        }
       
        //Setup the context
        declareVariables(context, request, response);
        context.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI.append(xqwsCollectionUri).toString());
        context.setStaticallyKnownDocuments(staticallyKnownDocuments);
       
        //no pre-compiled XQuery, so compile, it
        if(compiled == null)
        {
            try
View Full Code Here

TOP

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

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.