Beispiel #1
0
  @Test
  public void testPQL_Lucene_Interactive() throws PadoException, PadoLoginException, IOException {
    // Query Lucene
    //		String queryString = "portfolio?(PortfolioId:port_a AND EndWrittenTime:[20121129 TO
    // 20141118])";
    String queryString = "portfolio?(Username:test1 AND EndWrittenTime:[20121129 TO 20141118])";

    imbiz.setAscending(false);
    imbiz.setFetchSize(100);
    imbiz.setForceRebuildIndex(true);
    imbiz.setQueryType(QueryType.PQL);
    imbiz.setOrderByField("EndWrittenTime");

    int pageNum = 1;
    int row = 1;
    String input = "";
    IScrollableResultSet rs = null;
    do {
      System.out.println("Page " + pageNum);
      if (input.equals("n")) {
        if (rs.nextSet()) {
          pageNum++;
        }
      } else if (input.equals("p")) {
        if (rs.previousSet()) {
          pageNum--;
        }
      } else {
        // Execute query
        rs = imbiz.execute(queryString);
        Assert.assertNotNull(rs);
      }
      List results = rs.toList();
      Assert.assertNotNull(results);
      int totalSize = rs.getTotalSize();
      System.out.println("   total size = " + totalSize + ", result set size = " + rs.getSetSize());
      row = rs.getStartIndex() + 1;
      for (int i = 0; i < results.size(); i++) {
        TemporalEntry entry = (TemporalEntry) results.get(i);
        ITemporalKey tk = entry.getTemporalKey();
        ITemporalData data = entry.getTemporalData();
        Date writtenTimeDate = new Date(tk.getWrittenTime());
        JsonLite jl = (JsonLite) data.getValue();
        System.out.println("   " + row++ + ". " + writtenTimeDate + ", " + jl);
      }

      System.out.println(
          "Enter to submit query again, 'n' to next page, 'p' to previous page, or 'q' + Enter to quit: ");
      LineNumberReader reader = new LineNumberReader(new InputStreamReader(System.in));
      input = reader.readLine().trim();
      if (input.length() == 0) {
        pageNum = 1;
        row = 1;
      }
    } while (input.equals("q") == false);

    rs.close();
    System.out.println("Stopped");
  }
Beispiel #2
0
  @Test
  public void testPQL_OQL2() throws PadoException, PadoLoginException, IOException {
    // Query OQL
    imbiz.setAscending(true);
    imbiz.setFetchSize(100);
    imbiz.setForceRebuildIndex(true);
    imbiz.setQueryType(QueryType.PQL);
    imbiz.setGridIds("mygrid");
    imbiz.setOrderByField("PortfolioName");

    int pageNum = 1;
    int row = 1;
    String input = "";
    IScrollableResultSet rs = null;
    do {
      System.out.println("Page " + pageNum);
      if (input.equals("n")) {
        if (rs.nextSet()) {
          pageNum++;
        }
      } else if (input.equals("p")) {
        if (rs.previousSet()) {
          pageNum--;
        }
      } else {

        // Execute IndexMatrix
        rs = imbiz.execute("portfolio?");
        Assert.assertNotNull(rs);
      }
      List results = rs.toList();
      Assert.assertNotNull(results);
      int totalSize = rs.getTotalSize();
      System.out.println("   total size = " + totalSize + ", result set size = " + rs.getSetSize());
      row = rs.getStartIndex() + 1;
      for (int i = 0; i < results.size(); i++) {
        ITemporalData data = (ITemporalData) results.get(i);
        System.out.println("   " + row++ + ". " + data.getValue());
      }

      System.out.println(
          "Enter to submit query again, 'n' to next page, 'p' to previous page, or 'q' + Enter to quit: ");
      LineNumberReader reader = new LineNumberReader(new InputStreamReader(System.in));
      input = reader.readLine().trim();
      if (input.length() == 0) {
        pageNum = 1;
        row = 1;
      }
    } while (input.equals("q") == false);

    rs.close();
    System.out.println("Stopped");
  }
