package com.shopping.core.base;


import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.shopping.core.dao.IGenericDAO;

public class GenericDAO<T>
  implements IGenericDAO<T>
{
  protected  Class<T> entityClass;

  @Autowired
  @Qualifier("genericEntityDao")
  private GenericEntityDao geDao;

  public Class<T> getEntityClass()
  {
    return this.entityClass;
  }

  public void setEntityClass(Class<T> entityClass) {
    this.entityClass = entityClass;
  }

  public GenericEntityDao getGeDao() {
    return this.geDao;
  }

  public void setGeDao(GenericEntityDao geDao) {
    this.geDao = geDao;
  }

  public GenericDAO() {
    this.entityClass = 
      ((Class)((java.lang.reflect.ParameterizedType)getClass()
      .getGenericSuperclass()).getActualTypeArguments()[0]);
  }

  public GenericDAO(Class<T> type)
  {
    this.entityClass = type;
  }

  public int batchUpdate(String jpql, Object[] params)
  {
    return this.geDao.batchUpdate(jpql, params);
  }

  public List executeNamedQuery(String queryName, Object[] params, int begin, int max)
  {
    return this.geDao.executeNamedQuery(queryName, params, begin, max);
  }

  public List executeNativeNamedQuery(String nnq)
  {
    return this.geDao.executeNativeNamedQuery(nnq);
  }

  public List executeNativeQuery(String nnq, Object[] params, int begin, int max)
  {
    return this.geDao.executeNativeQuery(nnq, params, begin, max);
  }

  public int executeNativeSQL(String nnq)
  {
    return this.geDao.executeNativeSQL(nnq);
  }

  public List find(String query, Map params, int begin, int max)
  {
    return getGeDao()
      .find(this.entityClass, query, params, begin, max);
  }

  public void flush()
  {
    this.geDao.flush();
  }

  public T get(Serializable id)
  {
    return (T) getGeDao().get(this.entityClass, id);//.get(this.entityClass, id);
  }

  public T getBy(String propertyName, Object value)
  {
    return (T) getGeDao().getBy(this.entityClass, propertyName, value);
  }

  public List query(String query, Map params, int begin, int max)
  {
    return getGeDao().query(query, params, begin, max);
  }

  public void remove(Serializable id)
  {
    getGeDao().remove(this.entityClass, id);
  }

  public void save(Object newInstance)
  {
    getGeDao().save(newInstance);
  }

  public void update(Object transientObject)
  {
    getGeDao().update(transientObject);
  }
}
最近下载更多
zolscy  LV24 2024年11月28日
杨豫川  LV12 2024年3月14日
SDLFJL  LV6 2023年8月16日
testuser1234567  LV24 2022年6月15日
oulingqiao  LV13 2022年6月8日
wanglinddad  LV55 2022年4月10日
evagsd  LV6 2022年1月3日
sanshao526  LV12 2021年5月30日
有一种心情叫痛心  LV8 2021年4月16日
ewan007  LV30 2021年3月30日
最近浏览更多
sn764889012 4月16日
暂无贡献等级
ryadmin123  LV2 2月14日
zolscy  LV24 2024年11月28日
lyh1989  LV34 2024年7月21日
TY0165  LV20 2024年6月24日
郭宇航裹裹  LV5 2024年6月9日
刘守曜 2024年4月24日
暂无贡献等级
杨豫川  LV12 2024年3月14日
ljhgff  LV1 2024年2月11日
liiiyou  LV1 2024年1月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友