@SuppressWarnings("unchecked") @Override public Array getArray() throws SQLException { final Object o = getObject(); if (o == null) { return null; } if (o instanceof ArrayImpl) { return (ArrayImpl) o; } // If it's not an Array already, assume it is a List. return new ArrayImpl((List<Object>) o, this); }
private void append(StringBuilder buf, Object o) { if (o == null) { buf.append("null"); } else if (o.getClass().isArray()) { append(buf, AvaticaUtils.primitiveList(o)); } else { buf.append(o); } }
public Object getArray() throws SQLException { return getArray(list, accessor); }
@Override public void testGetArray(ResultSet resultSet) throws SQLException { ColumnMetaData.ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", ColumnMetaData.Rep.INTEGER); Array expectedArray = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()).createArray( intType, Arrays.asList(1, 2, 3)); assertTrue(ArrayImpl.equalContents(expectedArray, g.getArray(resultSet))); } }
for (i = 0; i < objects.length; i++) { objects[i] = getArrayData(objects[i], componentAccessor);
@Override public void testGetArray(ResultSet resultSet) throws SQLException { ColumnMetaData.ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", ColumnMetaData.Rep.INTEGER); Array expectedArray = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()).createArray( intType, Arrays.asList(1, 2, 3)); assertTrue(ArrayImpl.equalContents(expectedArray, g.getArray(resultSet))); } }
for (i = 0; i < objects.length; i++) { objects[i] = getArrayData(objects[i], componentAccessor);
public Object getArray() throws SQLException { return getArray(list); }
private void append(StringBuilder buf, Object o) { if (o == null) { buf.append("null"); } else if (o.getClass().isArray()) { append(buf, AvaticaUtils.primitiveList(o)); } else { buf.append(o); } }
@Override public Array getArray() { final List list = (List) getObject(); if (list == null) { return null; } return new ArrayImpl(list, this); }
public Object getArray() throws SQLException { return getArray(list, accessor); }
private void append(StringBuilder buf, Object o) { if (o == null) { buf.append("null"); } else if (o.getClass().isArray()) { append(buf, AvaticaUtils.primitiveList(o)); } else { buf.append(o); } }
@SuppressWarnings("unchecked") @Override public Array getArray() throws SQLException { final Object o = getObject(); if (o == null) { return null; } if (o instanceof ArrayImpl) { return (ArrayImpl) o; } // If it's not an Array already, assume it is a List. return new ArrayImpl((List<Object>) o, this); }
public Object getArray(long index, int count) throws SQLException { return getArray(list.subList((int) index, count)); }
@Override public String toString() { final Iterator<?> iterator = list.iterator(); if (!iterator.hasNext()) { return "[]"; } final StringBuilder buf = new StringBuilder("["); for (;;) { accessor.componentSlotGetter.slot = iterator.next(); try { append(buf, accessor.componentAccessor.getString()); } catch (SQLException e) { throw new RuntimeException(e); } accessor.componentSlotGetter.slot = null; if (!iterator.hasNext()) { return buf.append("]").toString(); } buf.append(", "); } }
(AbstractCursor.ArrayAccessor) accessor.componentAccessor; for (i = 0; i < objects.length; i++) { objects[i] = new ArrayImpl((List) objects[i], componentAccessor);
Object getArrayData(Object o, AbstractCursor.ArrayAccessor componentAccessor) throws SQLException { if (o instanceof List) { return getArray((List<?>) o, componentAccessor); } else if (o instanceof ArrayImpl) { return (ArrayImpl) o; } throw new RuntimeException("Unhandled"); }
@Override public String toString() { final Iterator iterator = list.iterator(); if (!iterator.hasNext()) { return "[]"; } final StringBuilder buf = new StringBuilder("["); for (;;) { accessor.componentSlotGetter.slot = iterator.next(); try { append(buf, accessor.componentAccessor.getString()); } catch (SQLException e) { throw new RuntimeException(e); } accessor.componentSlotGetter.slot = null; if (!iterator.hasNext()) { return buf.append("]").toString(); } buf.append(", "); } }
@Override public Array createArray(AvaticaType elementType, Iterable<Object> elements) { final ArrayType array = ColumnMetaData.array(elementType, elementType.name, Rep.ARRAY); final List<ColumnMetaData> types = Collections.singletonList(ColumnMetaData.dummy(array, true)); // Avoid creating a new List if we already have a List List<Object> elementList; if (elements instanceof List) { elementList = (List<Object>) elements; } else { elementList = new ArrayList<>(); for (Object element : elements) { elementList.add(element); } } try (ListIteratorCursor cursor = new ListIteratorCursor(createRowForArrayData(elementList))) { List<Accessor> accessor = cursor.createAccessors(types, Unsafe.localCalendar(), this); assert 1 == accessor.size(); return new ArrayImpl(elementList, (ArrayAccessor) accessor.get(0)); } }
Object getArrayData(Object o, AbstractCursor.ArrayAccessor componentAccessor) throws SQLException { if (o instanceof List) { return getArray((List<?>) o, componentAccessor); } else if (o instanceof ArrayImpl) { return (ArrayImpl) o; } throw new RuntimeException("Unhandled"); }