Exemplo n.º 1
0
  public String execute() {
    try {

      sess = hsf.createSession();
      Criteria crit = sess.createCriteria(Site.class);

      if (!getKeyword().equalsIgnoreCase("")) {
        String keywordQuery = "%" + getKeyword() + "%";

        crit.add(
            Expression.disjunction()
                .add(Expression.like("name", keywordQuery).ignoreCase())
                .add(Expression.like("description", keywordQuery).ignoreCase())
                .add(Expression.like("title", keywordQuery).ignoreCase())
                .add(Expression.like("url_branding", keywordQuery).ignoreCase())
                .add(Expression.like("site_url", keywordQuery).ignoreCase())
                .add(Expression.like("admin_email", keywordQuery).ignoreCase())
                .add(Expression.like("notify_email", keywordQuery).ignoreCase())
                .add(Expression.like("notify_from", keywordQuery).ignoreCase())
                .add(Expression.like("notify_message", keywordQuery).ignoreCase()));
      }

      sites = crit.list();
      //			sess.flush();
      hsf.endSession(sess);
    } catch (HibernateException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      try {
        hsf.closeSession(sess);
      } catch (HibernateException e1) {
        e1.printStackTrace();
      } catch (SQLException e1) {
        e1.printStackTrace();
      }
    }

    return SUCCESS;
  }
Exemplo n.º 2
0
  public String execute() {
    try {

      sess = hsf.createSession();
      Criteria crit = sess.createCriteria(Category.class);

      categoryDescriptor = (Descriptor) pm.getById(Descriptor.class, getDescriptor_id());
      parentCategory = (Category) pm.getById(Category.class, getIparentcode());

      if (!getId().equalsIgnoreCase("")) {
        crit.add(Expression.like("id", "%" + getId() + "%"));
      }
      if (!getCode().equalsIgnoreCase("")) {
        crit.add(Expression.like("code", "%" + getCode() + "%"));
      }
      if (!getDescription().equalsIgnoreCase("")) {
        crit.add(Expression.like("description", "%" + getDescription() + "%"));
      }
      if (!getUrl_category_image().equalsIgnoreCase("")) {
        crit.add(Expression.like("url_category_image", "%" + getUrl_category_image() + "%"));
      }

      if (!getDescriptor_id().equalsIgnoreCase("")) {
        crit.add(Expression.like("categoryDescriptor.id", "%" + getDescriptor_id() + "%"));
      }
      if (!getIparentcode().equalsIgnoreCase("")) {
        crit.add(Expression.like("parentCategory.id", "%" + getIparentcode() + "%"));
      }

      if (getActiveFlag() != -1) {
        crit.add(Expression.eq("logInformation.activeFlag", new Integer(getActiveFlag())));
      }

      resultRows = crit.list().size();

      maxPage = resultRows / maxRowPerPage;
      if (resultRows % maxRowPerPage == 0) maxPage = maxPage - 1;

      categories =
          crit.addOrder(Order.asc(orderBy))
              .setFirstResult(currPage * maxRowPerPage)
              .setMaxResults(maxRowPerPage)
              .list();

      prevPage = currPage - 1;
      nextPage = currPage + 1;
      page = currPage + 1;

      hsf.endSession(sess);
      return SUCCESS;

    } catch (HibernateException e) {
      return ERROR;
    } catch (SQLException e) {
      return ERROR;
    } finally {
      try {
        hsf.closeSession(sess);
      } catch (HibernateException e1) {
        return ERROR;
      } catch (SQLException e1) {
        return ERROR;
      }
    }
  }