Java Code Examples for javax.persistence.criteria.CriteriaBuilder#greaterThanOrEqualTo()

The following examples show how to use javax.persistence.criteria.CriteriaBuilder#greaterThanOrEqualTo() . 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: CmsPlan.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private Predicate documentPredicate_date(CriteriaBuilder cb, Root<Document> root) throws Exception {
	if (null == this.dateRange || (!this.dateRange.available())) {
		return null;
	}
	Expression var1 = root.get(Document_.publishTime);
	if(this.draft){
		var1 = root.get(Document_.updateTime);
	}
	if (null == this.dateRange.start) {
		return cb.lessThanOrEqualTo(var1, this.dateRange.completed);
	} else if (null == this.dateRange.completed) {
		return cb.greaterThanOrEqualTo(var1, this.dateRange.start);
	} else {
		return cb.between(var1, this.dateRange.start, this.dateRange.completed);
	}
}
 
Example 2
Source File: ActionListForwardMonth.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<Meeting> list(EffectivePerson effectivePerson, Business business, Date start, Date end)
		throws Exception {
	EntityManager em = business.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Meeting> cq = cb.createQuery(Meeting.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), start);
	/** 这里两个都是startTime是对的 */
	p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.startTime), end));
	p = cb.and(p, cb.notEqual(root.get(Meeting_.manualCompleted), true));
	if (effectivePerson.isNotManager() && (!business.organization().person().hasRole(effectivePerson,
			OrganizationDefinition.MeetingManager))) {
		p = cb.and(p,
				cb.or(cb.equal(root.get(Meeting_.applicant), effectivePerson.getDistinguishedName()),
						cb.equal(root.get(Meeting_.auditor), effectivePerson.getDistinguishedName()),
						cb.isMember(effectivePerson.getDistinguishedName(), root.get(Meeting_.invitePersonList))));
	}
	cq.select(root).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example 3
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWithPersonWaitAccept(String person) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.completedTime), new Date());
	p = cb.and(p, cb.notEqual(root.get(Meeting_.manualCompleted), true));
	p = cb.and(p, cb.isMember(person, root.get(Meeting_.invitePersonList)));
	p = cb.and(p, cb.isNotMember(person, root.get(Meeting_.acceptPersonList)));
	p = cb.and(p, cb.isNotMember(person, root.get(Meeting_.rejectPersonList)));
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example 4
Source File: ProcessPlatformPlan.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private Predicate workPredicate_date(CriteriaBuilder cb, Root<Work> root) throws Exception {
	if (null == this.dateRange || (!this.dateRange.available())) {
		return null;
	}
	if (null == this.dateRange.start) {
		return cb.lessThanOrEqualTo(root.get(Work_.startTime), this.dateRange.completed);
	} else if (null == this.dateRange.completed) {
		return cb.greaterThanOrEqualTo(root.get(Work_.startTime), this.dateRange.start);
	} else {
		return cb.between(root.get(Work_.startTime), this.dateRange.start, this.dateRange.completed);
	}
}
 
Example 5
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWithDate(Date start, Date end) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), start);
	p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.startTime), end));
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example 6
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Long countSubjectForTodayByUserName( String userName ) throws Exception {
	DateOperation dateOperation = new DateOperation();
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.greaterThanOrEqualTo( root.get( BBSSubjectInfo_.createTime ), dateOperation.getTodayStartTime() );
	if( StringUtils.isNotEmpty( userName ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.creatorName ), userName ) );
	}
	cq.select( cb.count( root ) );		
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 7
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Long countForTodayByForumId( String forumId ) throws Exception {
	DateOperation dateOperation = new DateOperation();
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.greaterThanOrEqualTo( root.get( BBSSubjectInfo_.createTime ), dateOperation.getTodayStartTime() );
	if( StringUtils.isNotEmpty( forumId ) ){
		p = cb.or( p, cb.equal( root.get( BBSSubjectInfo_.forumId ), forumId ) );
	}
	cq.select( cb.count( root ) );		
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 8
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Long countSubjectForTodayBySectionId( String sectionId ) throws Exception {
	DateOperation dateOperation = new DateOperation();
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.greaterThanOrEqualTo( root.get( BBSSubjectInfo_.createTime ), dateOperation.getTodayStartTime() );
	if( StringUtils.isNotEmpty( sectionId ) ){
		Predicate or = cb.equal( root.get( BBSSubjectInfo_.mainSectionId ), sectionId );
		or = cb.or( or, cb.equal( root.get( BBSSubjectInfo_.sectionId ), sectionId ) );
		p = cb.and( p, or );
	}
	cq.select( cb.count( root ) );		
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 9
Source File: RangeSpecification.java    From docs-manage with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Predicate buildRangePredicate(Range<T> range, Root<T> root, CriteriaBuilder cb) {
    if (range.isBetween()) {
        return cb.between(root.get(range.getField()), range.getFrom(), range.getTo());
    } else if (range.isFromSet()) {
        return cb.greaterThanOrEqualTo(root.get(range.getField()), range.getFrom());
    } else if (range.isToSet()) {
        return cb.lessThanOrEqualTo(root.get(range.getField()), range.getTo());
    }
    return null;
}
 
Example 10
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWaitConfirm() throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.completedTime), new Date());
	p = cb.and(p, cb.equal(root.get(Meeting_.confirmStatus), ConfirmStatus.wait));
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example 11
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWithDate(Date start, Date end) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), start);
	p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.startTime), end));
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example 12
Source File: MeetingFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listWithPersonWithDate(String person, Date start, Date end) throws Exception {
	EntityManager em = this.entityManagerContainer().get(Meeting.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Meeting> root = cq.from(Meeting.class);
	Predicate p = cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), start);
	p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.startTime), end));
	p = cb.and(p,
			cb.or(cb.equal(root.get(Meeting_.applicant), person), cb.equal(root.get(Meeting_.auditor), person),
					cb.isMember(person, root.get(Meeting_.invitePersonList))));
	p = cb.and(p, cb.equal(root.get(Meeting_.manualCompleted), false));
	cq.select(root.get(Meeting_.id)).where(p);
	return em.createQuery(cq).getResultList();
}
 
Example 13
Source File: ByRangeUtil.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
private static <D extends Comparable<? super D>, E> Predicate buildRangePredicate(Range<E, D> range, Root<E> root, CriteriaBuilder builder) {
    Predicate rangePredicate = null;
    Path<D> path = JpaUtil.getInstance().getPath(root, range.getAttributes());
    if (range.isBetween()) {
        rangePredicate = builder.between(path, range.getFrom(), range.getTo());
    } else if (range.isFromSet()) {
        rangePredicate = builder.greaterThanOrEqualTo(path, range.getFrom());
    } else if (range.isToSet()) {
        rangePredicate = builder.lessThanOrEqualTo(path, range.getTo());
    }

    if (rangePredicate != null) {
        if (!range.isIncludeNullSet() || range.getIncludeNull() == FALSE) {
            return rangePredicate;
        } else {
            return builder.or(rangePredicate, builder.isNull(path));
        }
    } else {
        // no from/to is set, but include null or not could be:
        if (TRUE == range.getIncludeNull()) {
            return builder.isNull(path);
        } else if (FALSE == range.getIncludeNull()) {
            return builder.isNotNull(path);
        }
    }
    return null;
}
 
