Example #1
0
  private static void runquery(String tmfile, String qryfile, OptionsListener ohandler)
      throws IOException, java.net.MalformedURLException, InvalidQueryException {

    TopicMapIF tm = ImportExportUtils.getReader(tmfile).read();
    // run duplicate suppression only on in-memory topic maps. too expensive on
    // rdbms topic maps.
    if (tm instanceof net.ontopia.topicmaps.impl.basic.TopicMap)
      DuplicateSuppressionUtils.removeDuplicates(tm);

    String query;
    if (qryfile.trim().endsWith("?")) query = qryfile;
    else query = StreamUtils.read(new java.io.FileReader(qryfile));

    QueryProcessorIF processor = QueryUtils.getQueryProcessor(tm);
    ParsedQueryIF pquery = processor.parse(query);

    if (ohandler.debug) {
      System.out.println("Parsed query: " + pquery + "\n\n");

      net.ontopia.topicmaps.query.impl.basic.ParsedQuery pq =
          (net.ontopia.topicmaps.query.impl.basic.ParsedQuery) pquery;
      java.util.Iterator it = pq.getAllVariables().iterator();
      while (it.hasNext()) {
        String var = (String) it.next();
        System.out.println(
            var + ": " + net.ontopia.utils.DebugUtils.toString(pq.getVariableTypes(var)));
      }
    }

    long time = System.currentTimeMillis();
    QueryResultIF result = pquery.execute();
    System.out.println("Query time: " + (System.currentTimeMillis() - time));

    int rows = 0;

    while (result.next()) {
      for (int ix = 0; ix < result.getWidth(); ix++) System.out.print(result.getValue(ix) + "\t");
      System.out.println("");
      rows++;
    }

    System.out.println("Rows: " + rows);

    if (ohandler.timeit) {
      // runs the query 10 more times, to produce an average time
      System.out.println("\nDoing timing...");

      int times = 10;
      long total = 0;
      for (int ix = 0; ix < times; ix++) {
        time = System.currentTimeMillis();
        pquery.execute();
        total += (System.currentTimeMillis() - time);
      }

      System.out.println("Average: " + (total / times));
    }
  }
Example #2
0
 @Override
 public void onSubmit() {
   FileUpload upload = uploadField.getFileUpload();
   if (upload != null) {
     try {
       Reader input =
           new InputStreamReader(
               new Base64.InputStream(upload.getInputStream(), Base64.ENCODE), "utf-8");
       FieldInstance fieldInstance = fieldValueModel.getFieldInstanceModel().getFieldInstance();
       StringWriter swriter = new StringWriter();
       StreamUtils.transfer(input, swriter);
       String value = swriter.toString();
       fieldInstance.addValue(value, getLifeCycleListener());
       fieldValueModel.setExistingValue(value);
       uploaded = true;
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }