本文整理汇总了Java中javax.persistence.criteria.CriteriaBuilder.isNotNull方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaBuilder.isNotNull方法的具体用法?Java CriteriaBuilder.isNotNull怎么用?Java CriteriaBuilder.isNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.CriteriaBuilder
的用法示例。
在下文中一共展示了CriteriaBuilder.isNotNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUniqueTaskFailureStrings
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
/**
* 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;
}
示例2: toPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@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;
}
}