Package org.exist.xmldb

Examples of org.exist.xmldb.XQueryService


          return;

        try {
            StringBuilder fails = new StringBuilder();
            StringBuilder results = new StringBuilder();
            XQueryService xqs = (XQueryService) rootCollection.getService("XQueryService", "1.0");
            Source query = new FileSource(new File("test/src/xquery/runTests.xql"), "UTF-8", false);
            for (File file : files) {
                Document doc = parse(file);

                xqs.declareVariable("doc", doc);
        xqs.declareVariable("id", Sequence.EMPTY_SEQUENCE);
                ResourceSet result = xqs.execute(query);
                XMLResource resource = (XMLResource) result.getResource(0);
                results.append(resource.getContent()).append(EOL);
                Element root = (Element) resource.getContentAsDOM();
                NodeList tests = root.getElementsByTagName("test");
                for (int i = 0; i < tests.getLength(); i++) {
View Full Code Here


        });
        for (File suite: suites) {
            try {
                StringBuilder fails = new StringBuilder();
                StringBuilder results = new StringBuilder();
                XQueryService xqs = (XQueryService) rootCollection.getService("XQueryService", "1.0");
                xqs.setModuleLoadPath(getDirectory());
                Source query = new FileSource(suite, "UTF-8", false);

                ResourceSet result = xqs.execute(query);
                XMLResource resource = (XMLResource) result.getResource(0);
                results.append(resource.getContent()).append('\n');

                Element root = (Element) resource.getContentAsDOM();
                NodeList testsuites = root.getElementsByTagName("testsuite");
View Full Code Here

                File file = (File) i.next();
                Resource resource = collection.createResource(file.getName(), "XMLResource");
                resource.setContent(file);
                collection.storeResource(resource);
            }
            XQueryService service = (XQueryService) collection.getService("XQueryService", "1.0");
            ResourceSet result = service.execute(new ClassLoaderSource("/org/exist/performance/log2html.xql"));

            if (directory == null)
                directory = new File(System.getProperty("user.dir"));
            File htmlFile = new File(directory, "results.html");
            FileUtils.writeStringToFile(htmlFile, result.getResource(0).getContent().toString(), "UTF-8");
View Full Code Here

    public void execute(Connection connection) throws XMLDBException, EXistException {
        Collection collection = connection.getCollection(collectionPath);
        if (collection == null)
            throw new EXistException("collection " + collectionPath + " not found");
        XQueryService service = (XQueryService) collection.getService("XQueryService", "1.0");
        if (getParent().getNamespaces() != null) {
          for (Map.Entry<String, String> entry : getParent().getNamespaces().entrySet()) {
            service.setNamespace(entry.getKey(), entry.getValue());
          }
        }
        ResourceSet result = service.query(forceOptimize ? OPTIMIZE + query : query);
        lastResult = (int) result.getSize();
        if (retrieve) {
            for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
                Resource r = i.nextResource();
                LOG.debug(r.getContent());
View Full Code Here

    }


    public void execute(Connection connection) throws XMLDBException, EXistException {
        Collection collection = connection.getCollection("/db");
        XQueryService service = (XQueryService) collection.getService("XQueryService", "1.0");
        service.declareVariable("filename", "");
        service.declareVariable("count", "0");
        String query = IMPORT + xqueryContent;
        System.out.println("query: " + query);
        CompiledExpression compiled = service.compile(query);
        try {
            for (int i = 0; i < count; i++) {
                File nextFile = new File(directory, prefix + i + ".xml");
               
                service.declareVariable("filename", nextFile.getName());
                service.declareVariable("count", new IntegerValue(i));
                ResourceSet results = service.execute(compiled);

                Writer out = new OutputStreamWriter(new FileOutputStream(nextFile), "UTF-8");
                for (ResourceIterator iter = results.getIterator(); iter.hasMoreResources(); ) {
                    Resource r = iter.nextResource();
                    out.write(r.getContent().toString());
View Full Code Here

      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      final long tResult =0;
      long tCompiled=0;
     
      try {
        final XQueryService service= (XQueryService) collection.getService("XQueryService", "1.0");
        service.setProperty(OutputKeys.INDENT, properties.getProperty(OutputKeys.INDENT, "yes"));
        final long t0 = System.currentTimeMillis();
        final CompiledExpression compiled = service.compile(xpath);
        final long t1 = System.currentTimeMillis();
        tCompiled = t1 - t0;
       
        // In this way we can see the parsed structure meanwhile the query is
        final StringWriter writer = new StringWriter();
        service.dump(compiled, writer);
        exprDisplay.setText(writer.toString());
        resultTabs.setSelectedComponent(exprDisplay);
       
        statusMessage.setText(Messages.getString("QueryDialog.Compilation")+": " + tCompiled + "ms");
       
View Full Code Here

      setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      long tResult =0;
      long tCompiled=0;
      ResourceSet result = null;
      try {
        final XQueryService service= (XQueryService) collection.getService("XQueryService", "1.0");
        service.setProperty(OutputKeys.INDENT, properties.getProperty(OutputKeys.INDENT, "yes"));
        final long t0 = System.currentTimeMillis();
       
        if (resource != null) {
                    service.setModuleLoadPath(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + resource.getParentCollection().getName());
                }
       
        final CompiledExpression compiled = service.compile(xpath);
        final long t1 = System.currentTimeMillis();
        // Check could also be collection instanceof LocalCollection
        if(compiled instanceof CompiledXQuery)
          {context = ((CompiledXQuery)compiled).getContext();}
        tCompiled = t1 - t0;
       
        // In this way we can see the parsed structure meanwhile the query is
        StringWriter writer = new StringWriter();
        service.dump(compiled, writer);
        exprDisplay.setText(writer.toString());
       
        result = service.execute(compiled);
        context = null;
        tResult = System.currentTimeMillis() - t1;
       
        // jmfg: Is this still needed? I don't think so
        writer = new StringWriter();
        service.dump(compiled, writer);
        exprDisplay.setText(writer.toString());
       
        statusMessage.setText(Messages.getString("QueryDialog.retrievingmessage"));
        XMLResource resource;
        final int howmany= count.getNumber().intValue();
View Full Code Here

           
            // get root-collection
            Collection col =
                DatabaseManager.getCollection(URI + XmldbURI.ROOT_COLLECTION);
            // get query-service
            XQueryService service =
                (XQueryService) col.getService( "XQueryService", "1.0" );
           
            // set pretty-printing on
            service.setProperty( OutputKeys.INDENT, "yes" );
            service.setProperty( OutputKeys.ENCODING, "UTF-8" );
           
            CompiledExpression compiled = service.compile( query );
           
            long start = System.currentTimeMillis();
           
            // execute query and get results in ResourceSet
            ResourceSet result = service.execute( compiled );

            long qtime = System.currentTimeMillis() - start;
            start = System.currentTimeMillis();
           
            Properties outputProperties = new Properties();
View Full Code Here

    shutdown(collection1);
    shutdown(collection2);
  }

  private static void doQuery(Collection collection, String query) throws XMLDBException {
    XQueryService service = (XQueryService)
      collection.getService("XQueryService", "1.0");
    ResourceSet result = service.query(query);
    System.out.println("Found " + result.getSize() + " results.");
    for(ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
      System.out.println(i.nextResource().getContent());
    }
  }
View Full Code Here

   * <li>Write a "live" document to the database using the XQueryService</li>
   * <li>Create a "work" version of it</li>
   * </ul>
   */
  public final void testRemoveAndReload() {
    XQueryService service = setupDatabase();
   
    // write "live" document to the database
    try {
      store(createDocument(), service, "live.xml");
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.exist.xmldb.XQueryService

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.