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 Details

    • getIntOrNull

      default Integer getIntOrNull(ResultSet rs, String columnLabel) throws SQLException
      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 from
      columnLabel - 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

      default Optional<Integer> getOptionalInt(ResultSet rs, String columnLabel) throws SQLException
      Retrieves the Integer from the specified column of the ResultSet as an Optional wrapper.
      Parameters:
      rs - the ResultSet to retrieve the value from
      columnLabel - 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 from
      columnLabel - the name of the column
      defaultValue - 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

      default Long getLongOrNull(ResultSet rs, String columnLabel) throws SQLException
      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 from
      columnLabel - 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

      default Optional<Long> getOptionalLong(ResultSet rs, String columnLabel) throws SQLException
      Retrieves the Long from the specified column of the ResultSet as an Optional wrapper.
      Parameters:
      rs - the ResultSet to retrieve the value from
      columnLabel - 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 from
      columnLabel - the name of the column
      defaultValue - 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

      default Double getDoubleOrNull(ResultSet rs, String columnLabel) throws SQLException
      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 from
      columnLabel - 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

      default Optional<Double> getOptionalDouble(ResultSet rs, String columnLabel) throws SQLException
      Retrieves the Double from the specified column of the ResultSet as an Optional wrapper.
      Parameters:
      rs - the ResultSet to retrieve the value from
      columnLabel - 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 from
      columnLabel - the name of the column
      defaultValue - 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

      default Boolean getBooleanOrNull(ResultSet rs, String columnLabel) throws SQLException
      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 from
      columnLabel - 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

      default Optional<Boolean> getOptionalBoolean(ResultSet rs, String columnLabel) throws SQLException
      Retrieves the Boolean from the specified column of the ResultSet as an Optional wrapper.
      Parameters:
      rs - the ResultSet to retrieve the value from
      columnLabel - 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 from
      columnLabel - the name of the column
      defaultValue - 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

      default ZonedDateTime getZonedDateTimeOrNull(ResultSet rs, String columnLabel) throws SQLException
      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 from
      columnLabel - 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 from
      columnLabel - 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 from
      columnLabel - the name of the column
      defaultValue - 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

      default Float getFloatOrNull(ResultSet rs, String columnLabel) throws SQLException
      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 from
      columnLabel - 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

      default Optional<Float> getOptionalFloat(ResultSet rs, String columnLabel) throws SQLException
      Retrieves the Float from the specified column of the ResultSet as an Optional wrapper.
      Parameters:
      rs - the ResultSet to retrieve the value from
      columnLabel - 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 from
      columnLabel - the name of the column
      defaultValue - 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

      default <T> T getObjectOrNull(ResultSet rs, String columnLabel, Class<T> type) throws SQLException
      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 from
      columnLabel - the name of the column
      type - 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 from
      columnLabel - the name of the column
      type - 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 from
      columnLabel - the name of the column
      type - the class of the type expected from the column
      defaultValue - 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

      default boolean isValid(ResultSet rs) throws SQLException
      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

      default boolean hasColumn(ResultSet rs, String columnLabel) throws SQLException
      Checks whether the specified column exists in the given ResultSet.
      Parameters:
      rs - the ResultSet to check
      columnLabel - 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