Example 14
Source File: BBSReplyInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public List<BBSReplyInfo> listReplyForTodayByUserName( String creatorName, String forumId, String mainSectionId, String sectionId, String subjectId, Integer maxCount ) throws Exception {
	Boolean allFilterNull = true;
	if( StringUtils.isNotEmpty( creatorName ) ){
		allFilterNull = false;
	}
	if( StringUtils.isNotEmpty( forumId ) ){
		allFilterNull = false;
	}
	if( StringUtils.isNotEmpty( mainSectionId ) ){
		allFilterNull = false;
	}
	if( StringUtils.isNotEmpty( sectionId ) ){
		allFilterNull = false;
	}
	if( StringUtils.isNotEmpty( subjectId ) ){
		allFilterNull = false;
	}
	if( allFilterNull ){
		throw new Exception( "list filter can not all null." );
	}
	if( maxCount == null ){
		maxCount = 20;
	}
	DateOperation dateOperation = new DateOperation();
	EntityManager em = this.entityManagerContainer().get( BBSReplyInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSReplyInfo> cq = cb.createQuery( BBSReplyInfo.class );
	Root<BBSReplyInfo> root = cq.from( BBSReplyInfo.class );
	Predicate p = cb.greaterThanOrEqualTo( root.get( BBSReplyInfo_.createTime ), dateOperation.getTodayStartTime() );
	if( StringUtils.isNotEmpty( creatorName ) ){
		p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.creatorName ), creatorName ) );
	}
	if( StringUtils.isNotEmpty( forumId ) ){
		p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.forumId ), forumId ) );
	}
	if( StringUtils.isNotEmpty( mainSectionId ) ){
		p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.mainSectionId ), mainSectionId ) );
	}
	if( StringUtils.isNotEmpty( sectionId ) ){
		p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.sectionId ), sectionId ) );
	}
	if( StringUtils.isNotEmpty( subjectId ) ){
		p = cb.and( p, cb.equal( root.get( BBSReplyInfo_.subjectId ), subjectId ) );
	}
	cq.orderBy( cb.asc( root.get( BBSReplyInfo_.orderNumber ) ) );
	return em.createQuery(cq.where(p)).setMaxResults( maxCount ).getResultList();
}
 
Example 15
Source File: AuditRecordRepositoryImpl.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public Page<AuditRecord> findByActionTypeAndOperationTypeAndDate(AuditOperationType[] operations,
		AuditActionType[] actions, Instant fromDate, Instant toDate, Pageable pageable) {

	final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	final CriteriaQuery<AuditRecord> query = cb.createQuery(AuditRecord.class);
	final Root<AuditRecord> auditRecordRoot = query.from(AuditRecord.class);

	final Path<AuditActionType> auditAction = auditRecordRoot.get("auditAction");
	final Path<AuditOperationType> auditOperation = auditRecordRoot.get("auditOperation");
	final Path<Instant> createdOn = auditRecordRoot.get("createdOn");

	final Predicate datePredicate;
	if (fromDate != null && toDate == null) {
		datePredicate = cb.greaterThanOrEqualTo(createdOn, fromDate);
	}
	else if (fromDate == null && toDate != null) {
		datePredicate = cb.lessThanOrEqualTo(createdOn, toDate);
	}
	else if (fromDate != null && toDate != null) {
		datePredicate = cb.between(createdOn, fromDate, toDate);
	}
	else {
		datePredicate = null;
	}

	final List<Predicate> auditActionPredicates = new ArrayList<>();
	if (actions != null && actions.length > 0) {
		for (AuditActionType action : actions) {
			auditActionPredicates.add(cb.equal(auditAction, action));
		}
	}

	final List<Predicate> auditOperationsPredicates = new ArrayList<>();
	if (operations != null && operations.length > 0) {
		for (AuditOperationType operation : operations) {
			auditOperationsPredicates.add(cb.equal(auditOperation, operation));
		}
	}

	final List<Predicate> finalQueryPredicates = new ArrayList<>();
	if (!auditActionPredicates.isEmpty()) {
		final Predicate auditActionPredicatesOr = cb.or(auditActionPredicates.toArray(new Predicate[0]));
		finalQueryPredicates.add(auditActionPredicatesOr);
	}
	if (datePredicate != null) {
		finalQueryPredicates.add(datePredicate);
	}
	if (!auditOperationsPredicates.isEmpty()) {
		final Predicate auditOperationsPredicatesOr = cb.or(auditOperationsPredicates.toArray(new Predicate[0]));
		finalQueryPredicates.add(auditOperationsPredicatesOr);
	}

	final CriteriaQuery<AuditRecord> select = query.select(auditRecordRoot);

	if (!finalQueryPredicates.isEmpty()) {
		select.where(finalQueryPredicates.toArray(new Predicate[0]));
	}

	if (pageable.getSort().isUnsorted()) {
		select.orderBy(QueryUtils.toOrders(pageable.getSort().and(Sort.by("id")).ascending(), auditRecordRoot, cb));
	}
	else {
		select.orderBy(QueryUtils.toOrders(pageable.getSort(), auditRecordRoot, cb));
	}

	final TypedQuery<AuditRecord> typedQuery = entityManager.createQuery(select);
	typedQuery.setFirstResult((int) pageable.getOffset());
	typedQuery.setMaxResults(pageable.getPageSize());

	final List<AuditRecord> resultList = typedQuery.getResultList();

	final CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
	countQuery.select(cb.count(countQuery.from(AuditRecord.class)));

	if (!finalQueryPredicates.isEmpty()) {
		countQuery.where(finalQueryPredicates.toArray(new Predicate[0]));
	}

	final Long totalCount = entityManager.createQuery(countQuery)
			  .getSingleResult();

	return new PageImpl<>(resultList, pageable, totalCount);
}
 
