Package org.crank.crud.criteria

Examples of org.crank.crud.criteria.Comparison


  }

  @Test
  public void test() {
    paginatableDataSource.group().add(
        new Comparison("firstName", Operator.LIKE, "J%"));
    //int count =
      paginatableDataSource.getCount();
//    AssertJUnit.assertEquals(2, count);
//    AssertJUnit.assertEquals(2, paginatableDataSource.list(0, 10).size());
//    Employee employee = (Employee) paginatableDataSource.list(0, 3).get(0);
View Full Code Here


      employeeDao.persist(employee);
    }
    employeeDao.flushAndClear();
    paginatableDataSource.group().clear();
    paginatableDataSource.group().add(
        new Comparison("firstName", Operator.LIKE, "FOO%"));
    int count = paginatableDataSource.getCount();
    AssertJUnit.assertEquals(100, count);
  }
View Full Code Here


    public void testWhereClause () {
        Group group = new Group();
        group.eq("lastName", "Jones").eq("firstName", "Tom");
        Comparison comparison = Comparison.eq("middleName", "Milhouse");
        comparison.setCaseSensitive(false);
        group.add(comparison);
        String whereClause = CriteriaUtils.constuctWhereClause(group);
        assertEquals(" WHERE  o.lastName = :lastName  AND  o.firstName = :firstName  " +
                "AND  UPPER(  o.middleName )  =  UPPER( :middleName  ) ", whereClause);
View Full Code Here

    if (group.size() > 0) {
      builder.append(" WHERE ");
      /* If the current iteration is a comparison, use it. */
      for (Criterion criterion : group) {
        if (criterion instanceof Comparison) {
          Comparison comparison = (Comparison) criterion;
          if (comparison.getName().equals("taskCount")) {
            continue;
          }
          builder.append(comparison.getName());
          builder.append(" " + comparison.getOperator().getOperator());
          builder.append(" ? ");
          builder.append("AND ");
        }
      }
      return builder.toString().substring(0,builder.length()-4);
View Full Code Here

   */
  protected Object[] extractValues() {
    List <Object> values = new ArrayList<Object>();
    for (Criterion criterion : group) {
      if (criterion instanceof Comparison) {
        Comparison comparison = (Comparison) criterion;
        if (comparison.getOperator() == Operator.LIKE || comparison.getOperator() == Operator.LIKE_START) {
          String sValue = (String) comparison.getValue();
          values.add(sValue + "%");
        } else {
          values.add(comparison.getValue());
        }
      }
    }
    return values.toArray(new Object[values.size()]);
  }
View Full Code Here

    }
    for (Criterion criterion : group) {
      if (criterion instanceof Group) {
        addGroupParams(query, (Group) criterion, names);
      } else {
        Comparison comparison = (Comparison) criterion;
       
        if (comparison.isObjectIdentity()) {
          continue;
        }
       
        String name = CriteriaUtils.ditchDot(comparison.getName());

        name = CriteriaUtils.ensureUnique(names, name);

        if (comparison.getValue() != null) {
          final String sOperator = comparison.getOperator()
              .getOperator();
          if (!"like".equalsIgnoreCase(sOperator)) {
            if (comparison instanceof Between) {
              Between between = (Between) comparison;
              query.setParameter(name + "_1", comparison
                  .getValue());
              query
                  .setParameter(name + "_2", between
                      .getValue2());
            } else if (comparison instanceof VerifiedBetween) {
              VerifiedBetween between = (VerifiedBetween) comparison;
              query.setParameter(name + "_1", comparison
                  .getValue());
              query
                  .setParameter(name + "_2", between
                      .getValue2());
            } else {
              query.setParameter(name, comparison.getValue());
            }

          } else {
            Operator operator = comparison.getOperator();
            StringBuilder value = new StringBuilder(50);
            if (operator == Operator.LIKE) {
              value.append(comparison.getValue());
            } else if (operator == Operator.LIKE_CONTAINS) {
              value.append("%").append(comparison.getValue())
                  .append("%");
            } else if (operator == Operator.LIKE_END) {
              value.append("%").append(comparison.getValue());
            } else if (operator == Operator.LIKE_START) {
              value.append(comparison.getValue()).append("%");
            }
            if (logger.isDebugEnabled()) {
              logger.debug("parameters");
              logger
                  .debug("value name = "
                      + comparison.getName());
              logger.debug("value value = " + value);
            }
            query.setParameter(name, value.toString());
          }
        }
View Full Code Here

TOP

Related Classes of org.crank.crud.criteria.Comparison

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.