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

📄 hibernatepricingdao.java

📁 电信系统
💻 JAVA
字号:
package tarena.netctoss.dao;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import tarena.netctoss.dao.PricingDAO;
import tarena.netctoss.model.Tpricing;
import java.util.Collection;
import tarena.netctoss.exception.InfrastructureException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.hibernate.Session;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.Query;

public class HibernatePricingDAO extends HibernateDaoSupport implements
        PricingDAO {
    public HibernatePricingDAO() {
        super();
    }

    public void insertPricing(Tpricing pricing) throws InfrastructureException {
        try {
            this.getHibernateTemplate().save(pricing);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }
    }

    public void deletePricing(Tpricing pricing) throws InfrastructureException {
        try {
            this.getHibernateTemplate().delete(pricing);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }

    }

    public void deletePricing(Integer id) throws InfrastructureException {
        Tpricing pricing = new Tpricing();
        pricing.setId(id);
        try {
            this.getHibernateTemplate().delete(pricing);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }
    }

    public void deletePricings(Integer[] ids) throws InfrastructureException {
        StringBuffer buf = new StringBuffer(
                "delete from Tpricing where id in(");
        for (int i = 0; i < ids.length; i++) {
            buf.append(ids[i]);
            if (i < ids.length - 1) {
                buf.append(",");
            }
        }
        buf.append(")");
        final String hql = buf.toString();
        try {
            Query query = (Query)this.getHibernateTemplate().execute(new
                    HibernateCallback() {
                public Object doInHibernate(Session session) throws
                        SQLException,
                        HibernateException {
                    return session.createQuery(hql);
                }
            });
            query.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }
    }

    public void updatePricing(Tpricing pricing) throws InfrastructureException {
        try {
            this.getHibernateTemplate().update(pricing);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }

    }

    public Collection selectAllPricings() throws InfrastructureException {
        try {
            return this.getHibernateTemplate().find("from Tpricing");
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }

    }

    public Tpricing selectPricingById(Integer id) throws
            InfrastructureException {
        try {
            return (Tpricing)this.getHibernateTemplate().get(Tpricing.class, id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }

    }

    public boolean selectPricingByBaseFeeAndRateFee(Double baseFee,
            Double rateFee) throws InfrastructureException {
        try {
            if (this.getHibernateTemplate().find(
                    "from Tpricing pricing where pricing.baseFee=? and pricing.rateFee=?",
                    new Object[] {baseFee, rateFee}).size() == 0) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new InfrastructureException(e);
        }
    }
}

⌨️ 快捷键说明

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