本文整理汇总了Java中com.gemstone.gemfire.cache.query.SelectResults.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java SelectResults.iterator方法的具体用法?Java SelectResults.iterator怎么用?Java SelectResults.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gemstone.gemfire.cache.query.SelectResults
的用法示例。
在下文中一共展示了SelectResults.iterator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printResults
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public void printResults(SelectResults results, String message){
Object r;
Struct s;
LogWriterI18n logger = GemFireCacheImpl.getInstance().getLoggerI18n();
logger.fine(message);
int row = 0;
for (Iterator iter = results.iterator(); iter.hasNext(); ) {
r = iter.next();
row++;
if (r instanceof Struct) {
s = (Struct)r;
String[] fieldNames = ((Struct)r).getStructType().getFieldNames();
for (int i=0; i < fieldNames.length; i++){
logger.fine("### Row " + row + "\n" + "Field: " +
fieldNames[i] + " > " + s.get(fieldNames[i]).toString());
}
} else {
logger.fine("#### Row " + row + "\n" + r);
}
}
}
示例2: printoutResults
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
private void printoutResults(SelectResults results) {
Iterator iterator = results.iterator();
while (iterator.hasNext()) {
Portfolio p = (Portfolio) iterator.next();
System.out.println("->" + p + ";" + p.createDate);
}
}
示例3: selectWithType
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
@SuppressWarnings( { "unchecked" })
public QueryDataFunctionResult selectWithType(FunctionContext context, String queryString, boolean showMember,
String regionName, int limit) throws Exception {
LogWriter logger = null;
Cache cache = CacheFactory.getAnyInstance();
logger = cache.getLogger();
Function loclQueryFunc = new LocalQueryFunction("LocalQueryFunction", regionName, showMember)
.setOptimizeForWrite(true);
queryString = applyLimitClause(queryString, limit);
try {
TypedJson result = new TypedJson();
Region region = cache.getRegion(regionName);
if (region == null) {
throw new Exception(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND_ON_MEMBER.toLocalizedString(regionName,
cache.getDistributedSystem().getDistributedMember().getId()));
}
Object results = null;
boolean noDataFound = true;
if (region.getAttributes().getDataPolicy() == DataPolicy.NORMAL) {
QueryService queryService = cache.getQueryService();
Query query = queryService.newQuery(queryString);
results = query.execute();
} else {
ResultCollector rcollector = FunctionService.onRegion(cache.getRegion(regionName)).withArgs(queryString)
.execute(loclQueryFunc);
List list = (List) rcollector.getResult();
results = list.get(0);
}
if (results != null && results instanceof SelectResults) {
SelectResults selectResults = (SelectResults) results;
for (Iterator iter = selectResults.iterator(); iter.hasNext();) {
Object object = iter.next();
result.add(RESULT_KEY,object);
noDataFound = false;
}
} else {
result.add(RESULT_KEY,results);//TODO to confirm if there can be anything else apart from SelectResults
}
if (showMember) {
result.add(MEMBER_KEY,cache.getDistributedSystem().getDistributedMember().getId());
}
if (noDataFound) {
result.add(RESULT_KEY, NO_DATA_FOUND);
}
return new QueryDataFunctionResult(QUERY_EXEC_SUCCESS, BeanUtilFuncs.compress(result.toString()));
} catch (Exception e) {
logger.warning(e);
throw e;
} finally {
}
}
示例4: printSelectResults
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public int printSelectResults(SelectResults sr, int rowCount)
{
if (sr == null) {
println("Error: SelectResults is null");
return 0;
}
StringBuffer sb = new StringBuffer();
CollectionType type = sr.getCollectionType();
sb.append(sr.size());
sb.append(" results in a collection of type ");
sb.append(type);
sb.append("\n");
ObjectType elementType = type.getElementType();
int row = 1;
if (rowCount == -1) {
rowCount = Integer.MAX_VALUE;
}
for (Iterator iter = sr.iterator(); iter.hasNext() && row <= rowCount;) {
Object element = iter.next();
if (elementType.isStructType()) {
StructType structType = (StructType) elementType;
Struct struct = (Struct) element;
ObjectType[] fieldTypes = structType.getFieldTypes();
String[] fieldNames = structType.getFieldNames();
Object[] fieldValues = struct.getFieldValues();
sb.append(" Struct with ");
sb.append(fieldTypes.length);
sb.append(" fields\n");
for (int i = 0; i < fieldTypes.length; i++) {
ObjectType fieldType = fieldTypes[i];
String fieldName = fieldNames[i];
Object fieldValue = fieldValues[i];
sb.append(" ");
sb.append(fieldValue.getClass().getName());
sb.append(" ");
if (/*fieldName instanceof String || */element.getClass().isPrimitive()) { //FindBugs - instanceof not needed here
sb.append(fieldName);
} else {
sb.append(ReflectionUtil.toStringGettersAnd(fieldName));
}
sb.append(" = ");
if (fieldValue instanceof String || element.getClass().isPrimitive()) {
sb.append(fieldValue);
} else {
sb.append(ReflectionUtil.toStringGettersAnd(fieldValue));
}
sb.append("\n");
}
} else {
sb.append(" ");
sb.append(row);
sb.append(". ");
if (element instanceof String || element.getClass().isPrimitive()) {
sb.append(element);
} else {
sb.append(ReflectionUtil.toStringGettersAnd(element));
}
}
sb.append("\n");
row++;
}
println(sb);
return row - 1;
}
示例5: 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;
}
示例6: 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;
}
示例7: SelectResultsContainer
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
SelectResultsContainer(SelectResults sr)
{
this.sr = sr;
iterator = sr.iterator();
}
示例8: auxIterateEvaluate
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
/** invariant: the operand is known to be evaluated by iteration */
private SelectResults auxIterateEvaluate(CompiledValue operand,
ExecutionContext context, SelectResults intermediateResults)
throws FunctionDomainException, TypeMismatchException,
NameResolutionException, QueryInvocationTargetException {
// Asif: This can be a valid value if we have an AND condition
// like ID=1 AND true = true. In such cases , if an index is not
// available on ID still we have at least one expression which is
// independent of current scope. In such cases a value of null
// means ignore the null ( because it means all the results )
// thus a the resultset of current auxIterate which will be the
// subset of total resultset , will be the right data.
// auxIterEvalaute can be called only from an AND junction.
// This also implies that there will be at least one
// operand which will be evaluated using auxFilterEvaluate.Thus
// the resultset given to this function can be empty ( obtained
// using auxFilterEvaluate ,meaning no need to do iterations below )
// but it can never be null. As null itself signifies that the junction
// cannot be evaluated as a filter.
if (intermediateResults == null)
throw new RuntimeException(
LocalizedStrings.AbstractGroupOrRangeJunction_INTERMEDIATERESULTS_CAN_NOT_BE_NULL.toLocalizedString());
if (intermediateResults.isEmpty()) // short circuit
return intermediateResults;
List currentIters = (this.completeExpansion) ? context
.getCurrentIterators() : QueryUtils
.getDependentItrChainForIndpndntItrs(this.indpndntItr, context);
SelectResults resultSet = null;
RuntimeIterator rIters[] = new RuntimeIterator[currentIters.size()];
currentIters.toArray(rIters);
ObjectType elementType = intermediateResults.getCollectionType()
.getElementType();
resultSet = (elementType.isStructType()) ?
((SelectResults)new StructBag((StructTypeImpl)elementType,
context.getCachePerfStats())) :
((SelectResults)new ResultsBag(elementType,
context.getCachePerfStats()));
QueryObserver observer = QueryObserverHolder.getInstance();
try {
observer.startIteration(intermediateResults, operand);
Iterator iResultsIter = intermediateResults.iterator();
while (iResultsIter.hasNext()) {
Object tuple = iResultsIter.next();
if (tuple instanceof Struct) {
Object values[] = ((Struct)tuple).getFieldValues();
for (int i = 0; i < values.length; i++) {
rIters[i].setCurrent(values[i]);
}
}
else {
rIters[0].setCurrent(tuple);
}
Object result = null;
try {
result = operand.evaluate(context);
}
finally {
observer.afterIterationEvaluation(result);
}
if (result instanceof Boolean) {
if (((Boolean)result).booleanValue())
resultSet.add(tuple);
}
else if (result != null && result != QueryService.UNDEFINED)
throw new TypeMismatchException(
"AND/OR operands must be of type boolean, not type '"
+ result.getClass().getName() + "'");
}
}
finally {
observer.endIteration(resultSet);
}
return resultSet;
}
示例9: executeOql
import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
private InterpreterResult executeOql(String oql) {
try {
if (getExceptionOnConnect() != null) {
return new InterpreterResult(Code.ERROR, getExceptionOnConnect().getMessage());
}
@SuppressWarnings("unchecked")
SelectResults<Object> results =
(SelectResults<Object>) getQueryService().newQuery(oql).execute();
StringBuilder msg = new StringBuilder(TABLE_MAGIC_TAG);
boolean isTableHeaderSet = false;
Iterator<Object> iterator = results.iterator();
int rowDisplayCount = 0;
while (iterator.hasNext() && (rowDisplayCount < getMaxResult())) {
Object entry = iterator.next();
rowDisplayCount++;
if (entry instanceof Number) {
handleNumberEntry(isTableHeaderSet, entry, msg);
} else if (entry instanceof Struct) {
handleStructEntry(isTableHeaderSet, entry, msg);
} else if (entry instanceof PdxInstance) {
handlePdxInstanceEntry(isTableHeaderSet, entry, msg);
} else {
handleUnsupportedTypeEntry(isTableHeaderSet, entry, msg);
}
isTableHeaderSet = true;
msg.append(NEWLINE);
}
return new InterpreterResult(Code.SUCCESS, msg.toString());
} catch (Exception ex) {
logger.error("Cannot run " + oql, ex);
return new InterpreterResult(Code.ERROR, ex.getMessage());
}
}