ITeye博客

实现自己的HibernateCallBack

hongsoft · 2004-12-29 22:03 · Spring · Markdown

我们知道,Spring中,HibernateTemplate是依靠回调函数HibernateCallBack来实现其功能的,但在我们的系统中, 这个CallBack可能不满足我们的要求,这时,我们就需要实现自己的HibernateCallBack,本文讨论实现 自己的HibernateCallBack的方法.
1:声明回调接口 public interface HongSoftCallback {     Object doInHongSoft(Connection aConn, Object arg)             throws HongSoftException; }
2:定义回调函数(HibernateTemplate.java) public Object load(final int id) throws DataAccessException {   return execute(new HongSoftCallback() {    public Object doInHongSoft(Connection aConn, Object arg)             throws HongSoftException; {     return aConn.load(arg.toString(), id);    }   }); } 这里定义了回调函数,并通过execute()调用了该回调函数
3:具体的execute()方法
try {    Object result = action.doInHongSoft(conn,id);       return result;   }   catch (HongSoftException ex) {    throw convertHongSoftException(ex);   }   finally   {     conn.close();   }
4:调用回调函数 return getHibernateTemplate().load(3);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。