SSH框架整合之HibernateDAO工具类


import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/*DESC--此类是用于SSH框架整合时候的DAO工具类*/
public class HiberDaoUtil extends HibernateDaoSupport{
/*查询一组对象--返回一组pojo*/
public Object getObjectPOJO(String hql) {
  List list = null;
  Object object = null;
  try {
   list = getHibernateTemplate().find(hql);
   if (list.size() == 1) {
    object = (Object) list.get(0);
   }
  } catch (DataAccessException ex) {
   System.out.print("@@@登陆时候查询用户名抛出异常@@@");
   ex.printStackTrace();
  }
  return object;
}
/*查询全部--返回一个List*/
public List getObjectALL(String hql){
  List list = null;
  try{
  list = getHibernateTemplate().find(hql);
  }catch (DataAccessException ex) {
   System.out.print("@@@查询全部抛出异常@@@");
   ex.printStackTrace();
  }
  return list;
}
/*插入操作--返回boolean*/
    public boolean addObject(Object object){
     boolean flag = false;
     try{
         this.getHibernateTemplate().save(object);
         flag = true;
     }catch(DataAccessException ex){
      System.out.print("@@@插入操作抛出异常@@@");
      ex.printStackTrace();
      flag = false;
     }
     return flag;
    }
    /*删除操作--返回boolean*/
    public boolean deleteObject(Object object){
     boolean flag = false;
     try{
      this.getHibernateTemplate().delete(object);
      flag = true;
     }catch(DataAccessException ex) {
      System.out.print("@@@删除操作抛出异常@@@");
      ex.printStackTrace();
      flag = false;
  }
     return flag;
    }
    /*修改操作*/
    public boolean updateObject(Object object){
     boolean flag = false;
     try{
      this.getHibernateTemplate().update(object);
     }catch (DataAccessException ex) {
      System.out.print("@@@修改操作抛出异常@@@");
   ex.printStackTrace();
   flag = false;
  }
     return flag;
    }
}

你可能感兴趣的:(DAO,框架,orm,ssh)