当前位置: 首页>>代码示例>>Java>>正文


Java SelectResults.getCollectionType方法代码示例

本文整理汇总了Java中com.gemstone.gemfire.cache.query.SelectResults.getCollectionType方法的典型用法代码示例。如果您正苦于以下问题:Java SelectResults.getCollectionType方法的具体用法?Java SelectResults.getCollectionType怎么用?Java SelectResults.getCollectionType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.gemstone.gemfire.cache.query.SelectResults的用法示例。


在下文中一共展示了SelectResults.getCollectionType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:73,代码来源:Gfsh.java

示例2: 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;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:62,代码来源:SimplePrintUtil.java

示例3: 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;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:77,代码来源:SimplePrintUtil.java

示例4: 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;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:78,代码来源:PrintUtil.java

示例5: testResultComposition

import com.gemstone.gemfire.cache.query.SelectResults; //导入方法依赖的package包/类
public void testResultComposition() throws Exception {
  String queries[] = { "select distinct p from /Portfolios p where p.ID > 0",
      "select distinct p.getID from /Portfolios p where p.ID > 0 ",
      "select distinct p.getID as secID from /Portfolios p where p.ID > 0 "};
  for (int i = 0; i < queries.length; i++) {
    Query q = CacheUtils.getQueryService().newQuery(queries[i]);
    Object o = q.execute();
    if (o instanceof SelectResults) {
      SelectResults sr = (SelectResults) o;
      if (sr instanceof StructSet && i != 2)
          Assert
              .fail(" StructMemberAccess::testResultComposition: Got StrcutSet when expecting ResultSet");
      CollectionType ct = sr.getCollectionType();
      System.out.println("***Elememt Type of Colelction = "
          + ct.getElementType());
      System.out.println((sr.getCollectionType())
          .getElementType().getSimpleClassName());
      List ls = sr.asList();
      for (int j = 0; j < ls.size(); ++j)
        System.out.println("Object in the resultset = "
            + ls.get(j).getClass());
      switch (i) {
        case 0:
          if (ct.getElementType().getSimpleClassName().equals("Portfolio")) {
            Assert.assertTrue(true);
          } else {
            System.out
                .println("StructMemberAcessTest::testResultComposition:Colelction Element's class="
                    + ct.getElementType().getSimpleClassName());
            Assert.fail();
          }
          break;
        case 1:
          if (ct.getElementType().getSimpleClassName().equals("int")) {
            Assert.assertTrue(true);
          } else {
            System.out
                .println("StructMemberAcessTest::testResultComposition:Colelction Element's class="
                    + ct.getElementType().getSimpleClassName());
            Assert.fail();
          }
          break;
        case 2:
          if (ct.getElementType().getSimpleClassName().equals("Struct")) {
            Assert.assertTrue(true);
          } else {
            System.out
                .println("StructMemberAcessTest::testResultComposition:Colelction Element's class="
                    + ct.getElementType().getSimpleClassName());
            Assert.fail();
          }
      }
    }
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:56,代码来源:StructMemberAcessTest.java


注:本文中的com.gemstone.gemfire.cache.query.SelectResults.getCollectionType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。