📄 pricingmgmtdaobyhibernate.java
字号:
package com.tarena.oss.pricing.dao;
import java.sql.SQLException;
import java.util.Collection;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tarena.oss.pricing.pojo.Pricing;
public class PricingMgmtDAOByHibernate extends HibernateDaoSupport implements
PricingMgmtDAO {
public void deletePricing(Pricing p) {
this.getHibernateTemplate().delete(p);
}
public void insertPricing(Pricing p) {
this.getHibernateTemplate().save(p);
}
public boolean isUsed(Integer id) {
// TODO Auto-generated method stub
return false;
}
public Collection<Pricing> queryAll() {
return this.getHibernateTemplate().find("from Pricing");
}
public Collection<Pricing> queryAll(String condition) {
return this.getHibernateTemplate().find("from Pricing p where 1=1 " + condition);
}
public Pricing queryPricingById(Integer id) {
return (Pricing) this.getHibernateTemplate().get(Pricing.class, id);
}
public void updatePricing(Pricing p) {
this.getHibernateTemplate().saveOrUpdate(p);
}
public Collection<Pricing> queryAll(int currentPage, int rowCnt) {
final int start = (currentPage - 1) * rowCnt;
final int rows = rowCnt;
return this.getHibernateTemplate().executeFind(
new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery("from Pricing");
query.setFirstResult(start);
query.setMaxResults(rows);
return query.list();
}
});
}
public Collection<Pricing> queryAll(String condition, int currentPage, int rowCnt) {
final String coditions =condition;
final int start = (currentPage - 1) * rowCnt;
final int rows = rowCnt;
return this.getHibernateTemplate().executeFind(
new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery("from Pricing where 1=1 "+ coditions);
query.setFirstResult(start);
query.setMaxResults(rows);
return query.list();
}
});
}
public int queryRowCounts() {
Long l = (Long) this.getHibernateTemplate().find("select count(*) from Pricing").get(0);
return l.intValue();
}
public int queryRowcounts(String condition) {
Long l = (Long) this.getHibernateTemplate().find("select count(*) from Pricing where 1=1" +condition).get(0);
return l.intValue();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -