Initial set of mappers initialized.

COMPONENT JAVA
Applying Design Patterns to JDBC: Building a Lightweight Object-Relational Mapping Framework
Frank Sauer
Listing 3. Initial set of mappers initialized.


protected Mapper getMapper(Object key) {
  if (mappers == null) {
      mappers = new HashMap();
      registerMapper(Byte.class,
                 Types.TINYINTnew ByteMapper());
      DateMapper dm = new DateMapper();
      registerMapper(java.util.Date.class,
                 Types.DATE, dm);
      // always convert sql Dates to util
      // Dates from ResultSets
      registerMapper(java.sql.Date.class,
                 0, dm);
      registerMapper(Double.class,
                 Types.DOUBLE,
                 new DoubleMapper());
      registerMapper(Float.class, Types.FLOAT,
                  new FloatMapper());
      registerMapper(Integer.class,
                 Types.INTEGER,
                 new IntMapper());
      registerMapper(BigDecimal.class,
                 Types.NUMERIC,
                 new NumericMapper());
      registerMapper(Long.class, Types.BIGINT,
                 new LongMapper());
      registerMapper(Short.class,
                 Types.SMALLINT,
                 new ShortMapper());
      StringMapper strm = new StringMapper();
      registerMapper(String.class,
                 Types.VARCHAR, strm);
      registerMapper(null, Types.LONGVARCHAR,
                 strm);
      registerMapper(Time.class, Types.TIME,
                 new TimeMapper());
      registerMapper(Timestamp.class,
                 Types.TIMESTAMP,
                 new TimestampMapper());
  }
  return (Mapper)mappers.get(key);
}