Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person...
- private String lastName;
- private String firstName;
- private int numberOfDependents;
- class AbstractMapper...
- protected Map loadedMap = new HashMap();
- abstract protected String findStatement();
- protected DomainObject abstractFind(Long id) {
- DomainObject result = (DomainObject) loadedMap.get(id);
- if (result != null) return result;
- PreparedStatement findStatement = null;
- try {
- findStatement = DB.prepare(findStatement());
- findStatement.setLong(1, id.longValue());
- ResultSet rs = findStatement.executeQuery();
- rs.next();
- result = load(rs);
- return result;
- } catch (SQLException e) {
- throw new ApplicationException(e);
- } finally {
- DB.cleanUp(findStatement);
- }
- }
- class PersonMapper...
- protected String findStatement() {
- return "SELECT " + COLUMNS +
- " FROM people" +
- " WHERE id = ?";
- }
- public static final String COLUMNS = " id, lastname, firstname, number_of_dependents ";
- public Person find(Long id) {
- return (Person) abstractFind(id);
- }
- public Person find(long id) {
- return find(new Long(id));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement