@Test
 public void testBug37723() {
   Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   QueryService qs = CacheUtils.getQueryService();
   String qry =
       "select distinct getID, status from /portfolios pf where getID < 10 order by getID desc";
   Query q = qs.newQuery(qry);
   try {
     SelectResults result = (SelectResults) q.execute();
     Iterator itr = result.iterator();
     int j = 3;
     while (itr.hasNext()) {
       Struct struct = (Struct) itr.next();
       assertEquals(j--, ((Integer) struct.get("getID")).intValue());
     }
     qry = "select distinct getID, status from /portfolios pf where getID < 10 order by getID asc";
     q = qs.newQuery(qry);
     result = (SelectResults) q.execute();
     itr = result.iterator();
     j = 0;
     while (itr.hasNext()) {
       Struct struct = (Struct) itr.next();
       assertEquals(j++, ((Integer) struct.get("getID")).intValue());
     }
   } catch (Exception e) {
     e.printStackTrace();
     fail("Test failed because of exception=" + e);
   }
 }
Beispiel #2
0
  private static void computeMaxLengths(List list, StructType structType, Struct struct) {
    ObjectType[] fieldTypes = structType.getFieldTypes();
    String[] fieldNames = structType.getFieldNames();
    Object[] fieldValues = struct.getFieldValues();

    int listIndex = 0;
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];

      Integer len;
      if (listIndex >= list.size()) {
        len = fieldName.length();
        list.add(len);
      } else {
        len = (Integer) list.get(listIndex);
      }
      if (fieldValue == null) {
        if (len.intValue() < 4) {
          len = 4;
        }
      } else {
        int valueLen = fieldValue.toString().length();
        if (len.intValue() < valueLen) {
          len = valueLen;
        }
      }
      list.set(listIndex, len);
      listIndex++;
    }
  }
Beispiel #3
0
  private static void printStruct(int row, Struct struct, int level) {
    String spaces = getSpaces(level);
    String spaces2 = getSpaces(level + 1);

    StructType structType = struct.getStructType();
    ObjectType[] fieldTypes = structType.getFieldTypes();
    String[] fieldNames = structType.getFieldNames();
    Object[] fieldValues = struct.getFieldValues();

    int listIndex = 0;
    PadoShell.println(spaces + row + ".");
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];
      printObject(fieldName, fieldValue, level + 1);
    }
  }
 public void xtestBug32763()
     throws FunctionDomainException, TypeMismatchException, NameResolutionException,
         QueryInvocationTargetException, TimeoutException, CacheWriterException {
   Region region = CacheUtils.createRegion("pos", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   QueryService qs = CacheUtils.getQueryService();
   String qStr =
       "SELECT DISTINCT key: key, iD: entry.value.iD, secId: posnVal.secId  FROM /pos.entries entry, entry.value.positions.values posnVal  WHERE entry.value.\"type\" = 'type0' AND posnVal.secId = 'YHOO'";
   Query q = qs.newQuery(qStr);
   SelectResults result = (SelectResults) q.execute();
   StructType type = (StructType) result.getCollectionType().getElementType();
   String names[] = type.getFieldNames();
   List list = result.asList();
   if (list.size() < 1) fail("Test failed as the resultset's size is zero");
   for (int i = 0; i < list.size(); ++i) {
     Struct stc = (Struct) list.get(i);
     if (!stc.get(names[2]).equals("YHOO")) {
       fail("Test failed as the SecID value is not YHOO");
     }
   }
 }
Beispiel #5
0
  private static void printHeaders(List list, StructType structType, Struct struct, int rowMaxLen) {
    StringBuffer printStr = new StringBuffer();
    printStr.append(StringUtil.getRightPaddedString("Row", rowMaxLen, ' '));
    printStr.append("  ");

    ObjectType[] fieldTypes = structType.getFieldTypes();
    String[] fieldNames = structType.getFieldNames();
    Object[] fieldValues = struct.getFieldValues();

    int listIndex = 0;
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];
      fieldValue = getPrintableValue(fieldValue);
      int maxLen = (Integer) list.get(listIndex);
      String header = fieldName;
      printStr.append(StringUtil.getRightPaddedString(header, maxLen, ' '));
      printStr.append("  ");
      listIndex++;
    }
    PadoShell.println(printStr.toString());

    printStr = new StringBuffer();
    printStr.append(StringUtil.getRightPaddedString("", rowMaxLen, '-'));
    printStr.append("  ");
    listIndex = 0;
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];
      fieldValue = getPrintableValue(fieldValue);
      int maxLen = (Integer) list.get(listIndex);
      String header = fieldName;
      printStr.append(
          StringUtil.getRightPaddedString(
              StringUtil.getRightPaddedString("", header.length(), '-'), maxLen, ' '));
      printStr.append("  ");
      listIndex++;
    }
    PadoShell.println(printStr.toString());
  }
  @Test
  public void testMultipleOrderByClauses() {
    Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
    region.put("2", new Portfolio(2));
    region.put("3", new Portfolio(3));
    region.put("4", new Portfolio(4));
    region.put("5", new Portfolio(5));
    region.put("6", new Portfolio(6));
    region.put("7", new Portfolio(7));
    QueryService qs = CacheUtils.getQueryService();
    String qry =
        "select distinct status, getID from /portfolios pf where getID < 10 order by status asc, getID desc";
    Query q = qs.newQuery(qry);
    try {
      SelectResults result = (SelectResults) q.execute();
      Iterator itr = result.iterator();
      int j = 6;
      while (itr.hasNext() && j > 0) {
        Struct struct = (Struct) itr.next();
        assertEquals("active", struct.get("status"));
        assertEquals(j, ((Integer) struct.get("getID")).intValue());

        j -= 2;
      }
      j = 7;
      while (itr.hasNext()) {
        Struct struct = (Struct) itr.next();
        assertEquals(j, ((Integer) struct.get("getID")).intValue());
        assertEquals("inactive", struct.get("status"));
        j -= 2;
      }
      /*
      qry = "select distinct getID, status from /portfolios pf where getID < 10 order by getID asc";
      q = qs.newQuery(qry);
      result = (SelectResults) q.execute();
      itr = result.iterator();
      j = 0;
      while ( itr.hasNext()) {
       Struct struct = (Struct)itr.next();
       assertEquals(j++, ((Integer)struct.get("getID")).intValue());
      }*/
    } catch (Exception e) {
      e.printStackTrace();
      fail("Test failed because of exception=" + e);
    }
  }
Beispiel #7
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");
  }