@Repository("fxyDao")
public List<TBasEnterprise> findAllTBasEnterprise() throws Exception{
String hql = "from TBasEnterprise";
System.out.println(1);
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
System.out.println(2);
list = this.getHibernateTemplate().find(hql);
System.out.println(3);
return list;
}
public List<TBasEnterprise> findAllTBasEnterprise(final int page,final int pageSize)
throws Exception {
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "from TBasEnterprise";
Query query = session.createQuery(hql);
query.setFirstResult((page-1)*pageSize);
query.setMaxResults(pageSize);
return query.list();
}
});
return list;
}
@Override
public List<TBasEnterprise> findAllTBasEnterprise(final Page page,final String hql)
throws Exception {
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult((page.getNowPage()-1)*page.getPageSize());
query.setMaxResults(page.getPageSize());
return query.list();
}
});
return list;
}
@Override
public String getStringValue(final String sql) throws Exception {
// TODO Auto-generated method stub
List<String> list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});
return list.get(0);
}
@Override
public int getRowsBySql(final String sql) throws Exception {
List<Integer> list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});
return list.get(0);
}
}
public class FxyDaoImpl extends HibernateDaoSupport implements FxyDao{
//以下内容必须写入,才可以使用HibernateDaoSupport中的各种代理方法
private SessionFactory mySessionFacotry;
@Resource
public void setMySessionFacotry(SessionFactory sessionFacotry) {
this.mySessionFacotry = sessionFacotry;
}
@PostConstruct
public void injectSessionFactory() {
super.setSessionFactory(mySessionFacotry);
}
public List<TBasEnterprise> findAllTBasEnterprise() throws Exception{
String hql = "from TBasEnterprise";
System.out.println(1);
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
System.out.println(2);
list = this.getHibernateTemplate().find(hql);
System.out.println(3);
return list;
}
public List<TBasEnterprise> findAllTBasEnterprise(final int page,final int pageSize)
throws Exception {
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "from TBasEnterprise";
Query query = session.createQuery(hql);
query.setFirstResult((page-1)*pageSize);
query.setMaxResults(pageSize);
return query.list();
}
});
return list;
}
@Override
public List<TBasEnterprise> findAllTBasEnterprise(final Page page,final String hql)
throws Exception {
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult((page.getNowPage()-1)*page.getPageSize());
query.setMaxResults(page.getPageSize());
return query.list();
}
});
return list;
}
@Override
public String getStringValue(final String sql) throws Exception {
// TODO Auto-generated method stub
List<String> list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});
return list.get(0);
}
@Override
public int getRowsBySql(final String sql) throws Exception {
List<Integer> list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});
return list.get(0);
}
}