Package de.chojo.sqlutil.conversion
Class ArrayConverter
java.lang.Object
de.chojo.sqlutil.conversion.ArrayConverter
Class to convert sql arrays to java arrays or collections and vice versa.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @Nullable T[]Converts a column of a result set to an java array.static <T> T[]Convert a SQLArrayinto a java array of the requested return type.static <T> @Nullable T[]Converts an array of a result set collumn to an java arraystatic <T> Collection<T>toCollection(Array array) Convert a SQLArrayinto a java array of the requested return type.static <T extends Collection<T>>
TtoCollection(ResultSet resultSet, String column, Supplier<T> supplier) Convert a SQLArrayinto a java array of the requested return type.static <T> List<T>Converts a column of a result set to a list.static <T> Set<T>Converts a column of a result set to a set.static ArraytoSqlArray(Connection conn, SQLType type, Object[] array) Convert a java array to an sql array of the required type.static ArraytoSqlArray(Connection conn, SQLType type, Collection<?> collection) Convert a java collection to an sql array of the required type.
-
Method Details
-
toArray
Convert a SQLArrayinto a java array of the requested return type.- Type Parameters:
T- type of required array- Parameters:
array- array- Returns:
- array with the requested type
- Throws:
SQLException- if an error occurs while attempting to access the arraySQLFeatureNotSupportedException- if the JDBC driver does not support this method
-
toArray
@Nullable public static <T> @Nullable T[] toArray(ResultSet resultSet, String column) throws SQLException Converts an array of a result set collumn to an java array- Type Parameters:
T- type of result- Parameters:
resultSet- result setcolumn- column name- Returns:
- new array
- Throws:
SQLException- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result setSQLFeatureNotSupportedException- if the JDBC driver does not support this method
-
toArray
@Nullable @Contract("_,_,!null -> !null") public static <T> @Nullable T[] toArray(@NotNull @NotNull ResultSet resultSet, @NotNull @NotNull String column, @Nullable @Nullable T[] def) throws SQLException Converts a column of a result set to an java array.- Type Parameters:
T- type of result- Parameters:
resultSet- result setcolumn- name of columndef- default value- Returns:
- array of requested type
- Throws:
SQLException- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result setSQLFeatureNotSupportedException- if the JDBC driver does not support this method
-
toCollection
Convert a SQLArrayinto a java array of the requested return type.- Type Parameters:
T- type of required array- Parameters:
array- array- Returns:
- array with the requested type
- Throws:
SQLException- if an error occurs while attempting to access the arraySQLFeatureNotSupportedException- if the JDBC driver does not support this method
-
toCollection
public static <T extends Collection<T>> T toCollection(ResultSet resultSet, String column, Supplier<T> supplier) throws SQLException Convert a SQLArrayinto a java array of the requested return type.- Type Parameters:
T- type of result- Parameters:
resultSet- result setcolumn- name of columnsupplier- supplier of the collection- Returns:
- array with the requested type
- Throws:
SQLException- if an error occurs while attempting to access the arraySQLFeatureNotSupportedException- if the JDBC driver does not support this method
-
toSet
Converts a column of a result set to a set.- Type Parameters:
T- type of result- Parameters:
resultSet- result setcolumn- name of column- Returns:
- array as set
- Throws:
SQLException- if a database error occurs, the JDBC type is not appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type
-
toList
Converts a column of a result set to a list.- Type Parameters:
T- type of list- Parameters:
resultSet- result setcolumn- column name- Returns:
- new list
- Throws:
SQLException- if a database error occurs, the JDBC type is not appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type
-
toSqlArray
public static Array toSqlArray(Connection conn, SQLType type, Collection<?> collection) throws SQLException Convert a java collection to an sql array of the required type.- Parameters:
conn- connectiontype- type of arraycollection- collection- Returns:
- sql array
- Throws:
SQLException- if a database error occurs, the JDBC type is not appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type
-
toSqlArray
Convert a java array to an sql array of the required type.- Parameters:
conn- connectiontype- type of arrayarray- array- Returns:
- sql array
- Throws:
SQLException- if a database error occurs, the JDBC type is not appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection.SQLFeatureNotSupportedException- if the JDBC driver does not support this data type
-