Example usage for org.hibernate.criterion Restrictions not

List of usage examples for org.hibernate.criterion Restrictions not

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions not.

Prototype

public static Criterion not(Criterion expression) 

Source Link

Document

Return the negation of an expression

Usage

From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java

@Override
@Transactional/*from   w  w  w . ja v a  2 s . c  om*/
public String closeShop(Shop shop) throws Exception {
    ExceptionUtil.checkParamStringNullAndEmpty(shop.getShopNo());
    Shop shopPo = shopDao.get("shopNo", shop.getShopNo());
    Criteria criteria = orderDao.createCriteria(Restrictions.eq("shopNo", shop.getShopNo()));
    criteria.add(Restrictions.not(Restrictions.in("basicState",
            new String[] { OrderConstants.BASIC_STATE_WAITING_PAY, OrderConstants.BASIC_STATE_COMPLETED,
                    OrderConstants.BASIC_STATE_CLOSED, OrderConstants.BASIC_STATE_ALREADY_REFUND })));
    List<Order> orders = criteria.list();
    if (orders != null && !orders.isEmpty()) {
        return "hasOrder";
    } else {
        shopPo.setStatus(3);
        shopDao.update(shopPo);
        cartItemDao.delete("shopNo", shop.getShopNo());
        return "success";
    }
}

From source file:cpcc.core.services.RealVehicleRepositoryImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from w w w. j a v a2  s.  c  o m*/
 */
@SuppressWarnings("unchecked")
@Override
public List<RealVehicle> findAllActiveRealVehiclesExceptOwn() {
    Parameter rvNameParam = qm.findParameterByName(Parameter.REAL_VEHICLE_NAME);
    if (rvNameParam == null) {
        return findAllActiveRealVehicles();
    }

    return (List<RealVehicle>) session.createCriteria(RealVehicle.class)
            .add(Restrictions.not(Restrictions.eq(REAL_VEHICLE_NAME, rvNameParam.getValue())))
            .add(Restrictions.eq("deleted", Boolean.FALSE)).list();
}

From source file:cpcc.vvrte.services.db.TaskRepositoryImpl.java

License:Open Source License

/**
 * {@inheritDoc}/* w w w  . java2 s .c  o  m*/
 */
@SuppressWarnings("unchecked")
@Override
public List<Task> findAllIncompleteTasks() {
    return session.createCriteria(Task.class)
            .add(Restrictions.not(Restrictions.eq("taskState", TaskState.COMPLETED)))
            .add(Restrictions.not(Restrictions.eq("taskState", TaskState.EXECUTED)))
            .addOrder(Order.desc("executionStart")).addOrder(Order.desc("order"))
            .addOrder(Order.desc("creationTime")).list();
}

From source file:cz.jirutka.rsql.hibernate.AbstractCriterionBuilder.java

License:Open Source License

/**
 * Apply a negative case-insensitive "like" constraint to the named property. 
 * Value should contains wildcards "*" (% in SQL) and "_".
 * /*from w ww .ja  v  a2 s.c o m*/
 * @param propertyPath property name prefixed with an association alias
 * @param argument Value with wildcards.
 * @return Criterion
 */
protected Criterion createNotLike(String propertyPath, Object argument) {
    return Restrictions.not(createLike(propertyPath, argument));
}

From source file:cz.jirutka.rsql.hibernate.AbstractCriterionBuilderTest.java

License:Open Source License

@Test
public void testCreateCriterion3args() {
    String property = "foo";
    Criterion exptected;/*from   ww  w . j  a  va 2s. c om*/
    Criterion actual;

    exptected = Restrictions.eq(property, "bar");
    actual = instance.createCriterion(property, Comparison.EQUAL, "bar");
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.ilike(property, "bar%");
    actual = instance.createCriterion(property, Comparison.EQUAL, "bar*");
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.ne(property, "bar");
    actual = instance.createCriterion(property, Comparison.NOT_EQUAL, "bar");
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.not(Restrictions.ilike(property, "%bar"));
    actual = instance.createCriterion(property, Comparison.NOT_EQUAL, "*bar");
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.gt(property, 42);
    actual = instance.createCriterion(property, Comparison.GREATER_THAN, 42);
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.ge(property, -42);
    actual = instance.createCriterion(property, Comparison.GREATER_EQUAL, -42);
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.lt(property, 42.2);
    actual = instance.createCriterion(property, Comparison.LESS_THAN, 42.2);
    assertEquals(exptected.toString(), actual.toString());

    exptected = Restrictions.le(property, -42.2);
    actual = instance.createCriterion(property, Comparison.LESS_EQUAL, -42.2);
    assertEquals(exptected.toString(), actual.toString());

}

From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java

License:Apache License