Beispiel #3
0
  @Test
  public void testOQL() throws PadoException, PadoLoginException, IOException {
    // Query OQL
    imbiz.setAscending(false);
    imbiz.setFetchSize(100);
    imbiz.setForceRebuildIndex(true);
    imbiz.setQueryType(QueryType.OQL);
    imbiz.setGridIds("mygrid");
    imbiz.setOrderByField("PortfolioId");

    int pageNum = 1;
    int row = 1;
    String input = "";
    IScrollableResultSet rs = null;
    do {
      System.out.println("Page " + pageNum);
      if (input.equals("n")) {
        if (rs.nextSet()) {
          pageNum++;
        }
      } else if (input.equals("p")) {
        if (rs.previousSet()) {
          pageNum--;
        }
      } else {
        rs = imbiz.execute("select * from /mygrid/portfolio");
        Assert.assertNotNull(rs);
      }
      List results = rs.toList();
      Assert.assertNotNull(results);
      int totalSize = rs.getTotalSize();
      System.out.println("   total size = " + totalSize + ", result set size = " + rs.getSetSize());
      row = rs.getStartIndex() + 1;
      for (int i = 0; i < results.size(); i++) {
        Object obj = results.get(i);
        if (obj instanceof ITemporalData) {
          ITemporalData data = (ITemporalData) results.get(i);
          System.out.println("   " + row++ + ". " + data.getValue());
        } else if (obj instanceof Struct) {
          Struct struct = (Struct) obj;
          String[] fieldNames = struct.getStructType().getFieldNames();
          for (int j = 0; j < fieldNames.length; j++) {
            if (j > 0) {
              System.out.print(", ");
            }
            System.out.print(fieldNames[j] + "=" + struct.get(fieldNames[j]));
          }
          System.out.println();
        } else {
          System.out.println("   " + row++ + ". " + obj);
        }
      }

      System.out.println(
          "Enter to submit query again, 'n' to next page, 'p' to previous page, or 'q' + Enter to quit: ");
      LineNumberReader reader = new LineNumberReader(new InputStreamReader(System.in));
      input = reader.readLine().trim();
      if (input.length() == 0) {
        pageNum = 1;
        row = 1;
      }
    } while (input.equals("q") == false);

    rs.close();
    System.out.println("Stopped");
  }
Beispiel #4
0
  @SuppressWarnings("unchecked")
  @Test
  public void testPQL_Lucene() throws PadoException, PadoLoginException, IOException {
    // Query Lucene
    String queryString = "portfolio?PortfolioId:MyPortfolio";
    //		String queryString = "portfolio?(PortfolioId:port_ab AND EndWrittenTime:[20121129 TO
    // 20141118])";
    //		String queryString = "portfolio?(Username:dpark AND EndWrittenTime:[20121129 TO 20141118])";
    //		String queryString = "spare/spare?(InvName:MSTEC AND EndWrittenTime:[20121129 TO
    // 20141118])";
    //		String queryString = "spare/spare?(InvName:MSTEC)";

    //		String orderBy = "EndWrittenTime";
    String orderBy = "WrittenTime";
    //		String orderBy = "StartValidTime";
    //		String orderBy = "EndValidTime";
    //		String orderBy = "PortfolioId";
    //		String orderBy = "AccountId";
    //		String orderBy = "Description";
    //		String orderBy = "PortfolioName";
    boolean isAscending = true;

    boolean isDate =
        orderBy.equals("WrittenTime")
            || orderBy.equals("EndWrittenTime")
            || orderBy.equals("StartValidTime")
            || orderBy.equals("EndValidTime");
    imbiz.setAscending(isAscending);
    imbiz.setFetchSize(100);
    imbiz.setForceRebuildIndex(true);
    imbiz.setQueryType(QueryType.PQL);
    imbiz.setOrderByField(orderBy);

    int row = 1;
    IScrollableResultSet rs = imbiz.execute(queryString);
    int totalSize = rs.getTotalSize();
    System.out.println("   total size = " + totalSize);
    do {
      List results = rs.toList();
      Assert.assertNotNull(results);
      row = rs.getStartIndex() + 1;
      Object prevItem = null;
      JsonLite prevJl = null;
      for (int i = 0; i < results.size(); i++) {
        TemporalEntry entry = (TemporalEntry) results.get(i);
        ITemporalKey tk = entry.getTemporalKey();
        ITemporalData data = entry.getTemporalData();
        JsonLite jl = (JsonLite) data.getValue();
        Comparable item = (Comparable) tk.getWrittenTime();
        if (orderBy.equals("WrittenTime") || orderBy.equals("EndWrittenTime")) {
          item = (Comparable) tk.getWrittenTime();
        } else if (orderBy.equals("StartValidTime")) {
          item = (Comparable) tk.getStartValidTime();
        } else if (orderBy.equals("EndValidTime")) {
          item = (Comparable) tk.getEndValidTime();
        } else if (orderBy.equals("Username")) {
          item = tk.getUsername();
        } else {
          item = (Comparable) jl.get(orderBy);
        }
        if (item == null) {
          System.err.println(orderBy + " field not found.");
          Assert.fail();
        }
        if (prevItem != null) {
          if (isAscending) {
            if (item.compareTo(prevItem) < 0) {
              printItems(row, jl, prevJl, item, prevItem, orderBy, isAscending, isDate);
              //							Assert.fail();
            }
          } else {
            if (item.compareTo(prevItem) > 0) {
              printItems(row, jl, prevJl, item, prevItem, orderBy, isAscending, isDate);
              //							Assert.fail();
            }
          }
        }
        row++;
        prevItem = item;
        prevJl = jl;
      }
    } while (rs.nextSet());
    rs.close();
    System.out.println("Complete");
  }