posts - 0,  comments - 1,  trackbacks - 0

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</a>
 */
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</a>
 */
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 雨飞 阅读(243) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

<2025年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

留言簿

文章档案

搜索

  •  

最新评论