📄 hibernatepricingdao.java
字号:
package tarena.netctoss.dao;
import java.util.*;
import tarena.netctoss.exception.*;
import tarena.netctoss.model.*;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.hibernate.Session;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.Query;
public class HibernatePricingDAO extends HibernateDaoSupport implements PricingDAO {
/**
* deletePricing
*
* @param pricing Tpricing
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public void deletePricing(Tpricing pricing) throws InfrastructureException {
try{
this.getHibernateTemplate().delete(pricing);
}catch(Exception e){
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
/**
* deletePricing
*
* @param pricingId Long
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public void deletePricing(Long pricingId) throws InfrastructureException {
Tpricing pricing = new Tpricing();
pricing.setPricingId(pricingId);
try{
this.getHibernateTemplate().delete(pricing);
}catch(Exception e){
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
/**
* deletePricings
*
* @param pricingId Long[]
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public void deletePricings(Long[] pricingId) throws InfrastructureException {
final StringBuffer sql = new StringBuffer(
"delete from Tpricing pricing where pricing.pricingId in(");
for (int i = 0; i < pricingId.length; i++) {
if (i == 0)
sql.append(pricingId[i]);
else
sql.append("," + pricingId[i]);
}
sql.append(")");
try {
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws SQLException,
HibernateException {
Query query = session.createQuery(sql.toString());
query.executeUpdate();
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
/**
* insertPricing
*
* @param pricing Tpricing
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public void insertPricing(Tpricing pricing) throws InfrastructureException {
try{
this.getHibernateTemplate().save(pricing);
}catch(Exception e){
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
/**
* selectAllPricing
*
* @return Collection
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public Collection selectAllPricing() throws InfrastructureException {
try{
return (Collection)this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws SQLException,
HibernateException {
return session.createQuery("from Tpricing").list();
}
});
}catch(Exception e){
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
/**
* selectPricingByBaseFeeAndRateFee
*
* @param baseFee double
* @param rateFee double
* @return boolean
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public boolean selectPricingByBaseFeeAndRateFee(double baseFee,
double rateFee) throws InfrastructureException {
final double baseFeeTemp = baseFee;
final double rateFeeTemp = rateFee;
Integer i = (Integer)this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws SQLException,
HibernateException {
Query query = session.createQuery("select count(*) from Tpricing pricing where pricing.baseFee=? and pricing.rateFee=?");
return query.setDouble(0,baseFeeTemp).setDouble(1,rateFeeTemp).uniqueResult();
}
});
if(i.intValue()==0){
return false;
}else{
return true;
}
}
/**
* selectPricingById
*
* @param pricingId Long
* @return Tpricing
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public Tpricing selectPricingById(Long pricingId) throws
InfrastructureException {
try{
return (Tpricing)this.getHibernateTemplate().load(Tpricing.class,
pricingId);
}catch(Exception e){
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
/**
* updatePricing
*
* @param pricing Tpricing
* @throws InfrastructureException
* @todo Implement this tarena.netctoss.dao.PricingDAO method
*/
public void updatePricing(Tpricing pricing) throws InfrastructureException {
try{
this.getHibernateTemplate().update(pricing);
}catch(Exception e){
e.printStackTrace();
throw new InfrastructureException(e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -