Example usage for javax.persistence.criteria ListJoin get

List of usage examples for javax.persistence.criteria ListJoin get

Introduction

In this page you can find the example usage for javax.persistence.criteria ListJoin get.

Prototype

<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);

Source Link

Document

Create a path corresponding to the referenced single-valued attribute.

Usage

From source file:com.hengyi.japp.execution.Util.java

public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Task> root,
        TaskQueryCommand command) {/*from   w  w  w. ja va2 s.  c o  m*/
    Predicate p1 = cb.equal(root.get(Task_.charger), command.getOperator());
    ListJoin<Task, Operator> joinFollowers = root.join(Task_.followers, JoinType.LEFT);
    Predicate p2 = cb.equal(joinFollowers.get(Operator_.id), command.getOperator().getId());
    ListJoin<Task, Operator> joinExecutors = root.join(Task_.executors, JoinType.LEFT);
    Predicate p3 = cb.equal(joinExecutors.get(Operator_.id), command.getOperator().getId());
    Predicate p = cb.or(p1, p2, p3);
    if (command.getExecutor() != null) {
        p = cb.and(p, cb.equal(p, cb.isMember(command.getExecutor(), root.get(Task_.executors))));
    }
    if (command.getCustomer() != null) {
        p = cb.and(p, cb.equal(root.get(Task_.customer), command.getCustomer()));
    }
    if (!isBlank(command.getContent())) {
        p = cb.and(p, cb.like(root.get(Task_.content), command.getContentQuery()));
    }
    Collection<TaskType> TaskTypes = command.getTypes();
    if (TaskTypes != null && !TaskTypes.isEmpty()) {
        p = cb.and(p, root.get(Task_.type).in(TaskTypes));
    }
    Collection<TaskStatus> statuses = command.getStatuses();
    if (statuses != null && !statuses.isEmpty()) {
        p = cb.and(p, root.get(Task_.status).in(statuses));
    }
    if (command.getCreateDate() != null) {
        Date createDateStart = LocalDate.fromDateFields(command.getCreateDate()).toDate();
        Date createDateEnd = LocalDate.fromDateFields(command.getCreateDate()).plusDays(1).toDate();
        p = cb.and(p, cb.between(root.get(Task_.logInfo).get(LogInfo_.createDateTime), createDateStart,
                createDateEnd));
        // TODO timestamp date convert
        //p = cb.and(p, cb.equal(root.get(Task_.logInfo).get(LogInfo_.createDateTime).as(java.sql.Date.class), command.getCreateDate()));
    }
    cq.where(p);
}

From source file:com.orange.clara.tool.controllers.AbstractDefaultController.java

protected List<WatchedResource> getFilteredWatchedResources(User user, boolean isAdmin, String isPublic,
        String tags, String types, Date afterDate) {
    Specification<WatchedResource> specification = new Specification<WatchedResource>() {
        @Override/*www  .ja  v  a  2 s .c  om*/
        public Predicate toPredicate(Root<WatchedResource> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            List<Predicate> predicates = new ArrayList<>();
            if (tags != null) {
                ListJoin<WatchedResource, Tag> tagJoin = root.joinList("tags");
                predicates.add(cb.isTrue(tagJoin.get("name").in(Tag.namesFromStringList(tags))));
            }
            if (types != null) {
                predicates.add(cb.isTrue(root.get("type").in(ResourceType.fromStringList(types))));
            }
            if (isPublic != null) {
                predicates.add(cb.isTrue(root.get("isPublic")));
            }
            if (afterDate != null) {
                predicates.add(cb.greaterThan(root.get("updatedResourceAt"), afterDate));
            }
            if (!isAdmin) {
                ListJoin<WatchedResource, User> usersJoin = root.joinList("users");
                predicates.add(cb.equal(usersJoin.get("uuid"), user.getUuid()));
            }
            Predicate finalPredicate = cb.and(predicates.toArray(new Predicate[] {}));
            if (isPublic != null) {
                finalPredicate = cb.or(finalPredicate, cb.isTrue(root.get("isPublic")));
            }
            return finalPredicate;
        }
    };
    return this.watchedResourceRepo.findAll(specification);
}

From source file:net.dontdrinkandroot.persistence.dao.ExampleGeneratedIdEntityDaoImpl.java

@Override
@Transactional(readOnly = true)/*from ww w  .  ja  v  a  2  s  . c  om*/
public List<ExampleGeneratedIdEntity> findByOtherText(final String text) {
    final CriteriaBuilder builder = this.getCriteriaBuilder();
    final CriteriaQuery<ExampleGeneratedIdEntity> criteriaQuery = builder.createQuery(this.entityClass);
    criteriaQuery.distinct(true);
    final Root<ExampleGeneratedIdEntity> root = criteriaQuery.from(this.entityClass);

    final ListJoin<ExampleGeneratedIdEntity, ExampleIdEntity> join = root
            .join(ExampleGeneratedIdEntity_.otherEntities);

    criteriaQuery.where(builder.equal(join.get(ExampleIdEntity_.text), text));

    return this.find(criteriaQuery);
}