Example 16
Source File: SimpleExpression.java    From sctalk with Apache License 2.0 4 votes vote down vote up
@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: GeSpecification.java    From jpa-spec with MIT License 4 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    From from = getRoot(property, root);
    String field = getProperty(property);
    return cb.greaterThanOrEqualTo(from.get(field), compare);
}
 
Example 18
Source File: GenericRsqlSpecification.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Predicate toPredicate(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) {
    final List<Object> args = castArguments(root);
    final Object argument = args.get(0);
    switch (RsqlSearchOperation.getSimpleOperator(operator)) {

    case EQUAL: {
        if (argument instanceof String) {
            return builder.like(root.get(property), argument.toString().replace('*', '%'));
        } else if (argument == null) {
            return builder.isNull(root.get(property));
        } else {
            return builder.equal(root.get(property), argument);
        }
    }
    case NOT_EQUAL: {
        if (argument instanceof String) {
            return builder.notLike(root.<String> get(property), argument.toString().replace('*', '%'));
        } else if (argument == null) {
            return builder.isNotNull(root.get(property));
        } else {
            return builder.notEqual(root.get(property), argument);
        }
    }
    case GREATER_THAN: {
        return builder.greaterThan(root.<String> get(property), argument.toString());
    }
    case GREATER_THAN_OR_EQUAL: {
        return builder.greaterThanOrEqualTo(root.<String> get(property), argument.toString());
    }
    case LESS_THAN: {
        return builder.lessThan(root.<String> get(property), argument.toString());
    }
    case LESS_THAN_OR_EQUAL: {
        return builder.lessThanOrEqualTo(root.<String> get(property), argument.toString());
    }
    case IN:
        return root.get(property).in(args);
    case NOT_IN:
        return builder.not(root.get(property).in(args));
    }

    return null;
}
 
Example 19
Source File: GreaterThanOrEqual.java    From specification-arg-resolver with Apache License 2.0 4 votes vote down vote up
@Override
protected <Y extends Comparable<? super Y>> Predicate makePredicate(CriteriaBuilder cb, Expression<? extends Y> x, Y y) {
	return cb.greaterThanOrEqualTo(x, y);
}
 
Example 20
Source File: DateAfterInclusive.java    From specification-arg-resolver with Apache License 2.0 4 votes vote down vote up
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    return cb.greaterThanOrEqualTo(this.<Date>path(root), date);
}