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