示例#1
0
  @Test
  public void childSelector() throws XPathException {
    NodeSelector selector = new ChildSelector(seqSpeech.toNodeSet(), -1);
    NameTest test = new NameTest(Type.ELEMENT, new QName("LINE", ""));
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);

    assertEquals(9492, set.getLength());
  }
示例#2
0
  @Test
  public void descendantOrSelfSelector() throws XPathException {
    NodeSelector selector = new DescendantOrSelfSelector(seqSpeech.toNodeSet(), -1);
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEECH", ""));
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);

    assertEquals(2628, set.getLength());
  }
示例#3
0
  @Test
  public void ancestorSelector() throws XPathException {
    NodeSelector selector = new AncestorSelector(seqSpeech.toNodeSet(), -1, false, true);
    NameTest test = new NameTest(Type.ELEMENT, new QName("ACT", ""));
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);

    assertEquals(15, set.getLength());
  }
示例#4
0
  @Test
  public void descendantSelector() throws XPathException, SAXException, PermissionDeniedException {
    Sequence seq = executeQuery(broker, "//SCENE", 72, null);
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSelector selector = new DescendantSelector(seq.toNodeSet(), -1);
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seq.getDocumentSet(), test.getName(), selector);

    assertEquals(2639, set.getLength());
  }
示例#5
0
 ItemList executeQuery(String query, WrapperFactory wrapperFactory, Object[] params) {
   long t1 = System.currentTimeMillis(), t2 = 0, t3 = 0, t4 = 0;
   if (presub) query = presub(query, params);
   DBBroker broker = null;
   try {
     broker = db.acquireBroker();
     prepareContext(broker);
     if (overrideDocs != null) docs = overrideDocs;
     final org.exist.source.Source source = buildQuerySource(query, params, "execute");
     final XQuery xquery = broker.getXQueryService();
     final XQueryPool pool = xquery.getXQueryPool();
     CompiledXQuery compiledQuery = pool.borrowCompiledXQuery(broker, source);
     MutableDocumentSet docsToLock = new DefaultDocumentSet();
     if (docs != null) docsToLock.addAll(docs);
     if (base != null) docsToLock.addAll(base.getDocumentSet());
     try {
       XQueryContext context;
       if (compiledQuery == null) {
         context = xquery.newContext(AccessContext.INTERNAL_PREFIX_LOOKUP);
         buildXQueryStaticContext(context, true);
       } else {
         context = compiledQuery.getContext();
         // static context already set
       }
       buildXQueryDynamicContext(context, params, docsToLock, true);
       t2 = System.currentTimeMillis();
       if (compiledQuery == null) {
         compiledQuery = xquery.compile(context, source);
         t3 = System.currentTimeMillis();
       }
       docsToLock.lock(broker, false, false);
       try {
         return new ItemList(
             xquery.execute(wrap(compiledQuery, wrapperFactory, context), base),
             namespaceBindings.extend(),
             db);
       } finally {
         docsToLock.unlock(false);
         t4 = System.currentTimeMillis();
       }
     } finally {
       if (compiledQuery != null) pool.returnCompiledXQuery(source, compiledQuery);
     }
   } catch (XPathException e) {
     LOG.debug(
         "query execution failed --  "
             + query
             + "  -- "
             + (params == null ? "" : " with params " + Arrays.asList(params))
             + (bindings.isEmpty() ? "" : " and bindings " + bindings));
     throw new DatabaseException("failed to execute query", e);
   } catch (IOException e) {
     throw new DatabaseException("unexpected exception", e);
   } catch (LockException e) {
     throw new DatabaseException("deadlock", e);
   } catch (PermissionDeniedException e) {
     throw new DatabaseException("permission denied", e);
   } finally {
     db.releaseBroker(broker);
     STATS.update(query, t1, t2, t3, t4, System.currentTimeMillis());
   }
 }