@Override
public Criterion visit(ComparisonNode node) {
    String name = node.getSelector();
    /*/*from   w  w  w . j  a va2  s. c  o m*/
     Get the path and property names
     */
    Tuple<Type, String>[] path = getPath(root, name);
    Type type = getType(path);
    boolean isPrimitive = type instanceof StringRepresentableType;
    boolean isCustom = type instanceof CustomType;
    boolean isCollection = type instanceof CollectionType;

    String exp = getExpression(path, isCollection);
    List<Object> arguments = new ArrayList<Object>(node.getArguments().size());
    for (String argument : node.getArguments()) {
        Object value = argument;
        if (isPrimitive) {
            value = ((StringRepresentableType) type).fromStringValue((String) value);
        } else if (isCustom) {
            value = ((CustomType) type).stringToObject((String) value);
        } else if (isCollection) {
            value = IntegerType.INSTANCE.fromString((String) value);
        }
        if (value instanceof String) {
            value = toSqlWildcardString((String) value);
        }
        arguments.add(value);
    }
    ComparisonOperator operator = node.getOperator();

    assert arguments.size() >= 1;

    Object firstArgument = arguments.get(0);
    if (operator.equals(RSQLOperators.EQUAL)) {
        if (!isCollection) {
            if (String.class.isInstance(firstArgument) && ((String) firstArgument).contains("%")) {
                return Restrictions.ilike(exp, firstArgument);
            } else {
                return Restrictions.eq(exp, firstArgument);
            }
        } else {
            return Restrictions.sizeEq(exp, (Integer) firstArgument);
        }
    } else if (operator.equals(RSQLOperators.NOT_EQUAL)) {
        if (!isCollection) {
            if (String.class.isInstance(firstArgument) && ((String) firstArgument).contains("%")) {
                return Restrictions.not(Restrictions.ilike(exp, firstArgument));
            } else {
                return Restrictions.ne(exp, firstArgument);
            }
        } else {
            return Restrictions.sizeNe(exp, (Integer) firstArgument);
        }
    } else if (operator.equals(RSQLOperators.GREATER_THAN)) {
        if (!isCollection) {
            return Restrictions.gt(exp, firstArgument);
        } else {
            return Restrictions.sizeGt(exp, (Integer) firstArgument);
        }
    } else if (operator.equals(RSQLOperators.GREATER_THAN_OR_EQUAL)) {
        if (!isCollection) {
            return Restrictions.ge(exp, firstArgument);
        } else {
            return Restrictions.sizeGe(exp, (Integer) firstArgument);
        }
    } else if (operator.equals(RSQLOperators.LESS_THAN)) {
        if (!isCollection) {
            return Restrictions.lt(exp, firstArgument);
        } else {
            return Restrictions.sizeLt(exp, (Integer) firstArgument);
        }
    } else if (operator.equals(RSQLOperators.LESS_THAN_OR_EQUAL)) {
        if (!isCollection) {
            return Restrictions.le(exp, firstArgument);
        } else {
            return Restrictions.sizeLe(exp, (Integer) firstArgument);
        }
    } else if (operator.equals(RSQLOperators.IN)) {
        if (!isCollection) {
            return Restrictions.in(exp, arguments);
        }
    } else if (operator.equals(RSQLOperators.NOT_IN)) {
        if (!isCollection) {
            return Restrictions.not(Restrictions.in(exp, arguments));
        }
    }
    throw new IllegalArgumentException("Unknown operation " + operator.toString() + " for property" + name);
}

From source file:de.cosmocode.hibernate.CustomRestrictions.java

License:Apache License

/**
 * Apply a "not empty" constraint to the named property.
 * //  w  w w  . j  a  va  2  s .c o  m
 * <p>
 *   See also {@link StringUtils#isNotEmpty(String)}
 * </p>
 * 
 * @param propertyName the name of the property the constraint should be applied to
 * @return a new {@link Criterion}
 */
public static Criterion isNotEmpty(String propertyName) {
    return Restrictions.not(CustomRestrictions.isEmpty(propertyName));
}

From source file:de.cosmocode.hibernate.CustomRestrictions.java

License:Apache License

/**
 * Apply a "not ilike" constraint on the named property.
 * //from w ww . ja v  a2s .  co  m
 * <p>
 *   This implementation handles empty values correctly.
 * </p>
 * 
 * @param propertyName the name of the property the constraint should be applied to
 * @param value the actual value the property should be similiar to
 * @param matchMode the {@link MatchMode} being used
 * @return a new {@link Criterion}
 */
public static Criterion notIlike(String propertyName, String value, MatchMode matchMode) {
    if (StringUtils.isEmpty(value)) {
        return CustomRestrictions.isNotEmpty(propertyName);
    } else {
        return Restrictions.or(Restrictions.not(Restrictions.ilike(propertyName, value, matchMode)),
                CustomRestrictions.isEmpty(propertyName));
    }
}

From source file:de.cosmocode.hibernate.CustomRestrictions.java

License:Apache License

/**
 * Apply a "not reverse ilike" expression on the named property.
 * //w w w .  ja v a 2 s.c o  m
 * @see ReverseIlikeExpression
 * @see PropertyMatchMode
 * 
 * @param propertyName the name of the property the constraint should be applied to
 * @param value the actual value which should not be similiar to the named property
 * @param matchMode the {@link PropertyMatchMode} being used
 * @return a new {@link Criterion}
 */
public static Criterion notReverseIlike(String propertyName, String value, PropertyMatchMode matchMode) {
    return Restrictions.not(CustomRestrictions.reverseIlike(propertyName, value, matchMode));
}

From source file:de.decidr.model.filters.EqualsFilter.java

License:Apache License

@Override
public void apply(Criteria criteria) {
    if (propertyValue == null) {
        // checking against null is a special case
        if (include) {
            criteria.add(Restrictions.isNull(propertyName));
        } else {//w  w  w .j  a v  a 2  s . c  o  m
            criteria.add(Restrictions.isNotNull(propertyName));
        }
    } else {
        if (include) {
            criteria.add(Restrictions.eq(propertyName, propertyValue));
        } else {
            criteria.add((Restrictions.not(Restrictions.eq(propertyName, propertyValue))));
        }
    }
}