當前位置: 首頁>>代碼示例>>Java>>正文


Java Array.getResultSet方法代碼示例

本文整理匯總了Java中java.sql.Array.getResultSet方法的典型用法代碼示例。如果您正苦於以下問題:Java Array.getResultSet方法的具體用法?Java Array.getResultSet怎麽用?Java Array.getResultSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Array的用法示例。


在下文中一共展示了Array.getResultSet方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractUsingResultSet

import java.sql.Array; //導入方法依賴的package包/類
/**
 * Converts an Array into a List using {@link Array#getResultSet()}. This implementation is
 * recursive and can parse multi-dimensional arrays.
 */
static List<?> extractUsingResultSet(Array array, Calendar calendar) throws SQLException {
  ResultSet arrayValues = array.getResultSet();
  TreeMap<Integer, Object> map = new TreeMap<>();
  while (arrayValues.next()) {
    // column 1 is the index in the array, column 2 is the value.
    // Recurse on `getValue` to unwrap nested types correctly.
    // `j` is zero-indexed and incremented for us, thus we have `1` being used twice.
    map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar));
  }
  // If the result set is not in the same order as the actual Array, TreeMap fixes that.
  // Need to make a concrete list to ensure Jackson serialization.
  return new ArrayList<>(map.values());
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:18,代碼來源:JdbcResultSet.java

示例2: resultSetFromArray

import java.sql.Array; //導入方法依賴的package包/類
@Test public void resultSetFromArray() throws Exception {
  // Define the struct type we're creating
  ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER);
  ArrayType arrayType = ColumnMetaData.array(intType, "INTEGER", Rep.INTEGER);
  ColumnMetaData arrayMetaData = MetaImpl.columnMetaData("MY_ARRAY", 1, arrayType, false);
  ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone());
  // Create some arrays from the structs
  Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2));
  Array array2 = factory.createArray(intType, Arrays.<Object>asList(3));
  Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6));
  List<List<Object>> rows = Arrays.asList(Collections.<Object>singletonList(array1),
      Collections.<Object>singletonList(array2), Collections.<Object>singletonList(array3));
  // Create two rows, each with one (array) column
  try (Cursor cursor = new ListIteratorCursor(rows.iterator())) {
    List<Accessor> accessors = cursor.createAccessors(Collections.singletonList(arrayMetaData),
        Unsafe.localCalendar(), factory);
    assertEquals(1, accessors.size());
    Accessor accessor = accessors.get(0);

    assertTrue(cursor.next());
    Array actualArray = accessor.getArray();
    // An Array's result set has one row per array element.
    // Each row has two columns. Column 1 is the array offset (1-based), Column 2 is the value.
    ResultSet actualArrayResultSet = actualArray.getResultSet();
    assertEquals(2, actualArrayResultSet.getMetaData().getColumnCount());
    assertTrue(actualArrayResultSet.next());
    // Order is Avatica implementation specific
    assertEquals(1, actualArrayResultSet.getInt(1));
    assertEquals(1, actualArrayResultSet.getInt(2));
    assertTrue(actualArrayResultSet.next());
    assertEquals(2, actualArrayResultSet.getInt(1));
    assertEquals(2, actualArrayResultSet.getInt(2));
    assertFalse(actualArrayResultSet.next());

    assertTrue(cursor.next());
    actualArray = accessor.getArray();
    actualArrayResultSet = actualArray.getResultSet();
    assertEquals(2, actualArrayResultSet.getMetaData().getColumnCount());
    assertTrue(actualArrayResultSet.next());
    assertEquals(1, actualArrayResultSet.getInt(1));
    assertEquals(3, actualArrayResultSet.getInt(2));
    assertFalse(actualArrayResultSet.next());

    assertTrue(cursor.next());
    actualArray = accessor.getArray();
    actualArrayResultSet = actualArray.getResultSet();
    assertEquals(2, actualArrayResultSet.getMetaData().getColumnCount());
    assertTrue(actualArrayResultSet.next());
    assertEquals(1, actualArrayResultSet.getInt(1));
    assertEquals(4, actualArrayResultSet.getInt(2));
    assertTrue(actualArrayResultSet.next());
    assertEquals(2, actualArrayResultSet.getInt(1));
    assertEquals(5, actualArrayResultSet.getInt(2));
    assertTrue(actualArrayResultSet.next());
    assertEquals(3, actualArrayResultSet.getInt(1));
    assertEquals(6, actualArrayResultSet.getInt(2));
    assertFalse(actualArrayResultSet.next());

    assertFalse(cursor.next());
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:62,代碼來源:ArrayImplTest.java


注:本文中的java.sql.Array.getResultSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。