Interface DatabaseMapping<T>

  • Type Parameters:
    T - the type for this mapping
    All Known Implementing Classes:
    Database.BasicMapping, DatabaseRecord.Mapping

    public interface DatabaseMapping<T>
    A component that defines how a data type is mapped to a database for select, insert, update and delete operations.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  DatabaseMapping.Binder<T>
      A Binder that can bind a record to a PreparedStatement object
      static interface  DatabaseMapping.Mapper<T>
      A Mapper that can create an Object from the current row in a ResultSet
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static void applyBoolean​(java.sql.PreparedStatement stmt, int paramIndex, java.lang.Boolean value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyDate​(java.sql.PreparedStatement stmt, int paramIndex, java.sql.Date value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyDate​(java.sql.PreparedStatement stmt, int paramIndex, java.sql.Date value, java.util.Calendar calendar)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyDouble​(java.sql.PreparedStatement stmt, int paramIndex, java.lang.Double value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyFloat​(java.sql.PreparedStatement stmt, int paramIndex, java.lang.Float value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyInt​(java.sql.PreparedStatement stmt, int paramIndex, java.lang.Integer value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyLong​(java.sql.PreparedStatement stmt, int paramIndex, java.lang.Long value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static void applyString​(java.sql.PreparedStatement stmt, int paramIndex, java.lang.String value)
      Applies the value to the statement, calling PreparedStatement.setNull() if value is null
      static java.sql.PreparedStatement bindArgs​(java.sql.PreparedStatement stmt, java.util.List<java.lang.Object> args)
      Binds an array of arguments to the prepared statement
      static java.sql.PreparedStatement bindArgs​(java.sql.PreparedStatement stmt, java.util.TimeZone timeZone, java.util.List<java.lang.Object> args)
      Binds an array of arguments to the prepared statement
      default DatabaseMapping.Binder<T> delete()
      The binder to bind arguments to a PreparedStatement for affecting deletes
      static <T> java.lang.String getDeleteSql​(DatabaseMapping<T> mapping)
      Returns the SQL resolved from the DatabaseSql annotation on the delete method
      static <T> java.lang.String getInsertSql​(DatabaseMapping<T> mapping)
      Returns the SQL resolved from the DatabaseSql annotation on the insert method
      static <T> java.lang.String getSelectSql​(DatabaseMapping<T> mapping)
      Returns the SQL resolved from the DatabaseSql annotation on the select method
      static java.lang.String getSql​(DatabaseMapping<?> mapping, java.lang.String methodName)
      Returns the SQL resolved from the DatabaseSql annotation on the named method
      static <T> java.lang.String getUpdateSql​(DatabaseMapping<T> mapping)
      Returns the SQL resolved from the DatabaseSql annotation on the update method
      static java.lang.String in​(java.util.Collection<?> values)
      Returns a command separated list of values for an in clause
      static java.lang.String in​(java.util.Collection<?> values, com.d3x.core.util.Option<java.time.ZoneId> zoneId)
      Returns a command separated list of values for an in clause
      default DatabaseMapping.Binder<T> insert()
      The binder to bind arguments to a PreparedStatement for affecting inserts
      static <T> java.util.Iterator<T> iterator​(java.sql.ResultSet rs, DatabaseMapping.Mapper<T> mapper)
      Returns an iterator that extracts records from ResultSet using the mapper
      static <T> java.util.List<T> list​(java.sql.ResultSet rs, DatabaseMapping.Mapper<T> mapper)
      Extracts records from the result set using the mapper and returns them as a list
      static com.d3x.core.util.Option<java.lang.Boolean> readBoolean​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Boolean> readBoolean​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs, int column, java.util.Calendar calendar)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs, java.lang.String column, java.util.Calendar calendar)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Double> readDouble​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Double> readDouble​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Float> readFloat​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Float> readFloat​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Integer> readInt​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Integer> readInt​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.time.LocalDate> readLocalDate​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.time.LocalDate> readLocalDate​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.time.LocalDateTime> readLocalDateTime​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.time.LocalDateTime> readLocalDateTime​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Long> readLong​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Long> readLong​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Short> readShort​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.Short> readShort​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.String> readString​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.lang.String> readString​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs, int column, java.util.Calendar calendar)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs, java.lang.String column, java.util.Calendar calendar)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs, int column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs, int column, java.util.Calendar calendar)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs, java.lang.String column)
      Returns an option on the value read from the ResultSet
      static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs, java.lang.String column, java.util.Calendar calendar)
      Returns an option on the value read from the ResultSet
      default DatabaseMapping.Mapper<T> select()
      The mapper to map a row in a result set to some object
      static <T> java.util.Set<T> set​(java.sql.ResultSet rs, DatabaseMapping.Mapper<T> mapper)
      Extracts records from the result set using the mapper and returns them as a set
      default java.util.Iterator<T> toIterator​(java.sql.ResultSet rs)
      Returns an iterator over the records generated by the ResultSet
      default java.util.List<T> toList​(java.sql.ResultSet rs)
      Extracts all data from result set into a list using this mapping
      default java.util.Set<T> toSet​(java.sql.ResultSet rs)
      Extracts all data from result set into a list using this mapping
      java.lang.reflect.Type type()
      Returns the data type for this mapping
      default DatabaseMapping.Binder<T> update()
      The binder to bind arguments to a PreparedStatement for affecting updates
    • Method Detail

      • type

        java.lang.reflect.Type type()
        Returns the data type for this mapping
        Returns:
        the data type
      • select

        default DatabaseMapping.Mapper<T> select()
        The mapper to map a row in a result set to some object
        Returns:
        the mapper to map a row in a result set to some object
      • insert

        default DatabaseMapping.Binder<T> insert()
        The binder to bind arguments to a PreparedStatement for affecting inserts
        Returns:
        binder to bind arguments to a PreparedStatement for affecting inserts
      • update

        default DatabaseMapping.Binder<T> update()
        The binder to bind arguments to a PreparedStatement for affecting updates
        Returns:
        binder to bind arguments to a PreparedStatement for affecting updates
      • delete

        default DatabaseMapping.Binder<T> delete()
        The binder to bind arguments to a PreparedStatement for affecting deletes
        Returns:
        binder to bind arguments to a PreparedStatement for affecting deletes
      • readBoolean

        static com.d3x.core.util.Option<java.lang.Boolean> readBoolean​(java.sql.ResultSet rs,
                                                                       int column)
                                                                throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readBoolean

        static com.d3x.core.util.Option<java.lang.Boolean> readBoolean​(java.sql.ResultSet rs,
                                                                       java.lang.String column)
                                                                throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readShort

        static com.d3x.core.util.Option<java.lang.Short> readShort​(java.sql.ResultSet rs,
                                                                   int column)
                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readShort

        static com.d3x.core.util.Option<java.lang.Short> readShort​(java.sql.ResultSet rs,
                                                                   java.lang.String column)
                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readInt

        static com.d3x.core.util.Option<java.lang.Integer> readInt​(java.sql.ResultSet rs,
                                                                   int column)
                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readInt

        static com.d3x.core.util.Option<java.lang.Integer> readInt​(java.sql.ResultSet rs,
                                                                   java.lang.String column)
                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readLong

        static com.d3x.core.util.Option<java.lang.Long> readLong​(java.sql.ResultSet rs,
                                                                 int column)
                                                          throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readLong

        static com.d3x.core.util.Option<java.lang.Long> readLong​(java.sql.ResultSet rs,
                                                                 java.lang.String column)
                                                          throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readFloat

        static com.d3x.core.util.Option<java.lang.Float> readFloat​(java.sql.ResultSet rs,
                                                                   int column)
                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readFloat

        static com.d3x.core.util.Option<java.lang.Float> readFloat​(java.sql.ResultSet rs,
                                                                   java.lang.String column)
                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readDouble

        static com.d3x.core.util.Option<java.lang.Double> readDouble​(java.sql.ResultSet rs,
                                                                     int column)
                                                              throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readDouble

        static com.d3x.core.util.Option<java.lang.Double> readDouble​(java.sql.ResultSet rs,
                                                                     java.lang.String column)
                                                              throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readString

        static com.d3x.core.util.Option<java.lang.String> readString​(java.sql.ResultSet rs,
                                                                     int column)
                                                              throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readString

        static com.d3x.core.util.Option<java.lang.String> readString​(java.sql.ResultSet rs,
                                                                     java.lang.String column)
                                                              throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readDate

        static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs,
                                                                int column)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readDate

        static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs,
                                                                java.lang.String column)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readDate

        static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs,
                                                                int column,
                                                                java.util.Calendar calendar)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        calendar - the calendar to initialize date
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readDate

        static com.d3x.core.util.Option<java.sql.Date> readDate​(java.sql.ResultSet rs,
                                                                java.lang.String column,
                                                                java.util.Calendar calendar)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        calendar - the calendar to initialize date
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readLocalDate

        static com.d3x.core.util.Option<java.time.LocalDate> readLocalDate​(java.sql.ResultSet rs,
                                                                           int column)
                                                                    throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readLocalDate

        static com.d3x.core.util.Option<java.time.LocalDate> readLocalDate​(java.sql.ResultSet rs,
                                                                           java.lang.String column)
                                                                    throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTime

        static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs,
                                                                int column)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTime

        static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs,
                                                                java.lang.String column)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTime

        static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs,
                                                                int column,
                                                                java.util.Calendar calendar)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        calendar - the calendar to initialize time
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTime

        static com.d3x.core.util.Option<java.sql.Time> readTime​(java.sql.ResultSet rs,
                                                                java.lang.String column,
                                                                java.util.Calendar calendar)
                                                         throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        calendar - the calendar to initialize time
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTimestamp

        static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs,
                                                                          int column)
                                                                   throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTimestamp

        static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs,
                                                                          java.lang.String column,
                                                                          java.util.Calendar calendar)
                                                                   throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        calendar - the calendar to initialize timestamp
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTimestamp

        static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs,
                                                                          int column,
                                                                          java.util.Calendar calendar)
                                                                   throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        calendar - the calendar to initialize timestamp
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readTimestamp

        static com.d3x.core.util.Option<java.sql.Timestamp> readTimestamp​(java.sql.ResultSet rs,
                                                                          java.lang.String column)
                                                                   throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readLocalDateTime

        static com.d3x.core.util.Option<java.time.LocalDateTime> readLocalDateTime​(java.sql.ResultSet rs,
                                                                                   int column)
                                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • readLocalDateTime

        static com.d3x.core.util.Option<java.time.LocalDateTime> readLocalDateTime​(java.sql.ResultSet rs,
                                                                                   java.lang.String column)
                                                                            throws java.sql.SQLException
        Returns an option on the value read from the ResultSet
        Parameters:
        rs - the result set to read from
        column - the column to access
        Returns:
        the option on value
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyBoolean

        static void applyBoolean​(java.sql.PreparedStatement stmt,
                                 int paramIndex,
                                 java.lang.Boolean value)
                          throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyInt

        static void applyInt​(java.sql.PreparedStatement stmt,
                             int paramIndex,
                             java.lang.Integer value)
                      throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyLong

        static void applyLong​(java.sql.PreparedStatement stmt,
                              int paramIndex,
                              java.lang.Long value)
                       throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyDouble

        static void applyDouble​(java.sql.PreparedStatement stmt,
                                int paramIndex,
                                java.lang.Double value)
                         throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyFloat

        static void applyFloat​(java.sql.PreparedStatement stmt,
                               int paramIndex,
                               java.lang.Float value)
                        throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyString

        static void applyString​(java.sql.PreparedStatement stmt,
                                int paramIndex,
                                java.lang.String value)
                         throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyDate

        static void applyDate​(java.sql.PreparedStatement stmt,
                              int paramIndex,
                              java.sql.Date value)
                       throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        Throws:
        java.sql.SQLException - if there is a SQL error
      • applyDate

        static void applyDate​(java.sql.PreparedStatement stmt,
                              int paramIndex,
                              java.sql.Date value,
                              java.util.Calendar calendar)
                       throws java.sql.SQLException
        Applies the value to the statement, calling PreparedStatement.setNull() if value is null
        Parameters:
        stmt - the statement to apply value to
        paramIndex - the parameter index
        value - the value to apply, can be null
        calendar - the calendar to control time zone
        Throws:
        java.sql.SQLException - if there is a SQL error
      • toSet

        default java.util.Set<T> toSet​(java.sql.ResultSet rs)
                                throws java.sql.SQLException
        Extracts all data from result set into a list using this mapping
        Parameters:
        rs - the result set to process
        Returns:
        the list of results
        Throws:
        java.sql.SQLException - if there is a SQL exception
      • toList

        default java.util.List<T> toList​(java.sql.ResultSet rs)
                                  throws java.sql.SQLException
        Extracts all data from result set into a list using this mapping
        Parameters:
        rs - the result set to process
        Returns:
        the list of results
        Throws:
        java.sql.SQLException - if there is a SQL exception
      • toIterator

        default java.util.Iterator<T> toIterator​(java.sql.ResultSet rs)
        Returns an iterator over the records generated by the ResultSet
        Parameters:
        rs - the SQL result set to extract records from
        Returns:
        the iterator with records
      • in

        static java.lang.String in​(java.util.Collection<?> values)
        Returns a command separated list of values for an in clause
        Parameters:
        values - the list of values, for example List.of("x", "y", "z")
        Returns:
        the in clause expression, for example ('x', 'y', 'z')
      • in

        static java.lang.String in​(java.util.Collection<?> values,
                                   com.d3x.core.util.Option<java.time.ZoneId> zoneId)
        Returns a command separated list of values for an in clause
        Parameters:
        values - the list of values, for example List.of("x", "y", "z")
        zoneId - the optional zone if for formatting LocalDateTime
        Returns:
        the in clause expression, for example ('x', 'y', 'z')
      • bindArgs

        static java.sql.PreparedStatement bindArgs​(java.sql.PreparedStatement stmt,
                                                   java.util.List<java.lang.Object> args)
                                            throws DatabaseException
        Binds an array of arguments to the prepared statement
        Parameters:
        stmt - the prepared statement object to bind args to
        args - the array of args to bind to statement
        Returns:
        the statement
        Throws:
        DatabaseException
      • bindArgs

        static java.sql.PreparedStatement bindArgs​(java.sql.PreparedStatement stmt,
                                                   java.util.TimeZone timeZone,
                                                   java.util.List<java.lang.Object> args)
                                            throws DatabaseException
        Binds an array of arguments to the prepared statement
        Parameters:
        stmt - the prepared statement object to bind args to
        timeZone - the time zone for timestamp related fields
        args - the array of args to bind to statement
        Returns:
        the statement
        Throws:
        DatabaseException
      • getSelectSql

        static <T> java.lang.String getSelectSql​(DatabaseMapping<T> mapping)
        Returns the SQL resolved from the DatabaseSql annotation on the select method
        Parameters:
        mapping - the mapping instance
        Returns:
        the SQL resolved from method
        Throws:
        DatabaseException - if no annotation on method
      • getInsertSql

        static <T> java.lang.String getInsertSql​(DatabaseMapping<T> mapping)
        Returns the SQL resolved from the DatabaseSql annotation on the insert method
        Parameters:
        mapping - the mapping instance
        Returns:
        the SQL resolved from method
        Throws:
        DatabaseException - if no annotation on method
      • getUpdateSql

        static <T> java.lang.String getUpdateSql​(DatabaseMapping<T> mapping)
        Returns the SQL resolved from the DatabaseSql annotation on the update method
        Parameters:
        mapping - the mapping instance
        Returns:
        the SQL resolved from method
        Throws:
        DatabaseException - if no annotation on method
      • getDeleteSql

        static <T> java.lang.String getDeleteSql​(DatabaseMapping<T> mapping)
        Returns the SQL resolved from the DatabaseSql annotation on the delete method
        Parameters:
        mapping - the mapping instance
        Returns:
        the SQL resolved from method
        Throws:
        DatabaseException - if no annotation on method
      • list

        static <T> java.util.List<T> list​(java.sql.ResultSet rs,
                                          DatabaseMapping.Mapper<T> mapper)
        Extracts records from the result set using the mapper and returns them as a list
        Type Parameters:
        T - the record type
        Parameters:
        rs - the result set to extract data from
        mapper - the mapper to generate records
        Returns:
        the list of records
      • set

        static <T> java.util.Set<T> set​(java.sql.ResultSet rs,
                                        DatabaseMapping.Mapper<T> mapper)
        Extracts records from the result set using the mapper and returns them as a set
        Type Parameters:
        T - the record type
        Parameters:
        rs - the result set to extract data from
        mapper - the mapper to generate records
        Returns:
        the set of records
      • iterator

        static <T> java.util.Iterator<T> iterator​(java.sql.ResultSet rs,
                                                  DatabaseMapping.Mapper<T> mapper)
        Returns an iterator that extracts records from ResultSet using the mapper
        Type Parameters:
        T - the record type
        Parameters:
        rs - the result set
        mapper - the record mapper
        Returns:
        the iterator
      • getSql

        static java.lang.String getSql​(DatabaseMapping<?> mapping,
                                       java.lang.String methodName)
        Returns the SQL resolved from the DatabaseSql annotation on the named method
        Parameters:
        mapping - the mapping instance
        methodName - the method name to inspect for annotation
        Returns:
        the SQL resolved from method
        Throws:
        DatabaseException - if no annotation on method