Example usage for javax.persistence.criteria JoinType LEFT

List of usage examples for javax.persistence.criteria JoinType LEFT

Introduction

In this page you can find the example usage for javax.persistence.criteria JoinType LEFT.

Prototype

JoinType LEFT

To view the source code for javax.persistence.criteria JoinType LEFT.

Click Source Link

Document

Left outer join.

Usage

From source file:org.verinice.persistence.CnaTreeElementDaoImpl.java

private TypedQuery<CnaTreeElement> createQueryForScopeKeyValue(Integer scopeId, String key, String value) {
    CriteriaQuery<CnaTreeElement> query = getCriteriaBuilder().createQuery(CnaTreeElement.class);
    Root<CnaTreeElement> rootelement = query.from(CnaTreeElement.class);
    query.select(rootelement);//www .j av  a2s .com

    Join<CnaTreeElement, Entity> entityJoin = rootelement.join("entity", JoinType.LEFT);
    Join<PropertyList, Entity> propertyListJoin = entityJoin.join("propertyLists", JoinType.LEFT);
    Join<PropertyList, Property> propertyJoin = propertyListJoin.join("properties", JoinType.LEFT);

    List<Predicate> conditions = new ArrayList<>();
    if (key != null) {
        conditions.add(getCriteriaBuilder().like(propertyJoin.get("propertytype"), key));
    }
    if (value != null) {
        conditions.add(getCriteriaBuilder().like(propertyJoin.get("propertyvalue"), value));
    }
    if (scopeId != null) {
        conditions.add(getCriteriaBuilder().equal(rootelement.get("scopeId"), scopeId));
    }
    query.where(conditions.toArray(new Predicate[conditions.size()]));

    query.distinct(true);
    return entityManager.createQuery(query);
}

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 va 2  s .  c o  m*/
        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 {/*from w  w w  .  jav a 2  s .  co m*/
        return null;
    }
}

From source file:com.expressui.sample.view.role.RoleQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<Role> rootEntity) {
    List<Predicate> criteria = new ArrayList<Predicate>();

    if (!isEmpty(name)) {
        ParameterExpression<String> p = builder.parameter(String.class, "name");
        criteria.add(builder.like(builder.upper(rootEntity.<String>get("name")), p));
    }//from w  w w  .  jav  a 2  s  .  c o m

    if (!isEmpty(doesNotBelongToUser)) {
        ParameterExpression<User> p = builder.parameter(User.class, "doesNotBelongToUser");
        Join join = rootEntity.join("userRoles", JoinType.LEFT);
        criteria.add(builder.or(builder.notEqual(join.get("user"), p), builder.isNull(join.get("user"))));
    }

    return criteria;
}

From source file:com.expressui.sample.view.user.UserQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, Root<User> rootEntity) {
    List<Predicate> criteria = new ArrayList<Predicate>();

    if (!isEmpty(loginName)) {
        ParameterExpression<String> p = builder.parameter(String.class, "loginName");
        criteria.add(builder.like(builder.upper(rootEntity.<String>get("loginName")), p));
    }/*  w w  w  .  ja  v a 2s  .  c  o  m*/

    if (!isEmpty(doesNotBelongToRole)) {
        ParameterExpression<Role> p = builder.parameter(Role.class, "doesNotBelongToRole");
        Join join = rootEntity.join("userRoles", JoinType.LEFT);
        criteria.add(builder.or(builder.notEqual(join.get("role"), p), builder.isNull(join.get("role"))));
    }

    return criteria;
}

From source file:com.expressui.core.dao.security.query.RelatedPermissionsQuery.java

@Override
public void addFetchJoins(Root<Permission> permission) {
    permission.fetch("role", JoinType.LEFT);
}

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

@Override
public void addFetchJoins(Root<Profile> profile) {
    profile.fetch("user", JoinType.LEFT);
}

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

@Override
public void addFetchJoins(Root<Contact> rootEntity) {
    rootEntity.fetch("mailingAddress", JoinType.LEFT).fetch("state", JoinType.LEFT);
}

From source file:com.movies.dao.impl.BaseDaoImpl.java

@Override
public <T> List<T> getObjectsByCriteria(Map<String, Object> map, Class returnClass,
        List<SingularAttribute> singleAttributes, List<ListAttribute> listAttributes,
        List<SetAttribute> setAttributes) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<T> cq = cb.createQuery(returnClass).distinct(true);
    Root<T> root = cq.from(returnClass);

    if (CollectionUtils.isNotEmpty(singleAttributes)) {
        for (SingularAttribute attribute : singleAttributes) {
            root.join(attribute);//from   www  .  ja  v  a 2 s  .co  m
            root.fetch(attribute);
        }
    }

    if (CollectionUtils.isNotEmpty(listAttributes)) {
        for (ListAttribute attribute : listAttributes) {
            root.join(attribute, JoinType.LEFT);
            root.fetch(attribute, JoinType.LEFT);
        }
    }

    if (CollectionUtils.isNotEmpty(setAttributes)) {
        for (SetAttribute attribute : setAttributes) {
            root.join(attribute, JoinType.LEFT);
            root.fetch(attribute, JoinType.LEFT);
        }
    }
    Set<Entry<String, Object>> set = map.entrySet();
    int numberOfClauses = set.size();
    Predicate[] predicates = new Predicate[numberOfClauses];
    int i = 0;
    for (Entry<String, Object> entry : set) {
        String key = entry.getKey();
        if (MovieConstants.NAME_FIELD.equals(key) || MovieConstants.SURNAME_FIELD.equals(key)) {
            predicates[i++] = cb.like(cb.upper(root.<String>get(key)), LIKE + entry.getValue() + LIKE);
        } else if (MovieConstants.MOVIE_DIRECTOR_FIELD.equals(key)) {
            //predicates[i++] = cb.equal( ,entry.getValue());
        } else {
            predicates[i++] = cb.equal(root.get(key), entry.getValue());
        }
    }

    return em.createQuery(cq.select(root).where(predicates)).getResultList();

}

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 {/*w w w . j  av a 2 s  .  co m*/
        return null;
    }
}