Java Code Examples for javax.persistence.criteria.CriteriaBuilder#notEqual()
The following examples show how to use
javax.persistence.criteria.CriteriaBuilder#notEqual() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserSpecification.java From tutorials with MIT License | 24 votes |
@Override public Predicate toPredicate(final Root<User> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { switch (criteria.getOperation()) { case EQUALITY: return builder.equal(root.get(criteria.getKey()), criteria.getValue()); case NEGATION: return builder.notEqual(root.get(criteria.getKey()), criteria.getValue()); case GREATER_THAN: return builder.greaterThan(root.get(criteria.getKey()), criteria.getValue().toString()); case LESS_THAN: return builder.lessThan(root.get(criteria.getKey()), criteria.getValue().toString()); case LIKE: return builder.like(root.get(criteria.getKey()), criteria.getValue().toString()); case STARTS_WITH: return builder.like(root.get(criteria.getKey()), criteria.getValue() + "%"); case ENDS_WITH: return builder.like(root.get(criteria.getKey()), "%" + criteria.getValue()); case CONTAINS: return builder.like(root.get(criteria.getKey()), "%" + criteria.getValue() + "%"); default: return null; } }
Example 2
Source File: ResourceDao.java From osiam with MIT License | 6 votes |
public <T extends ResourceEntity, V> boolean isUniqueAttributeAlreadyTaken(String attributeValue, String id, SingularAttribute<? super T, V> attribute, Class<T> clazz) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<T> resource = cq.from(clazz); cq.select(cb.countDistinct(resource)); Predicate predicate = cb.equal(resource.get(attribute), attributeValue); if (id != null) { Predicate ignoreId = cb.notEqual(resource.get(ResourceEntity_.id), id); predicate = cb.and(predicate, ignoreId); } cq.where(predicate); TypedQuery<Long> countQuery = em.createQuery(cq); return countQuery.getSingleResult() > 0; }
Example 3
Source File: JpaUtil.java From gazpachoquest with GNU General Public License v3.0 | 6 votes |
public static <E> Predicate stringPredicate(Expression<String> path, Object attrValue, SearchMode searchMode, SearchParameters sp, CriteriaBuilder builder) { if (!sp.isCaseSensitive()) { path = builder.lower(path); // attrValue = ((String) attrValue).toLowerCase(LocaleContextHolder.getLocale()); attrValue = ((String) attrValue).toLowerCase(); } switch (searchMode != null ? searchMode : sp.getSearchMode()) { case EQUALS: return builder.equal(path, attrValue); case NOT_EQUALS: return builder.notEqual(path, attrValue); case ENDING_LIKE: return builder.like(path, "%" + attrValue); case STARTING_LIKE: return builder.like(path, attrValue + "%"); case ANYWHERE: return builder.like(path, "%" + attrValue + "%"); case LIKE: return builder.like(path, (String) attrValue); // assume user // provide the wild // cards default: throw new IllegalStateException("expecting a search mode!"); } }
Example 4
Source File: SimpleSpecification.java From SpringBoot-Base-System with GNU Lesser General Public License v3.0 | 5 votes |
private Predicate generatePredicate(Root<T> root, CriteriaBuilder criteriaBuilder, SpecificationOperator op) { /* * 根据不同的操作符返回特定的查询 */ if (SpecificationOperator.Operator.eq.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.equal(root.get(op.getKey()), op.getValue()); } else if (SpecificationOperator.Operator.ge.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.ge(root.get(op.getKey()).as(Number.class), (Number) op.getValue()); } else if (SpecificationOperator.Operator.le.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.le(root.get(op.getKey()).as(Number.class), (Number) op.getValue()); } else if (SpecificationOperator.Operator.gt.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.gt(root.get(op.getKey()).as(Number.class), (Number) op.getValue()); } else if (SpecificationOperator.Operator.lt.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.lt(root.get(op.getKey()).as(Number.class), (Number) op.getValue()); } else if (SpecificationOperator.Operator.likeAll.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.like(root.get(op.getKey()).as(String.class), "%" + op.getValue() + "%"); } else if (SpecificationOperator.Operator.likeL.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.like(root.get(op.getKey()).as(String.class), op.getValue() + "%"); } else if (SpecificationOperator.Operator.likeR.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.like(root.get(op.getKey()).as(String.class), "%" + op.getValue()); } else if (SpecificationOperator.Operator.isNull.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.isNull(root.get(op.getKey())); } else if (SpecificationOperator.Operator.isNotNull.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.isNotNull(root.get(op.getKey())); } else if (SpecificationOperator.Operator.notEqual.name().equalsIgnoreCase(op.getOper())) { return criteriaBuilder.notEqual(root.get(op.getKey()), op.getValue()); } return null; }
Example 5
Source File: SyncOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<Person> listPerson(Business business) throws Exception { EntityManagerContainer emc = business.entityManagerContainer(); EntityManager em = emc.get(Person.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Person> cq = cb.createQuery(Person.class); Root<Person> root = cq.from(Person.class); Predicate p = cb.notEqual(root.get(Person_.qiyeweixinId), ""); p = cb.and(p, cb.isNotNull(root.get(Person_.qiyeweixinId))); List<Person> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList(); return os; }
Example 6
Source File: SyncOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<Unit> listUnit(Business business) throws Exception { EntityManagerContainer emc = business.entityManagerContainer(); EntityManager em = emc.get(Unit.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Unit> cq = cb.createQuery(Unit.class); Root<Unit> root = cq.from(Unit.class); Predicate p = cb.notEqual(root.get(Unit_.qiyeweixinId), ""); p = cb.and(p, cb.isNotNull(root.get(Unit_.qiyeweixinId))); List<Unit> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList(); return os; }
Example 7
Source File: SyncOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<Person> listZhengwuDingdingPerson(Business business) throws Exception { EntityManagerContainer emc = business.entityManagerContainer(); EntityManager em = emc.get(Person.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Person> cq = cb.createQuery(Person.class); Root<Person> root = cq.from(Person.class); Predicate p = cb.notEqual(root.get(Person_.zhengwuDingdingId), ""); p = cb.and(p, cb.isNotNull(root.get(Person_.zhengwuDingdingId))); List<Person> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList(); return os; }
Example 8
Source File: SyncOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<Unit> listZhengwuDingdingUnit(Business business) throws Exception { EntityManagerContainer emc = business.entityManagerContainer(); EntityManager em = emc.get(Unit.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Unit> cq = cb.createQuery(Unit.class); Root<Unit> root = cq.from(Unit.class); Predicate p = cb.notEqual(root.get(Unit_.zhengwuDingdingId), ""); p = cb.and(p, cb.isNotNull(root.get(Unit_.zhengwuDingdingId))); List<Unit> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList(); return os; }
Example 9
Source File: SyncOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<Person> listPerson(Business business) throws Exception { EntityManagerContainer emc = business.entityManagerContainer(); EntityManager em = emc.get(Person.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Person> cq = cb.createQuery(Person.class); Root<Person> root = cq.from(Person.class); Predicate p = cb.notEqual(root.get(Person_.dingdingId), ""); p = cb.and(p, cb.isNotNull(root.get(Person_.dingdingId))); List<Person> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList(); return os; }
Example 10
Source File: ActionCover.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private <W extends JpaObject, T extends JpaObject> List<T> orphanProcessElement(Business business, W w, Class<T> cls, String processId) throws Exception { EntityManager em = business.entityManagerContainer().get(cls); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<T> cq = cb.createQuery(cls); Root<T> root = cq.from(cls); Predicate p = cb.notEqual(root.get(JpaObject.id_FIELDNAME), w.getId()); p = cb.and(p, cb.equal(root.get("process"), processId)); cq.select(root).where(p); return em.createQuery(cq).getResultList(); }
Example 11
Source File: OkrErrorSystemIdentityInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<OkrErrorIdentityRecords> listRecordNotFlag(String flag) throws Exception { if( flag == null || flag.isEmpty() ){ return new ArrayList<OkrErrorIdentityRecords>(); } EntityManager em = this.entityManagerContainer().get( OkrErrorIdentityRecords.class ); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<OkrErrorIdentityRecords> cq = cb.createQuery(OkrErrorIdentityRecords.class); Root<OkrErrorIdentityRecords> root = cq.from(OkrErrorIdentityRecords.class); Predicate p = cb.notEqual( root.get(OkrErrorIdentityRecords_.flag), flag ); return em.createQuery(cq.where(p)).getResultList(); }
Example 12
Source File: OkrErrorSystemIdentityInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<OkrErrorSystemIdentityInfo> listNotFlag(String flag) throws Exception { if( flag == null || flag.isEmpty() ){ return new ArrayList<OkrErrorSystemIdentityInfo>(); } EntityManager em = this.entityManagerContainer().get( OkrErrorSystemIdentityInfo.class ); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<OkrErrorSystemIdentityInfo> cq = cb.createQuery(OkrErrorSystemIdentityInfo.class); Root<OkrErrorSystemIdentityInfo> root = cq.from(OkrErrorSystemIdentityInfo.class); Predicate p = cb.notEqual( root.get(OkrErrorSystemIdentityInfo_.flag), flag ); return em.createQuery(cq.where(p)).getResultList(); }
Example 13
Source File: OkrErrorSystemIdentityInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<OkrErrorIdentityRecords> listRecordNotFlag(String flag) throws Exception { if( flag == null || flag.isEmpty() ){ return new ArrayList<OkrErrorIdentityRecords>(); } EntityManager em = this.entityManagerContainer().get( OkrErrorIdentityRecords.class ); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<OkrErrorIdentityRecords> cq = cb.createQuery(OkrErrorIdentityRecords.class); Root<OkrErrorIdentityRecords> root = cq.from(OkrErrorIdentityRecords.class); Predicate p = cb.notEqual( root.get(OkrErrorIdentityRecords_.flag), flag ); return em.createQuery(cq.where(p)).getResultList(); }
Example 14
Source File: OkrErrorSystemIdentityInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<OkrErrorSystemIdentityInfo> listNotFlag(String flag) throws Exception { if( flag == null || flag.isEmpty() ){ return new ArrayList<OkrErrorSystemIdentityInfo>(); } EntityManager em = this.entityManagerContainer().get( OkrErrorSystemIdentityInfo.class ); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<OkrErrorSystemIdentityInfo> cq = cb.createQuery(OkrErrorSystemIdentityInfo.class); Root<OkrErrorSystemIdentityInfo> root = cq.from(OkrErrorSystemIdentityInfo.class); Predicate p = cb.notEqual( root.get(OkrErrorSystemIdentityInfo_.flag), flag ); return em.createQuery(cq.where(p)).getResultList(); }
Example 15
Source File: NeRestriction.java From base-framework with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") public Predicate build(Path expression, Object value,CriteriaBuilder builder) { return value == null ? builder.isNotNull(expression) : builder.notEqual(expression, value); }
Example 16
Source File: SimpleExpression.java From sctalk with Apache License 2.0 | 4 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 17
Source File: SimpleExpression.java From sctalk with Apache License 2.0 | 4 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); case IN: return builder.in(expression); default: return null; } }
Example 18
Source File: NotEqualSpecification.java From jpa-spec with MIT License | 4 votes |
private Predicate getPredicate(From root, CriteriaBuilder cb, Object value, String field) { return value == null ? cb.isNotNull(root.get(field)) : cb.notEqual(root.get(field), value); }
Example 19
Source File: NotEqualIgnoreCase.java From specification-arg-resolver with Apache License 2.0 | 4 votes |
@Override public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return path(root).getJavaType().equals(String.class) ? cb.notEqual(cb.upper(this.<String>path(root)), expectedValue.toUpperCase()) : super.toPredicate(root, query, cb); }
Example 20
Source File: Condition.java From activejpa with Apache License 2.0 | 4 votes |
@Override Predicate createPredicate(CriteriaBuilder builder, Path path, Expression... parameter) { return builder.notEqual(path, parameter[0]); }