package com.utstar.nms.vmm.spring.dao;
import Java(Java教程 Java培训 ).io.Serializable;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.utstar.nms.vmm.spring.util.GenericsUtils;
public class HibernateEntityDao《T》 extends HibernateDaoSupport
implements EntityDao《T》 {
protected Class《T》 entityClass;
public HibernateEntityDao() {
entityClass = GenericsUtils.getSuperClassGenricType(getClass());
}
/**
* find an object by its id
* @param id
* @return an object
*/
public T findByID(Serializable id) {
return (T) getHibernateTemplate().get(entityClass, id);
}
/**
* @return find all objects
*/
public List《T》 findAll()
{
return getHibernateTemplate().loadAll(entityClass);
}
/**
* find objects by sql(jdbc) or hql(hibernate)
* @param ql
* @param values parameter that
* @return an objects list of the query result
*/
public List《T》 findByQL(String hql, Object.。. values)
{
return getHibernateTemplate().find(hql, values);
}
/**
* save the object input
* @param o
*/
public void save(Object object)
{
getHibernateTemplate().save(object);
}
/**
* update the object input
* @param o
*/
public void update(Object object)
{
getHibernateTemplate().update(object);
}
/**
* saveOrUpdate the object input
* @param o
*/
public void saveOrUpdate(Object object)
{
getHibernateTemplate().saveOrUpdate(object);
}
/**
* delete the object input
* @param o
*/
public void remove(Object object)
{
/*delete the object*/
getHibernateTemplate().delete(object);
}
/**
* delete an object by its id
* @param id
*/
public void removeById(Serializable id)
{
/*find the object by id*/
Object object=findByID(id);
/*delete the object*/
remove(object);
}
}