Advertisement
Guest User

Untitled

a guest
May 9th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. class Person...
  2. private String lastName;
  3. private String firstName;
  4. private int numberOfDependents;
  5.  
  6.  
  7. class AbstractMapper...
  8. protected Map loadedMap = new HashMap();
  9. abstract protected String findStatement();
  10. protected DomainObject abstractFind(Long id) {
  11.     DomainObject result = (DomainObject) loadedMap.get(id);
  12.     if (result != null) return result;
  13.     PreparedStatement findStatement = null;
  14.     try {
  15.         findStatement = DB.prepare(findStatement());
  16.         findStatement.setLong(1, id.longValue());
  17.         ResultSet rs = findStatement.executeQuery();
  18.         rs.next();
  19.         result = load(rs);
  20.         return result;
  21.     } catch (SQLException e) {
  22.         throw new ApplicationException(e);
  23.     } finally {
  24.         DB.cleanUp(findStatement);
  25.     }
  26. }
  27.  
  28.  
  29. class PersonMapper...
  30. protected String findStatement() {
  31.     return "SELECT " + COLUMNS +
  32.         " FROM people" +
  33.         " WHERE id = ?";
  34. }
  35. public static final String COLUMNS = " id, lastname, firstname, number_of_dependents ";
  36. public Person find(Long id) {
  37.     return (Person) abstractFind(id);
  38. }
  39. public Person find(long id) {
  40.     return find(new Long(id));
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement