private Object buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException { List<Object> list = new ArrayList<>(); try (ResultSet rs = array.getResultSet()) { while (rs.next()) { list.add(elementMapper.map(rs, 2, ctx)); } } Object ary = Array.newInstance(componentType, list.size()); if (componentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(ary, i, list.get(i)); } return ary; } return list.toArray((Object[]) ary); } }
private R buildFromResultSet(Array array, StatementContext ctx) throws SQLException { A result = collector.supplier().get(); BiConsumer<A, T> accumulator = collector.accumulator(); try (ResultSet rs = array.getResultSet()) { while (rs.next()) { accumulator.accept(result, elementMapper.map(rs, 2, ctx)); } } return collector.finisher().apply(result); } }
if (resultSet.wasNull()) return NullNode.getInstance(); ResultSet rs = array.getResultSet(); int arrIdx = 1; if (rs.next()) {
@Override public ResultSet call() throws SQLException { return array.getResultSet(map); } });
@Override public ResultSet call() throws SQLException { return array.getResultSet(); } });
@Override public ResultSet call() throws SQLException { return array.getResultSet(index, count); } });
@Override public ResultSet call() throws SQLException { return array.getResultSet(index, count, map); } });
/** Returns whether two arrays have the same contents. * * <p>Arrays must have the same size, and elements in the same order. * Elements are compared using {@link Object#equals(Object)}, and null * values are equal to each other. */ public static boolean equalContents(Array left, Array right) throws SQLException { ResultSet leftResultSet = left.getResultSet(); ResultSet rightResultSet = right.getResultSet(); while (leftResultSet.next() && rightResultSet.next()) { if (!Objects.equals(leftResultSet.getObject(1), rightResultSet.getObject(1))) { return false; } } return !leftResultSet.next() && !rightResultSet.next(); }
/** Returns whether two arrays have the same contents. * * <p>Arrays must have the same size, and elements in the same order. * Elements are compared using {@link Object#equals(Object)}, and null * values are equal to each other. */ public static boolean equalContents(Array left, Array right) throws SQLException { ResultSet leftResultSet = left.getResultSet(); ResultSet rightResultSet = right.getResultSet(); while (leftResultSet.next() && rightResultSet.next()) { if (!Objects.equals(leftResultSet.getObject(1), rightResultSet.getObject(1))) { return false; } } return !leftResultSet.next() && !rightResultSet.next(); }
private C buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException { C result = collectionSupplier.get(); try (ResultSet rs = array.getResultSet()) { while (rs.next()) { result.add(elementMapper.map(rs, 2, ctx)); } } return result; } }
private Fingerprint parseFingerprint(ResultSet result, int index) throws SQLException { try (final ResultSet fp = result.getArray(index).getResultSet()) { return parseFingerprint(fp); } }
public static <T> List<T> toList(Class<T> clazz, Array array) throws SQLException { List<T> values = null; if (array != null) { values = new LinkedList<T>(); ResultSet rs = array.getResultSet(); while (rs.next()) { values.add(Row.convert(rs.getObject(2), clazz)); } } return values; }
/** * This will retrieve the string value for the given array data. * * @param dataArray data * @return string value * @throws SQLException sql exception when reading result set */ public static String getString(Array dataArray) throws SQLException { if (dataArray == null) { return null; } StringJoiner sj = new StringJoiner(",", "[", "]"); ResultSet rs = dataArray.getResultSet(); while (rs.next()) { Object arrayEl = rs.getObject(2); String val = String.valueOf(arrayEl); sj.add(val); } return sj.toString(); }
@Override public List<T> convert(Array in, Context context) throws Exception { if (in == null) return null; List<T> list = new ArrayList<T>(); ResultSet rs = in.getResultSet(); try { while(rs.next()) { list.add(getter.get(rs)); } } finally { rs.close(); } return list; } }
@Override public List<T> convert(Array in, Context context) throws Exception { if (in == null) return null; List<T> list = new ArrayList<T>(); ResultSet rs = in.getResultSet(); try { while(rs.next()) { list.add(getter.get(rs)); } } finally { rs.close(); } return list; } }
conn = ds.getConnection(); String storedProc = "{call enquiry_activity_report(?)}"; CallableStatement cs = conn.prepareCall(storedProc); // register output parameter cs.registerOutParameter(1, OracleTypes.ARRAY, "ACTIVITY_REPORT_ITEMS_TYPE"); cs.execute(); Array array = cs.getArray(1); ResultSet rs = array.getResultSet(); while (rs.next()) { // why getObject(2) instead of getObject(1)? Object elements[] = ((STRUCT) rs.getObject(2)).getAttributes(); System.out.println(elements[0]); System.out.println(elements[1]); System.out.println(elements[2]); } cs.close();
private Object buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException { List<Object> list = new ArrayList<>(); try (ResultSet rs = array.getResultSet()) { while (rs.next()) { list.add(elementMapper.map(rs, 2, ctx)); } } Object ary = Array.newInstance(componentType, list.size()); if (componentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(ary, i, list.get(i)); } return ary; } return list.toArray((Object[]) ary); } }
/** * 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()); }
/** * 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()); }
default <T> Stream<T> convertArray(Array array, CheckedSqlBiFunction<ResultSet, Integer, T> extract) { try { Stream.Builder<T> builder = Stream.builder(); try (ResultSet arrayRs = array.getResultSet()) { while (arrayRs.next()) { // index 1 is array index number, so extract should use 2 builder.add(extract.apply(arrayRs, 2)); } } return builder.build(); } catch (SQLException e) { // see NamedParameterJdbcTemplate for source code throw ((JdbcTemplate) jdbc()).getExceptionTranslator() .translate("could not convert array: " + array, null, e); } }