package com.corej2eepatterns.util;

// importy
public class TORowMapper {

  // utworzenie obiektu CustomerTO
  public CustomerTO createCustomerTO(RowSet rowSet) {
    CustomerTO to = new CustomerTO();
    to.setId(getString(rowSet), 0);
    to.setName(getString(rowSet), 1);
    . . .
  }

  // utworzenie innych obiektw transferowych
  . . .

  // implementacja prostych metod wykorzystywanych przez metody tworzenia
  protected boolean wasNull(RowSet rowSet) {
    try {
      return rowSet.wasNull();
    } catch (SQLException e) {
      throw new RuntimeException(e.getMessage());
    }
  }

  protected String getString(RowSet rowSet, int columnIndex) {
    try {
      return rowSet.getString(columnIndex);
    } catch (SQLException e) {
      throw new RuntimeException(e.getMessage());
    }
  }

  protected boolean getBoolean(
      RowSet rowSet, int columnIndex) {
    try {
      return rowSet.getBoolean(columnIndex);
    } catch (SQLException e) {
      throw new RuntimeException(e.getMessage());
    }
  }

  protected java.util.Date getDate(
      RowSet rowSet, int columnIndex) {
    try {
      return rowSet.getDate(columnIndex);
    } catch (SQLException e) {
      throw new RuntimeException(e.getMessage());
    }
  }

  // Pozostae metody pobierania dla kolejnych typw danych.
  . . . 

}