?? rightmgmtdaobyhibernate.java
字號:
package com.tarena.oss.rights.dao;
import java.sql.SQLException;
import java.util.Collection;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tarena.oss.rights.pojo.Rights;
public class RightMgmtDAOByHibernate extends HibernateDaoSupport implements RightMgmtDAO {
public void deleteRight(Rights r) {
this.getHibernateTemplate().delete(r);
}
public void insertRight(Rights r) {
this.getHibernateTemplate().save(r);
}
public boolean isUsed(Integer id) {
// TODO Auto-generated method stub
return false;
}
public Collection<Rights> queryAll() {
return this.getHibernateTemplate().find("from Rights");
}
public Collection<Rights> 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 {
org.hibernate.Query query =session.createQuery("from Rights");
query.setFirstResult(start);
query.setMaxResults(rows);
return query.list();
}
});
}
public Collection<Rights> queryAll(String condition) {
return this.getHibernateTemplate().find("from Rights r where 1=1" +condition);
}
public Collection<Rights> queryAll(String condition, int currentPage,
int rowCnt) {
final String conditions=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 {
org.hibernate.Query query =session.createQuery("from Rights where 1=1 "+ conditions);
query.setFirstResult(start);
query.setMaxResults(rows);
return query.list();
}
});
}
public Rights queryRightById(Integer id) {
return (Rights) this.getHibernateTemplate().get(Rights.class, id);
}
public int queryRowCounts() {
Long l=(Long) this.getHibernateTemplate().find("select count(*)from Rights").get(0);
return l.intValue();
}
public int queryRowCounts(String condition) {
Long l=(Long) this.getHibernateTemplate().find("select count(*)from Rights +where 1=1 "+condition).get(0);
return l.intValue();
}
public void updateRight(Rights r) {
this.getHibernateTemplate().saveOrUpdate(r);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -