DatabaseHelperクラスのインスタンスを参照できていることがこのDAOクラスを書く上での前提条件。
このソースではAbstractDAOクラスを作成し、ContextManagerパターンを使用して、DatabaseHelperを提供している。

public class ResultDao extends AbstractDao {

  public Long save(Result result) {
    // 追加もしくは更新
    try {
      if (result.getId() == null){
        result.setId(System.currentTimeMillis());
        getHelper().getResultDao().create(result);
      } else {
        getHelper().getResultDao().update(result);
      }
      return result.getId();
    } catch (Exception e){
      setError(e);
      return null;
    }
  }

  public List findAll() {
    // 全件取得
    try {
      return getHelper().getResultDao().queryForAll();
    } catch (Exception e){
      setError(e);
      return null;
    }
  }

  public Result findByID(Long id) {
    // 指定IDでレコード取得
    try {
      return getHelper().getResultDao().queryForId(id);
    } catch (Exception e){
      setError(e);
      return null;
    }
  }

  public List findByItemId(Long itemId){
    // 指定マスターIDで全件取得
    try {
      return getHelper().getResultDao().queryForEq(Result.COL_NAME_ITEM_ID, itemId);
    } catch (Exception e){
      setError(e);
      return null;
    }
  }

  public List findByIdRange(Long startId, Long endId){
    // IDの範囲の全件取得
    try {
      QueryBuilder qb = getHelper().getResultDao().queryBuilder();
      Where where = qb.where();
      where.between(Result.COL_NAME_ID, startId, endId);
      qb.setWhere(where);
      qb.orderBy(Result.COL_NAME_ID, true);
      return qb.query();
    } catch (Exception e){
      setError(e);
      return null;
    }
  }

  public void remove(Long id) {
    // 指定IDでレコード削除
    try {
      getHelper().getResultDao().deleteById(id);
    } catch (Exception e){
      setError(e);
    }
  }

}