@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); } }
@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); } }
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"); } } }
@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"); }