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

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

 2009-11-17 00:00:00 来源:WEB开发网   
核心提示: AbstractGeneralDAOImpl<T, ID extends Serializable>1:importjava.io.Serializable;2:importjava.lang.reflect.ParameterizedType;3:4:importorg.apach

AbstractGeneralDAOImpl<T, ID extends Serializable>

   1:  import java.io.Serializable;
   2:  import java.lang.reflect.ParameterizedType;
   3:   
   4:  import org.apache.commons.logging.Log;
   5:  import org.apache.commons.logging.LogFactory;
   6:   
   7:  /**
   8:   * Abstract General DAO Implement
   9:   * 
  10:   * @author Hacker-TTAO
  11:   * @version 0.1.0
  12:   */
  13:  public abstract class AbstractGeneralDAOImpl<T, ID extends Serializable> implements GeneralDAO<T, ID> {
  14:   
  15:      private final Log log = LogFactory.getLog(this.getClass());
  16:   
  17:      protected final Class<T> persistenceClass;
  18:   
  19:      protected final Class<T> pkClass;
  20:   
  21:      protected AbstractGeneralDAOImpl() {
  22:          this.persistenceClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  23:          this.pkClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
  24:   
  25:          if (log.isInfoEnabled()) {
  26:              log.info("解析泛型参数 T : " + getPersistenceClass().getName());
  27:          }
  28:      }
  29:   
  30:      protected final Class<T> getPersistenceClass() {
  31:          return persistenceClass;
  32:      }
  33:   
  34:      protected Class<T> getPkClass() {
  35:          return pkClass;
  36:      }
  37:  }

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

Tags:JavaEE 架构 DAO

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