Consider adding array helper methods to KiwiJdbc in kiwi #692
Replies: 3 comments
-
Here are a few more helper methods that use the above public static <T> Set<T> arrayAsSet(ResultSet rs, String columnName) throws SQLException {
T[] ts = getArray(rs, columnName);
return Sets.newHashSet(ts);
}
public static <T> List<T> arrayAsList(ResultSet rs, String columnName) throws SQLException {
T[] ts = getArray(rs, columnName);
return Lists.newArrayList(ts);
} The above return mutable collections. We could change them to use |
Beta Was this translation helpful? Give feedback.
-
As a first step, these will be added to kiwi-beta. See Add JDBC array helper methods. |
Beta Was this translation helpful? Give feedback.
-
I am marking this discussed as Closed since it is now in kiwi-beta and may be moved to kiwi at some point. |
Beta Was this translation helpful? Give feedback.
-
I propose adding some methods to
KiwiJdbc
for dealing with arrays in JDBCResultSet
s. Modifications fornull
handling and/or name changes should also be considered and implemented. Here is a method that accepts aResultSet
, the expected type of array elements, and the column name:And here is a method that does not take the expected type, which can only be used with call sites where the type can be inferred by the compiler:
We probably should rename them to be consistent with the existing methods in
KiwiJdbc
, e.g. maybearrayOrNull
and they would therefore need to accommodate possible null values, which the above example methods do not. See the existing methods inKiwiJdbc
; it's just a simple check usingResultSet#wasNull
. But, I've not tested this (since our existing use cases do not permit null values) so would need to see what actually happens.Note also that the above only work for reference types. We would need to have specialized methods for primitives, e.g.
doubleArrayOrNull
,intArrayOrNull
, and so on.Alas, the methods would need to include some ugliness, for example (without null handling):
We could also add some type validation (again without null handling):
Beta Was this translation helpful? Give feedback.
All reactions