use of org.apache.calcite.avatica.util.ListIteratorCursor in project calcite-avatica by apache.
the class ArrayTypeTest method createArray.
/**
* Creates a JDBC {@link Array} from a list of values.
*
* @param typeName the SQL type name of the elements in the array
* @param componentType The Avatica type for the array elements
* @param arrayValues The array elements
* @return An Array instance for the given component and values
*/
@SuppressWarnings("unchecked")
private <T> Array createArray(String typeName, AvaticaType componentType, List<T> arrayValues) {
// Make a "row" with one "column" (which is really a list)
final List<Object> oneRow = Collections.singletonList((Object) arrayValues);
// Make an iterator over this one "row"
final Iterator<List<Object>> rowIterator = Collections.singletonList(oneRow).iterator();
ArrayType array = ColumnMetaData.array(componentType, typeName, Rep.ARRAY);
try (ListIteratorCursor cursor = new ListIteratorCursor(rowIterator)) {
List<ColumnMetaData> types = Collections.singletonList(ColumnMetaData.dummy(array, true));
Calendar calendar = Unsafe.localCalendar();
List<Accessor> accessors = cursor.createAccessors(types, calendar, null);
assertTrue("Expected at least one accessor, found " + accessors.size(), !accessors.isEmpty());
ArrayAccessor arrayAccessor = (ArrayAccessor) accessors.get(0);
return new ArrayImpl((List<Object>) arrayValues, arrayAccessor);
}
}
Aggregations