Class RowMapperRegistry

java.lang.Object
de.chojo.sadu.mapper.RowMapperRegistry

public class RowMapperRegistry extends Object
Class to register RowMapper to map rows to objects.
  • Constructor Details

    • RowMapperRegistry

      public RowMapperRegistry()
  • Method Details

    • register

      public RowMapperRegistry register(RowMapper<?> rowMapper)
      Registers a new mapper for a class.

      A class can only have one mapper per column combination.

      Parameters:
      rowMapper - the mapper to register
      Throws:
      MappingAlreadyRegisteredException - when a mapping with the same column name exists already
    • register

      public RowMapperRegistry register(RowMapper<?>... rowMapper)
      Registers new mapper.

      A class can only have one mapper per column combination.

      Parameters:
      rowMapper - one or more mapper to register
      Throws:
      MappingAlreadyRegisteredException - when a mapping with the same column name exists already
    • register

      public RowMapperRegistry register(List<RowMapper<?>> rowMapper)
      Registers new mapper.

      A class can only have one mapper per column combination.

      Parameters:
      rowMapper - one or more mapper to register
      Throws:
      MappingAlreadyRegisteredException - when a mapping with the same column name exists already
    • wildcard

      public <T> Optional<RowMapper<T>> wildcard(Class<T> clazz)
      Gets the wild card mapper if registered.
      Type Parameters:
      T - type of mapper
      Parameters:
      clazz - class to get the mapper
      Returns:
      mapper if exists
    • find

      public <T> Optional<RowMapper<T>> find(Class<T> clazz, ResultSet set, MapperConfig config) throws SQLException
      Searches for a matching mapper for this result set.

      A mapper is matching when all columns the mapper needs are present in the result set.

      The mapper with the most matching columns will be returned.

      Type Parameters:
      T - return type of mapper
      Parameters:
      clazz - clazz to find a mapper for
      set - result set to find a matching mapper
      Returns:
      mapper when found
      Throws:
      SQLException
    • find

      public <T> Optional<RowMapper<T>> find(Class<T> clazz, ResultSetMetaData meta, MapperConfig config)
      Searches for a matching mapper for this result set.

      A mapper is matching when all columns the mapper needs are present in the result set.

      The mapper with the most matching columns will be returned.

      Type Parameters:
      T - return type of mapper
      Parameters:
      clazz - clazz to find a mapper for
      meta - result set meta to find a matching mapper
      Returns:
      mapper when found
    • findOrWildcard

      public <T> RowMapper<T> findOrWildcard(Class<T> clazz, ResultSet set, MapperConfig config) throws MappingException, SQLException
      Searches for a matching mapper for this result set.

      A mapper is matching when all columns the mapper needs are present in the result set.

      The mapper with the most matching columns will be returned.

      Type Parameters:
      T - return type of mapper
      Parameters:
      clazz - clazz to find a mapper for
      set - result set to find a matching mapper
      config - mapper config
      Returns:
      mapper when found
      Throws:
      MappingException - when no mapper was found for this class and no wildcard mapper is registered.
      SQLException
    • findOrWildcard

      public <T> RowMapper<T> findOrWildcard(Class<T> clazz, ResultSetMetaData meta, MapperConfig config) throws MappingException, SQLException
      Finds a mapper for a class for the matching column names. If no mapper was found a possible wildcard mapper will be returned.
      Type Parameters:
      T - type of row mapper
      Parameters:
      clazz - clazz
      meta - meta
      Returns:
      row mapper when found
      Throws:
      MappingException - when no mapper was found for this class and no wildcard mapper is registered.
      SQLException - if a database access error occurs
    • register

      public <V> void register(Class<V> clazz)
      Registers row mapper of a class if they contain a constructor or static method annotated with MappingProvider
      Type Parameters:
      V - type of class to be registered
      Parameters:
      clazz - clazz to be registered
      Throws:
      InvalidMappingException - when no mapping was found.