コード例 #1
0
ファイル: CriteriaSearch.java プロジェクト: nwlg/Colony
 /**
  * Adds an <code>Expression</code> to a <code>Criteria</code>.
  *
  * @param criteria
  * @param parameterName
  * @param parameterValue
  * @param comparatorID
  * @param matchMode
  */
 private void addExpression(
     org.hibernate.Criteria criteria,
     String parameterName,
     Object parameterValue,
     int comparatorID,
     org.hibernate.criterion.MatchMode matchMode) {
   if (parameterValue != null) {
     switch (comparatorID) {
       case CriteriaSearchParameter.LIKE_COMPARATOR:
         {
           if ((matchMode != null) && (parameterValue instanceof String)) {
             criteria.add(
                 org.hibernate.criterion.Expression.like(
                     parameterName, (String) parameterValue, matchMode));
           } else {
             criteria.add(org.hibernate.criterion.Expression.like(parameterName, parameterValue));
           }
           break;
         }
       case CriteriaSearchParameter.INSENSITIVE_LIKE_COMPARATOR:
         {
           if ((matchMode != null) && (parameterValue instanceof String)) {
             criteria.add(
                 org.hibernate.criterion.Expression.ilike(
                     parameterName, (String) parameterValue, matchMode));
           } else {
             criteria.add(org.hibernate.criterion.Expression.ilike(parameterName, parameterValue));
           }
           break;
         }
       case CriteriaSearchParameter.EQUAL_COMPARATOR:
         {
           criteria.add(org.hibernate.criterion.Expression.eq(parameterName, parameterValue));
           break;
         }
       case CriteriaSearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR:
         {
           criteria.add(org.hibernate.criterion.Expression.ge(parameterName, parameterValue));
           break;
         }
       case CriteriaSearchParameter.GREATER_THAN_COMPARATOR:
         {
           criteria.add(org.hibernate.criterion.Expression.gt(parameterName, parameterValue));
           break;
         }
       case CriteriaSearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR:
         {
           criteria.add(org.hibernate.criterion.Expression.le(parameterName, parameterValue));
           break;
         }
       case CriteriaSearchParameter.LESS_THAN_COMPARATOR:
         {
           criteria.add(org.hibernate.criterion.Expression.lt(parameterName, parameterValue));
           break;
         }
     }
   } else {
     criteria.add(org.hibernate.criterion.Expression.isNull(parameterName));
   }
 }
コード例 #2
0
ファイル: PmsDaoImpl.java プロジェクト: rsyuxiangyang/myforum
 private Criterion findbyAnd(String type, String str) {
   Criterion criterion = null;
   List<String> srch = new ArrayList<String>();
   String[] srchAND = str.split(" and ");
   for (int i = 0; i < srchAND.length; i++) {
     String[] srch_ = srchAND[i].split(" ");
     for (int j = 0; j < srch_.length; j++) {
       if (cn.jsprun.utils.FormDataCheck.isValueString(srch_[j])) {
         srch.add(srch_[j]);
       }
     }
   }
   try {
     Criterion[] criterionArray = new Criterion[srch.size()];
     for (int i = 0; i < srch.size(); i++) {
       Criterion criterionCount = Expression.like(type, srch.get(i), MatchMode.ANYWHERE);
       criterionArray[i] = criterionCount;
     }
     for (int i = 0; i < criterionArray.length; i++) {
       if (i == 0) {
         criterion = Expression.and(criterionArray[i], criterionArray[i++]);
       } else {
         criterion = Expression.and(criterion, criterionArray[i]);
       }
     }
   } catch (HibernateException e) {
     e.printStackTrace();
     criterion = null;
   }
   return criterion;
 }
コード例 #3
0
 /** @see org.openmrs.api.db.LocationDAO#getAllLocationTags(boolean) */
 @SuppressWarnings("unchecked")
 public List<LocationTag> getAllLocationTags(boolean includeRetired) {
   Criteria criteria = sessionFactory.getCurrentSession().createCriteria(LocationTag.class);
   if (!includeRetired) {
     criteria.add(Expression.like("retired", false));
   }
   criteria.addOrder(Order.asc("name"));
   return criteria.list();
 }
