예제 #1
0
 @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);
   }
 }
예제 #2
0
  @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);
    }
  }