javax.persistence.criteria.AbstractQuery Java Examples

The following examples show how to use javax.persistence.criteria.AbstractQuery. 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: LinqImpl.java    From linq with Apache License 2.0 6 votes vote down vote up
protected void applyPredicateToCriteria(AbstractQuery<?> query) {

		Predicate predicate = parsePredicate(junction);
		if (predicate != null) {
			query.where(predicate);
		}
		
		predicate = parsePredicate(having);
		if (predicate != null) {
			query.having(predicate);
		}
		
		if (query instanceof CriteriaQuery) {
			if (!CollectionUtils.isEmpty(orders)) {
				((CriteriaQuery<?>) query).orderBy(orders);
			}
		}
	}
 
Example #2
Source File: LinqImpl.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
protected void applyPredicateToCriteria(AbstractQuery<?> query) {

		Predicate predicate = parsePredicate(junction);
		if (predicate != null) {
			query.where(predicate);
		}
		
		predicate = parsePredicate(having);
		if (predicate != null) {
			query.having(predicate);
		}
		
		if (query instanceof CriteriaQuery) {
			if (!CollectionUtils.isEmpty(orders)) {
				((CriteriaQuery<?>) query).orderBy(orders);
			}
		}
	}
 
Example #3
Source File: CriteriaSubqueryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AbstractQuery<?> getParent() {
	if ( ! AbstractQuery.class.isInstance( parent ) ) {
		throw new IllegalStateException( "Cannot call getParent on update/delete criterias" );
	}
	return (AbstractQuery<?>) parent;
}
 
Example #4
Source File: LinqImpl.java    From bdf3 with Apache License 2.0 5 votes vote down vote up
protected void beforeExecute(AbstractQuery<?> query) {
	if (!disableSmartSubQueryCriterion && c != null) {
		this.addParser(new SmartSubQueryParser(this, domainClass, collectInfos));
	}
	doParseCriteria();
	applyPredicateToCriteria(query);
}
 
Example #5
Source File: PredicateUtils.java    From genie with Apache License 2.0 5 votes vote down vote up
static <E extends BaseEntity> Predicate createCriterionPredicate(
    final Root<E> root,
    final AbstractQuery<?> cq,
    final CriteriaBuilder cb,
    final SingularAttribute<UniqueIdEntity, String> uniqueIdAttribute,
    final SingularAttribute<BaseEntity, String> nameAttribute,
    final SingularAttribute<BaseEntity, String> versionAttribute,
    final SingularAttribute<BaseEntity, String> statusAttribute,
    final Supplier<Join<E, TagEntity>> tagJoinSupplier,
    final SingularAttribute<IdEntity, Long> idAttribute,
    final Criterion criterion
) {
    final List<Predicate> predicates = Lists.newArrayList();

    criterion.getId().ifPresent(id -> predicates.add(cb.equal(root.get(uniqueIdAttribute), id)));
    criterion.getName().ifPresent(name -> predicates.add(cb.equal(root.get(nameAttribute), name)));
    criterion.getVersion().ifPresent(version -> predicates.add(cb.equal(root.get(versionAttribute), version)));
    criterion.getStatus().ifPresent(status -> predicates.add(cb.equal(root.get(statusAttribute), status)));

    final Set<String> tags = criterion.getTags();
    if (!tags.isEmpty()) {
        final Join<E, TagEntity> tagJoin = tagJoinSupplier.get();
        predicates.add(tagJoin.get(TagEntity_.tag).in(tags));

        cq.groupBy(root.get(idAttribute));
        cq.having(
            cb.equal(
                cb.count(root.get(idAttribute)),
                tags.size()
            )
        );
    }

    return cb.and(predicates.toArray(new Predicate[0]));
}
 
Example #6
Source File: QueryStructure.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public QueryStructure(AbstractQuery<T> owner, CriteriaBuilderImpl criteriaBuilder) {
	this.owner = owner;
	this.criteriaBuilder = criteriaBuilder;
	this.isSubQuery = Subquery.class.isInstance( owner );
}