Example #1
0
  protected Response query(Request request, DetachedCriteria obj, boolean lazyLoad, int maxResult)
      throws Exception {
    Response rsp = new Response();
    log.info("Detached Criteria Query :" + obj.toString());

    if (request.getIsCount() != null && request.getIsCount()) {
      obj = (DetachedCriteria) SerializationUtils.clone(obj);

      HibernateCallback callBack = getExecuteCountCriteriaHibernateCallback(obj);
      Integer rowCount = (Integer) getHibernateTemplate().execute(callBack);
      log.debug("DetachedCriteria ORMDAOImpl ===== count = " + rowCount);
      rsp.setRowCount(rowCount);
    } else {
      HibernateCallback callBack =
          getExecuteFindQueryCriteriaHibernateCallback(
              obj,
              lazyLoad,
              request.getFirstRow() == null ? -1 : request.getFirstRow(),
              maxResult > 0 ? maxResult : this.getResultCountPerQuery());
      List rs = (List) getHibernateTemplate().execute(callBack);
      rsp.setRowCount(rs.size());
      rsp.setResponse(rs);
    }

    return rsp;
  }
Example #2
0
  // if (obj instanceof HQLCriteria)
  protected Response query(
      Request request, HQLCriteria hqlCriteria, boolean lazyLoad, int maxResult) throws Exception {
    if (request.getIsCount() != null && request.getIsCount()) {
      String countQ = hqlCriteria.getCountHqlString();
      if (countQ == null) countQ = getCountQuery(hqlCriteria.getHqlString());
      log.info("HQL Query :" + countQ);
      Response rsp = new Response();
      HibernateCallback callBack =
          getExecuteCountQueryHibernateCallback(countQ, hqlCriteria.getParameters());
      Integer rowCount = Integer.parseInt(getHibernateTemplate().execute(callBack) + "");
      log.debug("HQL Query : count = " + rowCount);
      rsp.setRowCount(rowCount);
      return rsp;
    } else {
      log.info("HQL Query :" + hqlCriteria.getHqlString());
      Response rsp = new Response();
      HibernateCallback callBack =
          getExecuteFindQueryHibernateCallback(
              hqlCriteria.getHqlString(),
              hqlCriteria.getParameters(),
              lazyLoad,
              request.getFirstRow() == null ? -1 : request.getFirstRow(),
              maxResult > 0 ? maxResult : this.getResultCountPerQuery());
      List rs = (List) getHibernateTemplate().execute(callBack);

      rsp.setRowCount(rs.size());
      rsp.setResponse(rs);
      return rsp;
    }
  }