Package com.helixframework.db.repository
Interface ResultSetSupport
- All Known Subinterfaces:
ResultSetMapper<T>
public interface ResultSetSupport
The ResultSetSupport interface provides utility methods to simplify the retrieval
of columns from a
ResultSet. The methods in this interface handle SQL NULL
values gracefully by allowing the return of null, default values, or wrapping the
result in an Optional.
This interface offers convenience methods for common data types such as Integer,
Long, Double, Float, Boolean, and ZonedDateTime, reducing the need for boilerplate
code when working with ResultSet objects.-
Method Summary
Modifier and TypeMethodDescriptiondefault BooleangetBooleanOrDefault(ResultSet rs, String columnLabel, boolean defaultValue) Retrieves the Boolean from the specified column of the ResultSet or returns a specified default value if SQL NULL.default BooleangetBooleanOrNull(ResultSet rs, String columnLabel) Retrieves the Boolean from the specified column of the ResultSet, returning null if the value is SQL NULL.default DoublegetDoubleOrDefault(ResultSet rs, String columnLabel, double defaultValue) Retrieves the Double from the specified column of the ResultSet or returns a specified default value if SQL NULL.default DoublegetDoubleOrNull(ResultSet rs, String columnLabel) Retrieves the Double from the specified column of the ResultSet, returning null if the value is SQL NULL.default FloatgetFloatOrDefault(ResultSet rs, String columnLabel, Float defaultValue) Retrieves the Float from the specified column of the ResultSet or returns a specified default value if SQL NULL.default FloatgetFloatOrNull(ResultSet rs, String columnLabel) Retrieves the Float from the specified column of the ResultSet, returning null if the value is SQL NULL.default IntegergetIntOrDefault(ResultSet rs, String columnLabel, int defaultValue) Retrieves the Integer from the specified column of the ResultSet or returns a specified default value if SQL NULL.default IntegergetIntOrNull(ResultSet rs, String columnLabel) Retrieves the Integer from the specified column of the ResultSet, returning null if the value is SQL NULL.default LonggetLongOrDefault(ResultSet rs, String columnLabel, long defaultValue) Retrieves the Long from the specified column of the ResultSet or returns a specified default value if SQL NULL.default LonggetLongOrNull(ResultSet rs, String columnLabel) Retrieves the Long from the specified column of the ResultSet, returning null if the value is SQL NULL.default <T> TgetObjectOrDefault(ResultSet rs, String columnLabel, Class<T> type, T defaultValue) Retrieves the object of a specific type from the specified column of the ResultSet or returns a given default value if SQL NULL.default <T> TgetObjectOrNull(ResultSet rs, String columnLabel, Class<T> type) Retrieves an object of a specific type from the specified column of the ResultSet, returning null if the value is SQL NULL.getOptionalBoolean(ResultSet rs, String columnLabel) Retrieves the Boolean from the specified column of the ResultSet as an Optional wrapper.getOptionalDouble(ResultSet rs, String columnLabel) Retrieves the Double from the specified column of the ResultSet as an Optional wrapper.getOptionalFloat(ResultSet rs, String columnLabel) Retrieves the Float from the specified column of the ResultSet as an Optional wrapper.getOptionalInt(ResultSet rs, String columnLabel) Retrieves the Integer from the specified column of the ResultSet as an Optional wrapper.getOptionalLong(ResultSet rs, String columnLabel) Retrieves the Long from the specified column of the ResultSet as an Optional wrapper.default <T> Optional<T>getOptionalObject(ResultSet rs, String columnLabel, Class<T> type) Retrieves the object of a specific type from the specified column of the ResultSet as an Optional wrapper.default Optional<ZonedDateTime>getOptionalZonedDateTime(ResultSet rs, String columnLabel) Retrieves the ZonedDateTime from the specified column of the ResultSet as an Optional wrapper.default ZonedDateTimegetZonedDateTimeOrDefault(ResultSet rs, String columnLabel, ZonedDateTime defaultValue) Retrieves the ZonedDateTime from the specified column of the ResultSet or returns a given default value if SQL NULL.default ZonedDateTimegetZonedDateTimeOrNull(ResultSet rs, String columnLabel) Retrieves the ZonedDateTime from the specified column of the ResultSet, returning null if the value is SQL NULL.default booleanChecks whether the specified column exists in the given ResultSet.default booleanChecks whether the given ResultSet is valid and not closed.
-
Method Details
-
getIntOrNull
Retrieves the Integer from the specified column of the ResultSet, returning null if the value is SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- the Integer value, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalInt
Retrieves the Integer from the specified column of the ResultSet as an Optional wrapper.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- an Optional containing the Integer value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getIntOrDefault
default Integer getIntOrDefault(ResultSet rs, String columnLabel, int defaultValue) throws SQLException Retrieves the Integer from the specified column of the ResultSet or returns a specified default value if SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the Integer value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getLongOrNull
Retrieves the Long from the specified column of the ResultSet, returning null if the value is SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- the Long value, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalLong
Retrieves the Long from the specified column of the ResultSet as an Optional wrapper.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- an Optional containing the Long value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getLongOrDefault
default Long getLongOrDefault(ResultSet rs, String columnLabel, long defaultValue) throws SQLException Retrieves the Long from the specified column of the ResultSet or returns a specified default value if SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the Long value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getDoubleOrNull
Retrieves the Double from the specified column of the ResultSet, returning null if the value is SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- the Double value, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalDouble
Retrieves the Double from the specified column of the ResultSet as an Optional wrapper.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- an Optional containing the Double value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getDoubleOrDefault
default Double getDoubleOrDefault(ResultSet rs, String columnLabel, double defaultValue) throws SQLException Retrieves the Double from the specified column of the ResultSet or returns a specified default value if SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the Double value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs.
-
getBooleanOrNull
Retrieves the Boolean from the specified column of the ResultSet, returning null if the value is SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- the Boolean value, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalBoolean
Retrieves the Boolean from the specified column of the ResultSet as an Optional wrapper.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- an Optional containing the Boolean value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getBooleanOrDefault
default Boolean getBooleanOrDefault(ResultSet rs, String columnLabel, boolean defaultValue) throws SQLException Retrieves the Boolean from the specified column of the ResultSet or returns a specified default value if SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the Boolean value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getZonedDateTimeOrNull
Retrieves the ZonedDateTime from the specified column of the ResultSet, returning null if the value is SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- the ZonedDateTime value, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalZonedDateTime
default Optional<ZonedDateTime> getOptionalZonedDateTime(ResultSet rs, String columnLabel) throws SQLException Retrieves the ZonedDateTime from the specified column of the ResultSet as an Optional wrapper.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- an Optional containing the ZonedDateTime value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getZonedDateTimeOrDefault
default ZonedDateTime getZonedDateTimeOrDefault(ResultSet rs, String columnLabel, ZonedDateTime defaultValue) throws SQLException Retrieves the ZonedDateTime from the specified column of the ResultSet or returns a given default value if SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the ZonedDateTime value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getFloatOrNull
Retrieves the Float from the specified column of the ResultSet, returning null if the value is SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- the Float value, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalFloat
Retrieves the Float from the specified column of the ResultSet as an Optional wrapper.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the column- Returns:
- an Optional containing the Float value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getFloatOrDefault
default Float getFloatOrDefault(ResultSet rs, String columnLabel, Float defaultValue) throws SQLException Retrieves the Float from the specified column of the ResultSet or returns a specified default value if SQL NULL.- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the Float value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getObjectOrNull
Retrieves an object of a specific type from the specified column of the ResultSet, returning null if the value is SQL NULL.- Type Parameters:
T- the type of the object to retrieve- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columntype- the class of the type expected from the column- Returns:
- the object value of type T, or null if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getOptionalObject
default <T> Optional<T> getOptionalObject(ResultSet rs, String columnLabel, Class<T> type) throws SQLException Retrieves the object of a specific type from the specified column of the ResultSet as an Optional wrapper.- Type Parameters:
T- the type of the object to retrieve- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columntype- the class of the type expected from the column- Returns:
- an Optional containing the object value, or an empty Optional if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
getObjectOrDefault
default <T> T getObjectOrDefault(ResultSet rs, String columnLabel, Class<T> type, T defaultValue) throws SQLException Retrieves the object of a specific type from the specified column of the ResultSet or returns a given default value if SQL NULL.- Type Parameters:
T- the type of the object to retrieve- Parameters:
rs- the ResultSet to retrieve the value fromcolumnLabel- the name of the columntype- the class of the type expected from the columndefaultValue- the default value to return if the column contains SQL NULL- Returns:
- the object value, or the specified default value if the column contains SQL NULL
- Throws:
SQLException- if a database access error occurs
-
isValid
Checks whether the given ResultSet is valid and not closed.- Parameters:
rs- the ResultSet to check- Returns:
- true if the ResultSet is valid and open, false otherwise
- Throws:
SQLException- if a database access error occurs
-
hasColumn
Checks whether the specified column exists in the given ResultSet.- Parameters:
rs- the ResultSet to checkcolumnLabel- the name of the column to look for- Returns:
- true if the column exists in the ResultSet, false otherwise
- Throws:
SQLException- if a database access error occurs
-