Example usage for javax.persistence.criteria Root join

List of usage examples for javax.persistence.criteria Root join

Introduction

In this page you can find the example usage for javax.persistence.criteria Root join.

Prototype

<Y> Join<X, Y> join(SingularAttribute<? super X, Y> attribute, JoinType jt);

Source Link

Document

Create a join to the specified single-valued attribute using the given join type.

Usage

From source file:org.wallride.repository.CategorySpecifications.java

public static Specification<Category> hasArticle(String language) {
    return (root, query, cb) -> {
        query.distinct(true);//from   w w w  .  j av  a 2s .  c  om

        Subquery<Long> subquery = query.subquery(Long.class);
        Root<Article> a = subquery.from(Article.class);
        Join<Article, Category> c = a.join(Article_.categories, JoinType.INNER);
        subquery.select(c.get(Category_.id)).where(cb.equal(a.get(Article_.status), Article.Status.PUBLISHED));

        List<Predicate> predicates = new ArrayList<>();
        predicates.add(root.get(Category_.id).in(subquery));
        predicates.add(cb.equal(root.get(Category_.language), language));
        return cb.and(predicates.toArray(new Predicate[0]));
    };
}

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 .j  a  v  a 2s. c om
    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.expressui.sample.dao.query.RecentContactsQuery.java

@Override
public Path buildOrderBy(Root<Contact> contact) {
    if (getOrderByPropertyId().equals("mailingAddress.country")) {
        return contact.join("mailingAddress", JoinType.LEFT).join("country", JoinType.LEFT);
    } else if (getOrderByPropertyId().equals("mailingAddress.street")) {
        return contact.join("mailingAddress", JoinType.LEFT).get("street");
    } else if (getOrderByPropertyId().equals("mailingAddress.city")) {
        return contact.join("mailingAddress", JoinType.LEFT).get("city");
    } else if (getOrderByPropertyId().equals("mailingAddress.state.code")) {
        return contact.join("mailingAddress", JoinType.LEFT).join("state", JoinType.LEFT).get("code");
    } else {/*from w ww .  j ava2  s .  c om*/
        return null;
    }
}

From source file:com.expressui.sample.dao.query.ProfileQuery.java

@Override
public Path buildOrderBy(Root<Profile> profile) {
    if (getOrderByPropertyId().equals("user.loginName")) {
        return profile.join("user", JoinType.LEFT).get("loginName");
    } else {// www .ja  v  a 2 s .co  m
        return null;
    }
}

From source file:com.expressui.sample.dao.query.RelatedContactsQuery.java

@Override
public Path buildOrderBy(Root<Contact> contact) {
    if (getOrderByPropertyId().equals("mailingAddress.country")) {
        return contact.join("mailingAddress", JoinType.LEFT).join("country", JoinType.LEFT);
    } else if (getOrderByPropertyId().equals("mailingAddress.state.code")) {
        return contact.join("mailingAddress", JoinType.LEFT).join("state", JoinType.LEFT).get("code");
    } else {//from ww w  . ja  v a2  s .  c  o  m
        return null;
    }
}

From source file:com.expressui.sample.view.dashboard.RecentContactsQuery.java

@Override
public Path buildOrderBy(Root<Contact> rootEntity) {
    if (getOrderByPropertyId().equals("mailingAddress.country")) {
        return rootEntity.join("mailingAddress", JoinType.LEFT).join("country", JoinType.LEFT);
    } else if (getOrderByPropertyId().equals("mailingAddress.street")) {
        return rootEntity.join("mailingAddress", JoinType.LEFT).get("street");
    } else if (getOrderByPropertyId().equals("mailingAddress.city")) {
        return rootEntity.join("mailingAddress", JoinType.LEFT).get("city");
    } else if (getOrderByPropertyId().equals("mailingAddress.state.code")) {
        return rootEntity.join("mailingAddress", JoinType.LEFT).join("state", JoinType.LEFT).get("code");
    } else {//from  w  ww  . ja va2 s  . com
        return null;
    }
}

From source file:com.expressui.sample.dao.query.OpportunityQuery.java

@Override
public Path buildOrderBy(Root<Opportunity> opportunity) {
    if (getOrderByPropertyId().equals("account.name")) {
        return opportunity.join("account", JoinType.LEFT).get("name");
    } else {/*  w ww.ja va  2 s .c  o  m*/
        return null;
    }
}

From source file:com.expressui.sample.view.opportunity.OpportunityQuery.java

@Override
public Path buildOrderBy(Root<Opportunity> rootEntity) {
    if (getOrderByPropertyId().equals("account.name")) {
        return rootEntity.join("account", JoinType.LEFT).get("name");
    } else {//from  w  w w. j av  a  2  s . co m
        return null;
    }
}

From source file:com.expressui.sample.dao.query.ContactQuery.java

@Override
public Path buildOrderBy(Root<Contact> contact) {
    if (getOrderByPropertyId().equals("mailingAddress.country")) {
        return contact.join("mailingAddress", JoinType.LEFT).join("country", JoinType.LEFT);
    } else if (getOrderByPropertyId().equals("mailingAddress.city")) {
        return contact.join("mailingAddress", JoinType.LEFT).get("city");
    } else if (getOrderByPropertyId().equals("mailingAddress.state.name")) {
        return contact.join("mailingAddress", JoinType.LEFT).join("state", JoinType.LEFT).get("name");
    } else if (getOrderByPropertyId().equals("account.name")) {
        return contact.join("account", JoinType.LEFT).get("name");
    } else {/*from ww w  . j  a  va  2  s.c  o m*/
        return null;
    }
}

From source file:com.expressui.sample.dao.query.AccountQuery.java

@Override
public Path buildOrderBy(Root<Account> account) {
    if (getOrderByPropertyId().equals("billingAddress.country")) {
        return account.join("billingAddress", JoinType.LEFT).join("country", JoinType.LEFT);
    } else if (getOrderByPropertyId().equals("billingAddress.state.code")) {
        return account.join("billingAddress", JoinType.LEFT).join("state", JoinType.LEFT).get("code");
    } else {/* w  w  w  .  j a v a 2  s.com*/
        return null;
    }
}