WEB开发网
开发学院软件开发Java JavaEE 3层架构的 DAO, Service, Web 简单封装 阅读

JavaEE 3层架构的 DAO, Service, Web 简单封装

 2009-11-17 00:00:00 来源:WEB开发网   
核心提示: AbstractServiceImpl<T, ID extends Serializable, DAO extends GeneralDAO<T, ID>>1:importjava.io.Serializable;2:importjava.util.Collection;

AbstractServiceImpl<T, ID extends Serializable, DAO extends GeneralDAO<T, ID>>

   1:  import java.io.Serializable;
   2:  import java.util.Collection;
   3:  import java.util.List;
   4:   
   5:  import org.apache.commons.logging.Log;
   6:  import org.apache.commons.logging.LogFactory;
   7:   
   8:  /**
   9:   * 
  10:   * @author Hacker-TTAO
  11:   *
  12:   * @param <T>
  13:   * @param <ID>
  14:   * @param <DAO>
  15:   */
  16:  public abstract class AbstractServiceImpl<T, ID extends Serializable, DAO extends GeneralDAO<T, ID>> implements GeneralService<T, ID, DAO> {
  17:   
  18:      private DAO dao;
  19:   
  20:      private static final Log log = LogFactory.getLog(AbstractServiceImpl.class);
  21:   
  22:      public List<T> findAll() {
  23:          List<T> result = getDao().findAll();
  24:          log.info("findAll execute success");
  25:          return result;
  26:      }
  27:   
  28:      public T findByID(ID id) {
  29:          T result = getDao().findByID(id);
  30:          log.info("findById execute success");
  31:          return result;
  32:      }
  33:   
  34:      public void delete(Collection<T> entities) {
  35:          getDao().update(entities);
  36:      }
  37:   
  38:      public void delete(T entity) {
  39:          getDao().delete(entity);
  40:      }
  41:   
  42:      public void delete(ID id) {
  43:          getDao().delete(id);
  44:      }
  45:   
  46:      public void marge(T... eneity) {
  47:      }
  48:   
  49:      public void marge(T eneity) {
  50:          getDao().marge(eneity);
  51:   
  52:      }
  53:   
  54:      public void save(T... entity) {
  55:          getDao().save(entity);
  56:      }
  57:   
  58:      public T save(T entity) {
  59:          return getDao().save(entity);
  60:      }
  61:   
  62:      public void saveOrUpdate(Collection<T> entities) {
  63:          getDao().saveOrUpdate(entities);
  64:      }
  65:   
  66:      public void saveOrUpdate(T entity) {
  67:          getDao().saveOrUpdate(entity);
  68:      }
  69:   
  70:      public void update(Collection<T> entity) {
  71:          getDao().update(entity);
  72:      }
  73:   
  74:      public T update(T entity) {
  75:          return getDao().update(entity);
  76:      }
  77:   
  78:      public DAO getDao() {
  79:          return dao;
  80:      }
  81:   
  82:      public void setDao(DAO dao) {
  83:          this.dao = dao;
  84:      }
  85:   
  86:  }

上一页  1 2 3 4 5 6 7  下一页

Tags:JavaEE 架构 DAO

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接