pricedaoimpl.java

来自「电信计费项目 该系统在Sun Solaris下开发,运行于Apache Tom」· Java 代码 · 共 92 行

JAVA
92
字号
package com.tarena.netctoss.model.persist;import java.util.List;import org.hibernate.*;import com.tarena.util.*;import com.tarena.netctoss.model.biz.entity.Price;public class PriceDAOImpl implements IPriceDAO {	public void delete(Price price) throws PriceException{		Session session = HibernateFactoryManager.getSession();		try {			session.delete(price);		} catch (HibernateException e) {			e.printStackTrace();			throw new PriceException("delete Priceerror");		}	}	@SuppressWarnings("unchecked")	public List<Price> findAll() throws PriceException{		Session session = HibernateFactoryManager.getSession();		List<Price> prices = null;		String hql = "from Price";		try {			Query q = session.createQuery(hql);			prices = q.list();		} catch (HibernateException e) {			e.printStackTrace();			throw new PriceException("find all Price error");		}		return prices;	}	public void insert(Price price) throws PriceException{		Session session = HibernateFactoryManager.getSession();		try {			session.save(price);                        System.out.println("insert service");		} catch (HibernateException e) {			e.printStackTrace();			throw new PriceException("insert Price error");		}	} 	public void update(Price price) throws PriceException{		Session session = HibernateFactoryManager.getSession();		try {			Price p = findByID(price.getPrice_id());			p.setPrice_name(price.getPrice_name());			p.setPrice_descripte(price.getPrice_descripte());			p.setBase_fee(price.getBase_fee());			p.setRate_fee(price.getRate_fee());			session.update(p);		} catch (HibernateException e) {			e.printStackTrace();			throw new PriceException("update Price error");		}	}		public Price findByID(Long price_id) throws PriceException{		Price price = null;		Session session = HibernateFactoryManager.getSession();		String hql = "from Price price where price.price_id=?";		try {			Query q = session.createQuery(hql);			q.setLong(0, price_id);			price = (Price) q.uniqueResult();		} catch (HibernateException e) {			e.printStackTrace();			throw new PriceException("find by id Price error");		}		return price;	}		public Price findByName(String price_name) throws PriceException{		Price price = null;		Session session = HibernateFactoryManager.getSession();		String hql = "from Price price where price.price_name=?";		try {			Query q = session.createQuery(hql);			q.setString(0, price_name);			price = (Price) q.uniqueResult();		} catch (HibernateException e) {			e.printStackTrace();			throw new PriceException("find by id Price error");		}		return price;	}}

⌨️ 快捷键说明

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