package com.seipher.dao.callCenterInterface;
import com.seipher.pojo.Entity;
import net.sf.hibernate.HibernateException;
import java.util.List;
/**
* Created by IntelliJ IDEA
* Date: 2008-7-10
* Time: 9:06:18
*
* @author mengle
*/
public interface BaseDaoInterface {
public Entity load(Long id) throws HibernateException;
public void store(Entity entity) throws HibernateException;
public void update(Entity entity) throws HibernateException;
public void delete(Entity entity) throws HibernateException;
public void delete(Long id) throws HibernateException;
public List findAll(String entityName) throws HibernateException;
}
package com.seipher.dao.callCenter;
import com.seipher.pojo.Entity;
import com.seipher.dao.callCenterInterface.BaseDaoInterface;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.Session;
import net.virgosoft.framework.HibernateSession;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Created by IntelliJ IDEA
* Date: 2008-7-10
* Time: 9:05:05
*
* @author mengle
*/
abstract public class BaseDao implements BaseDaoInterface {
private Session session = null;
private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
public Entity load(Long id) throws HibernateException {
session = HibernateSession.callCenterSession();
return (Entity) session.load(this.getEntityClass(), id);
}
public void store(Entity entity) throws HibernateException {
session = HibernateSession.callCenterSession();
Transaction tx = session.beginTransaction();
session.save(entity);
tx.commit();
session.flush();
}
public void update(Entity entity) throws HibernateException {
session = HibernateSession.callCenterSession();
Transaction tx = session.beginTransaction();
session.update(entity);
tx.commit();
session.flush();
}
public void delete(Entity entity) throws HibernateException {
session = HibernateSession.callCenterSession();
Transaction tx = session.beginTransaction();
session.delete(entity);
tx.commit();
session.flush();
}
public void delete(Long id) throws HibernateException {
Entity entity = this.load(id);
this.delete(entity);
}
public List findAll(String entityName) throws HibernateException {
session = HibernateSession.callCenterSession();
return session.find("from " + entityName);
}
abstract protected Class getEntityClass();
}
posted on 2009-04-25 11:21 雨飞 阅读(132) 评论(0) 编辑 收藏