コード例 #4
0
ファイル: ModeloNegocio.java プロジェクト: chuxmendoza/GDM2
 public static List<Modelo> Buscar(String nombre) {
   List<Modelo> lista = new ArrayList<>();
   try {
     Session session = HibernateUtils.getSession();
     Criteria crit = session.createCriteria(Modelo.class);
     crit.add(Expression.like("nombre", nombre, MatchMode.ANYWHERE));
     lista = (List<Modelo>) crit.list();
   } catch (Exception ex) {
     throw ex;
   }
   return lista;
 }
コード例 #5
0
 /** @see SerializedObjectDAO#getAllObjects(Class, boolean) */
 @SuppressWarnings("unchecked")
 public List<SerializedObject> getAllSerializedObjects(Class<?> type, boolean includeRetired)
     throws DAOException {
   Criteria c = sessionFactory.getCurrentSession().createCriteria(SerializedObject.class);
   c.add(
       Expression.or(
           Expression.eq("type", type.getName()), Expression.eq("subtype", type.getName())));
   if (!includeRetired) {
     c.add(Expression.like("retired", false));
   }
   return (List<SerializedObject>) c.list();
 }
コード例 #6
0
ファイル: SiteFilter.java プロジェクト: fthamura/cimande
  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;
  }
コード例 #7
0
ファイル: CriteriaSearch.java プロジェクト: nwlg/Colony
 /**
  * Adds an <code>Expression</code> to a <code>Criteria</code>. The given <code>parameterValues
  * </code> represents either an array of <code>String</code> or another object. The different
  * values in the array are added to a disjunction which is connected with logical and to the other
  * criteria of the search.
  *
  * @param criteria
  * @param parameterName
  * @param parameterValues
  * @param searchIfNull
  * @param comparatorID
  * @param matchMode
  */
 private void addExpression(
     org.hibernate.Criteria criteria,
     String parameterName,
     Object[] parameterValues,
     int comparatorID,
     org.hibernate.criterion.MatchMode matchMode) {
   if (parameterValues != null) {
     org.hibernate.criterion.Disjunction disjunction =
         org.hibernate.criterion.Expression.disjunction();
     switch (comparatorID) {
       case CriteriaSearchParameter.LIKE_COMPARATOR:
         {
           if ((matchMode != null) && (parameterValues instanceof String[])) {
             String[] stringParameterValues = (String[]) parameterValues;
             for (int index = 0; index < parameterValues.length; index++) {
               if (stringParameterValues[index] != null) {
                 disjunction.add(
                     org.hibernate.criterion.Expression.like(
                         parameterName, stringParameterValues[index], matchMode));
               } else {
                 disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
               }
             }
           } else {
             for (int index = 0; index < parameterValues.length; index++) {
               if (parameterValues[index] != null) {
                 disjunction.add(
                     org.hibernate.criterion.Expression.like(
                         parameterName, parameterValues[index]));
               } else {
                 disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
               }
             }
           }
           break;
         }
       case CriteriaSearchParameter.INSENSITIVE_LIKE_COMPARATOR:
         {
           if ((matchMode != null) && (parameterValues instanceof String[])) {
             String[] stringParameterValues = (String[]) parameterValues;
             for (int index = 0; index < parameterValues.length; index++) {
               if (stringParameterValues[index] != null) {
                 disjunction.add(
                     org.hibernate.criterion.Expression.ilike(
                         parameterName, stringParameterValues[index], matchMode));
               } else {
                 disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
               }
             }
           } else {
             for (int index = 0; index < parameterValues.length; index++) {
               if (parameterValues[index] != null) {
                 disjunction.add(
                     org.hibernate.criterion.Expression.ilike(
                         parameterName, parameterValues[index]));
               } else {
                 disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
               }
             }
           }
           break;
         }
       case CriteriaSearchParameter.EQUAL_COMPARATOR:
         {
           for (int index = 0; index < parameterValues.length; index++) {
             if (parameterValues[index] != null) {
               disjunction.add(
                   org.hibernate.criterion.Expression.eq(parameterName, parameterValues[index]));
             } else {
               disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
             }
           }
           break;
         }
       case CriteriaSearchParameter.GREATER_THAN_OR_EQUAL_COMPARATOR:
         {
           for (int index = 0; index < parameterValues.length; index++) {
             if (parameterValues[index] != null) {
               disjunction.add(
                   org.hibernate.criterion.Expression.ge(parameterName, parameterValues[index]));
             } else {
               disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
             }
           }
           break;
         }
       case CriteriaSearchParameter.GREATER_THAN_COMPARATOR:
         {
           for (int index = 0; index < parameterValues.length; index++) {
             if (parameterValues[index] != null) {
               disjunction.add(
                   org.hibernate.criterion.Expression.gt(parameterName, parameterValues[index]));
             } else {
               disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
             }
           }
           break;
         }
       case CriteriaSearchParameter.LESS_THAN_OR_EQUAL_COMPARATOR:
         {
           for (int index = 0; index < parameterValues.length; index++) {
             if (parameterValues[index] != null) {
               disjunction.add(
                   org.hibernate.criterion.Expression.le(parameterName, parameterValues[index]));
             } else {
               disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
             }
           }
           break;
         }
       case CriteriaSearchParameter.LESS_THAN_COMPARATOR:
         {
           for (int index = 0; index < parameterValues.length; index++) {
             if (parameterValues[index] != null) {
               disjunction.add(
                   org.hibernate.criterion.Expression.lt(parameterName, parameterValues[index]));
             } else {
               disjunction.add(org.hibernate.criterion.Expression.isNull(parameterName));
             }
           }
           break;
         }
     }
     criteria.add(disjunction);
   } else {
     criteria.add(org.hibernate.criterion.Expression.isNull(parameterName));
   }
 }
