You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is the java.sql.Connection.createArrayOf(String typeName, Object[] elements)[1] and the proprietary PGConnection.createArrayOf(String typeName, Object elements)[2] which allows for primitive arrays.
The downside of both of these methods is that consumers are rarely actually keeping their objects in arrays, so calling these methods requires creating a copy of the data in order to create the array.
It would be nice if we could accept an Iterator and size or a Collection. With jdk 8, there are now even iterators optimized for (some) primitives[3]. It turns out that we are using the array type information to understand how to serialize the content. This information could easily be derived from PrimitiveIterator instances, but other Iterator or Collection types would be difficult to deal with.
What are your thoughts on adding these 5 methods to PGConnection to allow creating Array instances without requiring a copy of the backing data?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently there is the
java.sql.Connection.createArrayOf(String typeName, Object[] elements)
[1] and the proprietaryPGConnection.createArrayOf(String typeName, Object elements)
[2] which allows for primitive arrays.The downside of both of these methods is that consumers are rarely actually keeping their objects in arrays, so calling these methods requires creating a copy of the data in order to create the array.
It would be nice if we could accept an
Iterator
and size or aCollection
. With jdk 8, there are now even iterators optimized for (some) primitives[3]. It turns out that we are using the array type information to understand how to serialize the content. This information could easily be derived fromPrimitiveIterator
instances, but otherIterator
orCollection
types would be difficult to deal with.What are your thoughts on adding these 5 methods to
PGConnection
to allow creatingArray
instances without requiring a copy of the backing data?Array createArrayOf(String typeName, int size, PrimitiveIterator.OfInt intIter) throws SQLException;
Array createArrayOf(String typeName, int size, PrimitiveIterator.OfLong longIter) throws SQLException;
Array createArrayOf(String typeName, int size, PrimitiveIterator.OfDouble doubleIter) throws SQLException;
<T> Array createArrayOf(String typeName, Collection<? extends T> items, Class<T> clazz) throws SQLException;
<T> Array createArrayOf(String typeName, int size, Iterator<? extends T> iter, Class<T> clazz) throws SQLException;
[1] - https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#createArrayOf-java.lang.String-java.lang.Object:A-
[2] - https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/PGConnection.java#L45
[3] - https://docs.oracle.com/javase/8/docs/api/java/util/PrimitiveIterator.html
Beta Was this translation helpful? Give feedback.
All reactions