Class NullDelegatingMapper<T>

  • Type Parameters:
    T -
    All Implemented Interfaces:
    RowMapper<T>

    public final class NullDelegatingMapper<T>
    extends java.lang.Object
    implements RowMapper<T>
    Delegating mapper that implements the @PropagateNull semantics to check a specific column in the result set for null first. If that column is null, return null as the value, otherwise executed the delegated mapper.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void init​(ConfigRegistry registry)
      Allows for initialization of the row mapper instance within a ConfigRegistry scope.
      T map​(java.sql.ResultSet rs, StatementContext ctx)
      Map the current row of the result set.
      RowMapper<T> specialize​(java.sql.ResultSet rs, StatementContext ctx)
      Returns a specialized row mapper, optimized for the given result set.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • index

        private final int index
    • Constructor Detail

      • NullDelegatingMapper

        public NullDelegatingMapper​(int index,
                                    RowMapper<T> delegate)
    • Method Detail

      • init

        public void init​(ConfigRegistry registry)
        Description copied from interface: RowMapper
        Allows for initialization of the row mapper instance within a ConfigRegistry scope. This method is called once when the row mapper is first used from a ConfigRegistry.

        Note that handles, statements, sql objects etc. all create copies of the registry, and this method will be called for every copy

        Specified by:
        init in interface RowMapper<T>
        Parameters:
        registry - A reference to the ConfigRegistry that this instance belongs to.
      • map

        public T map​(java.sql.ResultSet rs,
                     StatementContext ctx)
              throws java.sql.SQLException
        Description copied from interface: RowMapper
        Map the current row of the result set. This method should not cause the result set to advance; allow Jdbi to do that, please.
        Specified by:
        map in interface RowMapper<T>
        Parameters:
        rs - the result set being iterated
        ctx - the statement context
        Returns:
        the value to produce for this row
        Throws:
        java.sql.SQLException - if anything goes wrong go ahead and let this percolate; Jdbi will handle it
      • specialize

        public RowMapper<T> specialize​(java.sql.ResultSet rs,
                                       StatementContext ctx)
                                throws java.sql.SQLException
        Description copied from interface: RowMapper
        Returns a specialized row mapper, optimized for the given result set.

        Before mapping the result set from a SQL statement; Jdbi will first call this method to obtain a specialized instance. The returned mapper will then be used to map the result set rows, and discarded.

        Implementing this method is optional; the default implementation returns this. Implementors might choose to override this method to improve performance, e.g. by matching up column names to properties once for the entire result set, rather than repeating the process for every row.

        Specified by:
        specialize in interface RowMapper<T>
        Parameters:
        rs - the result set to specialize over
        ctx - the statement context to specialize over
        Returns:
        a row mapper equivalent to this one, possibly specialized.
        Throws:
        java.sql.SQLException - if anything goes wrong go ahead and let this percolate; Jdbi will handle it
        See Also:
        for an example of specialization.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object