JavaEE 3层架构的 DAO, Service, Web 简单封装
2009-11-17 00:00:00 来源:WEB开发网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: }
更多精彩
赞助商链接