本文整理汇总了Java中com.gemstone.gemfire.cache.query.SelectResults.size方法的典型用法代码示例。如果您正苦于以下问题:Java SelectResults.size方法的具体用法?Java SelectResults.size怎么用?Java SelectResults.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gemstone.gemfire.cache.query.SelectResults
的用法示例。
在下文中一共展示了SelectResults.size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateQuery
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
/**
* Applies the query on the event.
* This method takes care of the performance related changed done to improve
* the CQ-query performance. When CQ-query is executed first time, it saves the
* query related information in the execution context and uses that info in later
* executions.
* @param cQuery
* @param event
* @return boolean
*/
private boolean evaluateQuery(CqQueryImpl cQuery, Object[] event) throws Exception {
ExecutionContext execContext = cQuery.getQueryExecutionContext();
execContext.reset();
execContext.setBindArguments(event);
boolean status = false;
// Check if the CQ query is executed once.
// If not execute the query in normal way.
// During this phase the query execution related info are stored in the
// ExecutionContext.
if (execContext.getScopeNum() <= 0) {
SelectResults results = (SelectResults)((DefaultQuery)cQuery.getQuery()).executeUsingContext(execContext);
if (results != null && results.size() > 0) {
status = true;
}
} else {
// Execute using the saved query info (in ExecutionContext).
// This avoids building resultSet, index look-up, generating build-plans
// that are not required for; query execution on single object.
CompiledSelect cs = ((DefaultQuery)(cQuery.getQuery())).getSelect();
status = cs.evaluateCq(execContext);
}
return status;
}
示例2: compare
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
/**
* Sort the array in ascending order of collection sizes.
*/
public int compare(Object obj1, Object obj2) {
if (!(obj1 instanceof SelectResults) || !(obj2 instanceof SelectResults)) {
Support.assertionFailed("The objects need to be of type SelectResults");
}
int answer = -1;
SelectResults sr1 = (SelectResults) obj1;
SelectResults sr2 = (SelectResults) obj2;
int sizeDifference = sr1.size() - sr2.size();
if (obj1 == obj2) {
answer = 0;
}
else if (sizeDifference > 0) {
answer = 1;
}
return answer;
}
示例3: validateSelectStarResults
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
private boolean validateSelectStarResults(int queryIndex,
SelectResults results, String queryString) {
long puts = MapBB.getBB().getSharedCounters().read(MapBB.NUM_PUT);
Log.getLogWriter().info(
"Comparing resultset of size: " + results.size() + " to region size: "
+ puts + " for query: " + queryString);
if (results.size() != puts) {
Log.getLogWriter().info(
"Size of resultset: " + results.size()
+ " does not match region size: " + puts + " for query: "
+ queryString);
return false;
}
for (Object elem : results) {
if (!(elem instanceof objects.Portfolio)) {
Log.getLogWriter().info(
" Expected Portfolio object but is " + elem.getClass());
return false;
}
}
return true;
}
示例4: selectValue
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public Object selectValue(String queryPredicate)
throws FunctionDomainException, TypeMismatchException,
NameResolutionException, QueryInvocationTargetException {
SelectResults result = query(queryPredicate);
if (result.isEmpty()) {
return null;
}
if (result.size() > 1) {
throw new FunctionDomainException(LocalizedStrings
.AbstractRegion_SELECTVALUE_EXPECTS_RESULTS_OF_SIZE_1_BUT_FOUND_RESULTS_OF_SIZE_0
.toLocalizedString(Integer.valueOf(result.size())));
}
return result.iterator().next();
}
示例5: selectValue
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public Object selectValue(String predicate) throws FunctionDomainException,
TypeMismatchException, NameResolutionException,
QueryInvocationTargetException
{
SelectResults result = query(predicate);
if (result.isEmpty()) {
return null;
}
if (result.size() > 1)
throw new FunctionDomainException(LocalizedStrings.AbstractRegion_SELECTVALUE_EXPECTS_RESULTS_OF_SIZE_1_BUT_FOUND_RESULTS_OF_SIZE_0.toLocalizedString(Integer.valueOf(result.size())));
return result.iterator().next();
}
示例6: testBug
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public void testBug() throws TimeoutException, CacheWriterException,
FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException, Exception {
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 qStr = "Select distinct structset.sos, structset.key " +
"from /portfolios pfos, pfos.positions.values outerPos, " +
"(SELECT DISTINCT key: key, sos: pos.sharesOutstanding "+
"from /portfolios.entries pf, pf.value.positions.values pos " +
"where outerPos.secId != 'IBM' AND " +
"pf.key IN (select distinct * from pf.value.collectionHolderMap['0'].arr)) structset " +
"where structset.sos > 2000";*/
String qStr = "Select distinct * from /portfolios pf, pf.positions.values where status = 'active' and secId = 'IBM'";
qs.createIndex("index1", IndexType.FUNCTIONAL, "status", "/portfolios pf");
qs.createIndex("index4", IndexType.FUNCTIONAL, "itr", "/portfolios pf, pf.collectionHolderMap chm, chm.value.arr itr");
qs.createIndex("index2", IndexType.FUNCTIONAL, "status", "/portfolios pf, positions.values pos");
qs.createIndex("index3", IndexType.FUNCTIONAL, "secId", "/portfolios pf, positions.values pos");
qs.createIndex("index5", IndexType.FUNCTIONAL, "pos.secId", "/portfolios pf, pf.collectionHolderMap chm, chm.value.arr, pf.positions.values pos");
qs.createIndex("index6", IndexType.FUNCTIONAL, "status", "/portfolios pf, pf.collectionHolderMap chm");
qs.createIndex("index7", IndexType.FUNCTIONAL, "itr", "/portfolios pf, positions.values, pf.collectionHolderMap chm, chm.value.arr itr");
Query q = qs.newQuery(qStr);
SelectResults result = (SelectResults) q.execute();
if(result.size()==0) fail("Test failed as size is zero");
}
示例7: verifyFromSnapshots
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
protected void verifyFromSnapshots(SelectResults results, String regionName) {
// compare the initial results with data in the snapshot to see if there are missing or extra elements
List dataFromSnapshots = getDataFromSnapshots(regionName);
List resultsList = results.asList();
Log.getLogWriter().info("regionName is " + regionName);
Log.getLogWriter().info("size of selectResults is " + results.size());
Log.getLogWriter().info("size of qualified data from snapshots is " + dataFromSnapshots.size());
List dataFromSnapshotsCopy = new ArrayList(dataFromSnapshots);
List resultsListCopy = new ArrayList(resultsList);
resultsListCopy.removeAll(dataFromSnapshots);
List unexpected = resultsListCopy;
dataFromSnapshotsCopy.removeAll(resultsList);
List missing = dataFromSnapshotsCopy;
StringBuffer aStr = new StringBuffer();
if (unexpected.size() > 0) {
aStr.append("the following " + unexpected.size() + " unexpected elements in SelectResults: " + Position.toString(unexpected));
}
if (missing.size() > 0) {
aStr.append("the following " + missing.size() + " elements were missing from SelectResults: " + Position.toString(missing));
}
if (aStr.length() != 0) {
throw new TestException(aStr.toString());
}
if (dataFromSnapshots.size() == results.size()) {
Log.getLogWriter().info("verified that results are correct");
}
else if (dataFromSnapshots.size() < results.size()) {
throw new TestException("There are more data in selectResults");
}
else {
throw new TestException("There are fewer data in selectResults");
}
}
示例8: pr
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public List pr(String queryString, boolean nextEnabled) throws Exception
{
long startTime = System.currentTimeMillis();
CommandResults cr = gfsh.getCommandClient().execute(new QueryTask(queryString, gfsh.getFetchSize(), nextEnabled, true));
long stopTime = System.currentTimeMillis();
if (cr.getCode() == QueryTask.ERROR_QUERY) {
gfsh.println(cr.getCodeMessage());
return null;
}
QueryResults results = (QueryResults) cr.getDataObject();
if (results == null) {
gfsh.println("No results");
return null;
}
List list = null;
Object obj = results.getResults();
if (obj instanceof SelectResults) {
SelectResults sr = (SelectResults) results.getResults();
list = sr.asList();
int startRowNum = results.getReturnedSize() - sr.size() + 1;
if (gfsh.isShowResults()) {
int rowsPrinted = PrintUtil.printSelectResults(sr, 0, startRowNum, sr.size());
gfsh.println("Fetch size: " + gfsh.getFetchSize());
gfsh.println(" Results: " + sr.size()
+ ", Returned: " + results.getReturnedSize() + "/" + results.getActualSize());
next n = (next)gfsh.getCommand("next");
// route the next command to select, which has the display routine
n.setCommand("select");
} else {
gfsh.println("Fetch size: " + gfsh.getFetchSize());
gfsh.println(" Results: " + sr.size() +
", Returned: " + results.getReturnedSize() + "/" + results.getActualSize());
}
} else {
gfsh.println("Results: " + obj);
}
if (gfsh.isShowTime()) {
gfsh.println("elapsed (msec): " + (stopTime - startTime));
}
return list;
}
示例9: select
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public List select(String queryString, boolean nextEnabled) throws Exception
{
long startTime = System.currentTimeMillis();
CommandResults cr = gfsh.getCommandClient().execute(new QueryTask(queryString, gfsh.getFetchSize(), nextEnabled));
long stopTime = System.currentTimeMillis();
if (cr.getCode() == QueryTask.ERROR_QUERY) {
gfsh.println(cr.getCodeMessage());
return null;
}
QueryResults results = (QueryResults) cr.getDataObject();
if (results == null) {
gfsh.println("No results");
return null;
}
List list = null;
Object obj = results.getResults();
if (obj instanceof SelectResults) {
SelectResults sr = (SelectResults) results.getResults();
list = sr.asList();
int startRowNum = results.getReturnedSize() - sr.size() + 1;
if (gfsh.isShowResults()) {
int rowsPrinted = PrintUtil.printSelectResults(sr, 0, startRowNum, sr.size());
gfsh.println("Fetch size: " + gfsh.getFetchSize() + ", Limit: " + limit);
gfsh.println(" Results: " + sr.size()
+ ", Returned: " + results.getReturnedSize() + "/" + results.getActualSize());
next n = (next)gfsh.getCommand("next");
n.setCommand(getClass().getSimpleName());
} else {
gfsh.println("Fetch size: " + gfsh.getFetchSize() + ", Limit: " + limit);
gfsh.println(" Results: " + sr.size() +
", Returned: " + results.getReturnedSize() + "/" + results.getActualSize());
}
} else {
gfsh.println("Results: " + obj);
}
if (gfsh.isShowTime()) {
gfsh.println("elapsed (msec): " + (stopTime - startTime));
}
return list;
}
示例10: printSelectResults
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
/**
* Prints the SelectResults contents up to the specified rowCount.
* @param sr
* @param startRowNum
* @param rowCount
* @return The number of rows printed
*/
public static int printSelectResults(SelectResults sr, int startIndex, int startRowNum, int rowCount)
{
if (sr == null) {
System.out.println("Error: SelectResults is null");
return 0;
}
int endIndex = startIndex + rowCount; // exclusive
if (endIndex >= sr.size()) {
endIndex = sr.size();
}
if (startIndex >= endIndex) {
return 0;
}
CollectionType type = sr.getCollectionType();
ObjectType elementType = type.getElementType();
int row = 1;
if (rowCount == -1) {
rowCount = sr.size();
}
HashSet elementNameSet = new HashSet();
Object element = null;
boolean isStructType = false;
StructType structType = null;
Struct struct = null;
List srList = sr.asList();
row = startRowNum;
for (int i = startIndex; i < endIndex; i++) {
element = srList.get(i);
if (elementType.isStructType()) {
structType = (StructType) elementType;
struct = (Struct) element;
printStruct(row, structType, struct, 0);
System.out.println();
} else {
System.out.println(row + ". " + getPrintableType(element));
printObject(null, element, 1);
System.out.println();
}
row++;
}
System.out.println();
for (Object elementClassName : elementNameSet) {
System.out.println("Class: " + elementClassName);
}
return endIndex - startIndex;
}
示例11: printSelectResults_iterator
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
private static int printSelectResults_iterator(SelectResults sr, int startRowNum, int rowCount)
{
if (sr == null) {
System.out.println("SelectResults is null");
return 0;
}
CollectionType type = sr.getCollectionType();
ObjectType elementType = type.getElementType();
int row = 1;
if (rowCount == -1) {
rowCount = sr.size();
}
HashSet elementNameSet = new HashSet();
ArrayList maxLenList = new ArrayList();
Object element = null;
boolean isStructType = false;
StructType structType = null;
Struct struct = null;
for (Iterator iter = sr.iterator(); iter.hasNext() && row <= rowCount;) {
element = iter.next();
if (elementType.isStructType()) {
structType = (StructType) elementType;
struct = (Struct) element;
computeMaxLengths(maxLenList, structType, struct);
isStructType = true;
} else {
computeMaxLengths(maxLenList, element, false);
elementNameSet.add(element.getClass().getName());
}
row++;
}
if (element == null && struct == null) {
return 0;
}
int rowMax = String.valueOf(startRowNum + rowCount - 1).length();
if (rowMax < 3) {
rowMax = 3;
}
if (isStructType) {
printHeaders(maxLenList, structType, struct, rowMax);
} else {
printHeaders(maxLenList, element, rowMax);
}
row = startRowNum;
int lastRow = startRowNum + rowCount - 1;
for (Iterator iter = sr.iterator(); iter.hasNext() && row <= lastRow;) {
element = iter.next();
if (elementType.isStructType()) {
structType = (StructType) elementType;
struct = (Struct) element;
System.out.print(StringUtil.getRightPaddedString(row + "", rowMax, ' '));
System.out.print(" ");
System.out.println();
} else {
System.out.print(StringUtil.getRightPaddedString(row + "", rowMax, ' '));
System.out.print(" ");
printObject(maxLenList, element, false);
System.out.println();
}
row++;
}
System.out.println();
for (Object elementClassName : elementNameSet) {
System.out.println("Class: " + elementClassName);
}
return row - 1;
}
示例12: printSelectResults_iterator
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
private static int printSelectResults_iterator(SelectResults sr, int startRowNum, int rowCount)
{
if (sr == null) {
System.out.println("SelectResults is null");
return 0;
}
CollectionType type = sr.getCollectionType();
ObjectType elementType = type.getElementType();
int row = 1;
if (rowCount == -1) {
rowCount = sr.size();
}
HashSet elementNameSet = new HashSet();
ArrayList maxLenList = new ArrayList();
Object element = null;
boolean isStructType = false;
StructType structType = null;
Struct struct = null;
for (Iterator iter = sr.iterator(); iter.hasNext() && row <= rowCount;) {
element = iter.next();
if (elementType.isStructType()) {
structType = (StructType) elementType;
struct = (Struct) element;
computeMaxLengths(maxLenList, structType, struct);
isStructType = true;
} else {
computeMaxLengths(maxLenList, element, false);
elementNameSet.add(element.getClass().getName());
}
row++;
}
if (element == null && struct == null) {
return 0;
}
int rowMax = String.valueOf(startRowNum + rowCount - 1).length();
if (rowMax < 3) {
rowMax = 3;
}
if (isStructType) {
printHeaders(maxLenList, structType, struct, rowMax);
} else {
printHeaders(maxLenList, element, rowMax);
}
row = startRowNum;
int lastRow = startRowNum + rowCount - 1;
for (Iterator iter = sr.iterator(); iter.hasNext() && row <= lastRow;) {
element = iter.next();
if (elementType.isStructType()) {
structType = (StructType) elementType;
struct = (Struct) element;
System.out.print(StringUtil.getRightPaddedString(row + "", rowMax, ' '));
System.out.print(" ");
printStruct(maxLenList, structType, struct);
System.out.println();
} else {
System.out.print(StringUtil.getRightPaddedString(row + "", rowMax, ' '));
System.out.print(" ");
printObject(maxLenList, element, false);
System.out.println();
}
row++;
}
System.out.println();
for (Object elementClassName : elementNameSet) {
System.out.println("Class: " + elementClassName);
}
return row - 1;
}
示例13: HydraTask_queryData
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public static void HydraTask_queryData() throws Exception {
Cache cache = CacheHelper.getCache();
Query query = cache
.getQueryService()
.newQuery(
"select c.name from /Amoeba/LoginCommunityAssignment as lca, /Amoeba/Community as c "
+ "where lca.communityId = c.id and lca.loginId='lfinker' and "
+ "(c.communityType='CommunityType:FullService' OR c.communityType='CommunityType:Clearing')");
SelectResults result1 = (SelectResults)query.execute();
Log.getLogWriter().info("OR - result: " + result1);
System.out.println("OR - result: " + result1);
// Works without OR
query = cache
.getQueryService()
.newQuery(
"select c.name from /Amoeba/LoginCommunityAssignment as lca, "
+ "/Amoeba/Community as c where lca.communityId = c.id and lca.loginId='lfinker' and "
+ "c.communityType='CommunityType:FullService'");
SelectResults result2 = (SelectResults)query.execute();
System.out.println("Without OR - result: " + result2);
Log.getLogWriter().info("Without OR - result: " + result2);
if (result1.size() != result2.size()) {
throw new TestException("");
}
Log.getLogWriter().info("Starting slow query");
// !!!SLOW!!!
query = cache
.getQueryService()
.newQuery(
"select distinct bca.branchId from /Amoeba/LoginCommunityAssignment as lca, "
+ "/Amoeba/Community as c, /Amoeba/BranchCommunityAssignment as bca where lca.loginId='lfinker' "
+ "and lca.communityId = c.id and "
+ "(c.communityType='CommunityType:FullService' or c.communityType='CommunityType:Clearing') "
+ "and c.id = bca.communityId");
long start = System.nanoTime();
Object result = query.execute();
long totalTime = System.nanoTime() - start;
Log.getLogWriter().info(
"Time taken by slow query::" + (totalTime / 1000) + "ms");
Log.getLogWriter().info("Result of slow query::" + result);
System.out.println(result);
}
示例14: compareResultSets
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
/**
* This method compares two selectResult Objects by
* 1. Size
* 2. SelectResults#CollectionType#ElementType()
*
* @param SelectResults
* @return void
* @throws
*/
public static String compareResultSets(SelectResults sr1 , SelectResults sr2){
ObjectType type1, type2;
String failureString = null;
type1 = sr1.getCollectionType().getElementType();
Assert.assertNotNull("PartitionedRegionTestHelper#compareResultSets: Type 1 is NULL " + type1, type1);
type2 = sr2.getCollectionType().getElementType();
Assert.assertNotNull(
"PartitionedRegionTestHelper#compareResultSets: Type 2 is NULL " + type2,
type2);
if ((type1.getClass().getName()).equals(type2.getClass().getName())) {
getLogger().info(
"PartitionedRegionTestHelper#compareResultSets: Both Search Results are of the same Type i.e.--> "
+ type1);
}
else {
getLogger()
.error(
"PartitionedRegionTestHelper#compareTwoQueryResults: Classes are : "
+ type1.getClass().getName() + " "
+ type2.getClass().getName());
failureString ="PartitionedRegionTestHelper#compareResultSets: FAILED:Search result Type is different in both the cases"+ type1.getClass().getName() + " "
+ type2.getClass().getName();
Assert.fail("PartitionedRegionTestHelper#compareResultSets: FAILED:Search result Type is different in both the cases");
return failureString;
}
if ((sr1.size()) == (sr2.size())) {
getLogger()
.info(
"PartitionedRegionTestHelper#compareResultSets: Both Search Results are non-zero and are of Same Size i.e. Size= "
+ sr1.size());
}
else {
getLogger()
.error(
"PartitionedRegionTestHelper#compareResultSets: FAILED:Search resultSet size are different in both the cases");
failureString="PartitionedRegionTestHelper#compareResultSets: FAILED:Search resultSet size are different in both the cases"+sr1.size()+" "+sr2.size();
Assert.fail("PartitionedRegionTestHelper#compareResultSets: FAILED:Search resultSet size are different in both the cases");
}
return failureString;
}