java增删改查封装实现_封装增删改查

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)  编辑  收藏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值