⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbdaohibernate.java

📁 Struts数据库开发中的一个案例
💻 JAVA
字号:
package com.relationinfo.dao.hibernate;import java.util.List;import com.relationinfo.model.Mb;import com.relationinfo.dao.MbDAO;import org.hibernate.HibernateException;import org.hibernate.Session;import org.hibernate.criterion.Example;import org.hibernate.criterion.MatchMode;import org.springframework.orm.ObjectRetrievalFailureException;import org.springframework.orm.hibernate3.HibernateCallback;public class MbDAOHibernate extends BaseDAOHibernate implements MbDAO {    /**     * @see com.relationinfo.dao.MbDAO#getMbs(com.relationinfo.model.Mb)     */    public List getMbs(final Mb mb) {        if (mb == null) {            return getHibernateTemplate().find("from Mb");        } else {            // filter on properties set in the mb            HibernateCallback callback = new HibernateCallback() {                public Object doInHibernate(Session session) throws HibernateException {                    Example ex = Example.create(mb).ignoreCase().enableLike(MatchMode.ANYWHERE);                    return session.createCriteria(Mb.class).add(ex).list();                }            };            return (List) getHibernateTemplate().execute(callback);        }    }    /**     * @see com.relationinfo.dao.MbDAO#getMb(String mbbm)     */    public Mb getMb(final String mbbm) {        Mb mb = (Mb) getHibernateTemplate().get(Mb.class, mbbm);        if (mb == null) {            log.warn("uh oh, mb with mbbm '" + mbbm + "' not found...");            throw new ObjectRetrievalFailureException(Mb.class, mbbm);        }        return mb;    }    /**     * @see com.relationinfo.dao.MbDAO#saveMb(Mb mb)     */        public void saveMb(final Mb mb) {        getHibernateTemplate().saveOrUpdate(mb);    }    /**     * @see com.relationinfo.dao.MbDAO#removeMb(String mbbm)     */    public void removeMb(final String mbbm) {        getHibernateTemplate().delete(getMb(mbbm));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -