Java Code Examples for javax.persistence.criteria.CriteriaBuilder.isNotNull()

The following are Jave code examples for showing how to use isNotNull() of the javax.persistence.criteria.CriteriaBuilder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: sctalk   File: SimpleExpression.java   Source Code and License Vote up 6 votes
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
    Path expression = null;
    if (fieldName.contains(".")) {
        
        System.out.println(root);
        String[] names = StringUtils.split(fieldName, ".");
        expression = root.get(names[0]);
        for (int i = 1; i < names.length; i++) {
            expression = expression.get(names[i]);
        }
    } else {
        expression = root.get(fieldName);
    }

    switch (operator) {
    case EQ:
        return builder.equal(expression, value);
    case NE:
        return builder.notEqual(expression, value);
    case LIKE:
        return builder.like((Expression<String>) expression, "%" + value + "%");
    case RLIKE:
        return builder.like((Expression<String>) expression, value + "%");
    case LLIKE:
        return builder.like((Expression<String>) expression, value + "%");
    case LT:
        return builder.lessThan(expression, (Comparable) value);
    case GT:
        return builder.greaterThan(expression, (Comparable) value);
    case LTE:
        return builder.lessThanOrEqualTo(expression, (Comparable) value);
    case GTE:
        return builder.greaterThanOrEqualTo(expression, (Comparable) value);
    case ISNULL:
        return builder.isNull(expression);
    case NOTNULL:
        return builder.isNotNull(expression);
    default:
        return null;
    }
}
 
Example 2
Project: osc-core   File: TaskEntityMgr.java   Source Code and License Vote up 5 votes
/**
 * Gets all the unique Task failures encountered since the from date.
 *
 * @param fromDate the start time to look for failed task
 * @param session the hibernate session
 *
 * @return unique task failures since the from date
 */
public static List<TaskFailureRecordDto> getUniqueTaskFailureStrings(Date fromDate, EntityManager em) {

    List<TaskFailureRecordDto> taskFailures = null;

    CriteriaBuilder cb = em.getCriteriaBuilder();

    CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
    Root<TaskRecord> root = query.from(TaskRecord.class);

    Predicate restriction = null;

    if(fromDate != null) {
        restriction = cb.and(
                cb.greaterThan(root.get("completedTimestamp"), fromDate),
                cb.isNotNull(root.get("failReason")));
    } else {
        restriction = cb.isNotNull(root.get("failReason"));
    }

    query = query.multiselect(root.get("failReason"), cb.count(root))
            .where(restriction);

    List<?> results = em
            .createQuery(query)
            .getResultList();

    if (!results.isEmpty()) {
        taskFailures = new ArrayList<TaskFailureRecordDto>();
        for (Object row : results) {
            Object[] rowArray = (Object[]) row;
            taskFailures.add(new TaskFailureRecordDto((String) rowArray[0], (long) rowArray[1]));
        }
    }

    return taskFailures;

}