コード例 #8
0
ファイル: SearchCategory.java プロジェクト: fthamura/cimande
  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;
      }
    }
  }
コード例 #9
0
  public List getComments(
      WebsiteData website,
      WeblogEntryData entry,
      String searchString,
      Date startDate,
      Date endDate,
      Boolean pending,
      Boolean approved,
      Boolean spam,
      boolean reverseChrono,
      int offset,
      int length)
      throws RollerException {

    try {
      Session session = ((HibernatePersistenceStrategy) this.strategy).getSession();
      Criteria criteria = session.createCriteria(CommentData.class);

      if (entry != null) {
        criteria.add(Expression.eq("weblogEntry", entry));
      } else if (website != null) {
        criteria.createAlias("weblogEntry", "e");
        criteria.add(Expression.eq("e.website", website));
      }

      if (searchString != null) {
        criteria.add(
            Expression.disjunction()
                .add(Expression.like("url", searchString, MatchMode.ANYWHERE))
                .add(Expression.like("content", searchString, MatchMode.ANYWHERE)));
      }

      if (startDate != null) {
        criteria.add(Expression.ge("postTime", startDate));
      }

      if (endDate != null) {
        criteria.add(Expression.le("postTime", endDate));
      }

      if (pending != null) {
        criteria.add(Expression.eq("pending", pending));
      }

      if (approved != null) {
        criteria.add(Expression.eq("approved", approved));
      }

      if (spam != null) {
        criteria.add(Expression.eq("spam", spam));
      }

      if (length != -1) {
        criteria.setMaxResults(offset + length);
      }

      if (reverseChrono) {
        criteria.addOrder(Order.desc("postTime"));
      } else {
        criteria.addOrder(Order.asc("postTime"));
      }

      List comments = criteria.list();
      if (offset == 0 || comments.size() < offset) {
        return comments;
      }
      List range = new ArrayList();
      for (int i = offset; i < comments.size(); i++) {
        range.add(comments.get(i));
      }
      return range;

    } catch (HibernateException e) {
      log.error(e);
      throw new RollerException(e);
    }
  }