DAO层小结2(查询)

  /**
   * 查询功能点表
   * @param vo FuncNodeVO
   * @throws SysException
   * @throws AppException
   * @return List
   */
  public List findFuncNode(FuncNodeVO vo) throws
                  SysException, AppException {
          List list = findFuncNodePO(vo);
          ArrayList ret = new ArrayList();
          try {
                  if (list != null) {
                          PropertyCopy.PO2VO(list,ret);
                  }
          } catch (PropertyCopyException ex) {
            ex.printStackTrace();
                  throw new SysException("9000005",
                                  "FuncNodeDAO.findFuncNode():PropertyCopyException", ex);
          }
          return ret;
  }

  /**
   * 根据一定条件查询PartyRel表的数据
   * @param vo FuncNodeVO
   * @throws SysException
   * @throws AppException
   * @return List
   */

  private List findFuncNodePO(FuncNodeVO vo) throws
                  SysException, AppException {
          String hql = constructHql(vo);
          Query query = null;
          try {
                  query = session.createQuery(hql);
          } catch (HibernateException ex) {
                  throw new SysException("9000004",
                                  "FuncNodeDAO.findFuncNodelPO():生成功能点表查询对象出错", ex);
          }
          try {
                  return query.list();
          } catch (HibernateException ex) {
                  throw new SysException("9000004",
                                  "FuncNodeDAO.findFuncNodelPO():查询功能点表记录出错", ex);
          }

  }

  /**
  * 构造Hql
  * @param vo FuncNodeVO 包含查询条件
  * @param flag String 查询新旧记录标志
  * @throws SysException
  * @throws AppException
  * @return String 返回Hql
  */
 private String constructHql(FuncNodeVO vo) throws
                 SysException, AppException {
         String hql = "from FuncNode as a where ";
         if (vo.getFuncNodeId() != null) {
                 hql = hql + "a.funcNodeId='" + vo.getFuncNodeId() + "' and ";
         }
         if (vo.getFuncNodeCode() != 0 ) {
                 hql = hql + "a.funcNodeCode='" + vo.getFuncNodeCode() + "' and ";
         }
         if (vo.getFuncNodeName() !=null ){
           hql = hql + "a.funcNodeName='" + vo.getFuncNodeName() + "' and ";
         }
         if (vo.getSubSystemName() != null) {
                 hql = hql + "a.subSystemName='" + vo.getSubSystemName() + "' and ";
         }
         if ( vo.getFuncNodeType() !=null ) {
                 hql = hql + "a.funcNodeType='" + vo.getFuncNodeType() + "' and ";
         }
         if (vo.getNodeTreeId() != null ){
                 hql = hql + "a.nodeTreeId='" + vo.getNodeTreeId() + "' and ";
         }


         if (hql.endsWith("where ")) {
                 hql = hql.substring(0, hql.length() - 6);
         } else {
                 hql = hql.substring(0, hql.length() - 4);
         }
         return hql;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值