Example usage for javax.persistence.criteria CriteriaBuilder isNull

List of usage examples for javax.persistence.criteria CriteriaBuilder isNull

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder isNull.

Prototype

Predicate isNull(Expression<?> x);

Source Link

Document

Create a predicate to test whether the expression is null.

Usage

From source file:core.commonapp.server.dao.security.UserLoginSecurityGroupDaoHibernateImpl.java

@Override
public List<UserLoginSecurityGroup> findBySecurityGroup(SecurityGroup securityGroup, boolean includeOld) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserLoginSecurityGroup> query = builder.createQuery(getPersistClass());
    Root<UserLoginSecurityGroup> root = query.from(getPersistClass());
    query.where(builder.equal(root.get("securityGroup"), securityGroup));

    if (!includeOld) {
        query.where(builder.isNull(root.get("thruDate")));
    }// w  w w.  ja  v  a  2s .c  o  m

    return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).getResultList();
}

From source file:net.groupbuy.dao.impl.ConsultationDaoImpl.java

public Page<Consultation> findPage(Member member, Product product, Boolean isShow, Pageable pageable) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class);
    Root<Consultation> root = criteriaQuery.from(Consultation.class);
    criteriaQuery.select(root);//from w  w  w. j a  va 2s  .  co  m
    Predicate restrictions = criteriaBuilder.conjunction();
    restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation")));
    if (member != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member));
    }
    if (product != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product));
    }
    if (isShow != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow));
    }
    criteriaQuery.where(restrictions);
    return super.findPage(criteriaQuery, pageable);
}

From source file:net.groupbuy.dao.impl.ConsultationDaoImpl.java

public Long count(Member member, Product product, Boolean isShow) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class);
    Root<Consultation> root = criteriaQuery.from(Consultation.class);
    criteriaQuery.select(root);/*from ww  w  .j a  va  2 s .co m*/
    Predicate restrictions = criteriaBuilder.conjunction();
    restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation")));
    if (member != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member));
    }
    if (product != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product));
    }
    if (isShow != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow));
    }
    criteriaQuery.where(restrictions);
    return super.count(criteriaQuery, null);
}

From source file:net.groupbuy.dao.impl.ConsultationDaoImpl.java

public List<Consultation> findList(Member member, Product product, Boolean isShow, Integer count,
        List<Filter> filters, List<Order> orders) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Consultation> criteriaQuery = criteriaBuilder.createQuery(Consultation.class);
    Root<Consultation> root = criteriaQuery.from(Consultation.class);
    criteriaQuery.select(root);//www. j ava  2s  . c o  m
    Predicate restrictions = criteriaBuilder.conjunction();
    restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forConsultation")));
    if (member != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("member"), member));
    }
    if (product != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("product"), product));
    }
    if (isShow != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isShow"), isShow));
    }
    criteriaQuery.where(restrictions);
    return super.findList(criteriaQuery, null, count, filters, orders);
}

From source file:core.commonapp.server.dao.security.UserLoginSecurityGroupDaoHibernateImpl.java

@Override
public List<UserLoginSecurityGroup> findByUserLoginAndSecurityGroup(UserLogin userLogin,
        SecurityGroup securityGroup, boolean includeOld) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserLoginSecurityGroup> query = builder.createQuery(getPersistClass());
    Root<UserLoginSecurityGroup> root = query.from(getPersistClass());
    query.where(builder.equal(root.get("securityGroup"), securityGroup),
            builder.equal(root.get("userLogin"), userLogin),
            (includeOld ? builder.isNotNull(root.get("thruDate")) : builder.isNull(root.get("thruDate"))));

    return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).getResultList();
}

From source file:core.commonapp.server.dao.security.SecurityGroupDaoHibernateImpl.java

@Override
@Transactional//from w  w w. j  ava2s  .co m
public Set<SecurityGroup> findAllByUserLogin(UserLogin userLogin) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<SecurityGroup> query = builder.createQuery(SecurityGroup.class);

    Root<SecurityGroup> root = query.from(SecurityGroup.class);
    Join<SecurityGroup, UserLoginSecurityGroup> join = root.join("userLoginSecurityGroup");

    builder.equal(join.get("userLogin.userLoginId"), userLogin.getUserLoginId());
    builder.isNull(join.get("thruDate"));

    //        criteria.setFetchMode("userLoginSecurityGroups", FetchMode.SELECT);
    //        criteria.setFetchMode("permissionSecurityGroups", FetchMode.SELECT);

    Set<SecurityGroup> securityGroups = new HashSet<SecurityGroup>(
            getEntityManager().createQuery(query).getResultList());

    for (SecurityGroup securityGroup : securityGroups) {
        securityGroup.getPermissionSecurityGroups().size();
        securityGroup.getUserLoginSecurityGroups().size();
    }

    return securityGroups;
}

From source file:net.groupbuy.dao.impl.MessageDaoImpl.java

public Page<Message> findDraftPage(Member sender, Pageable pageable) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Message> criteriaQuery = criteriaBuilder.createQuery(Message.class);
    Root<Message> root = criteriaQuery.from(Message.class);
    criteriaQuery.select(root);/* w w  w  . j  a v a  2s . com*/
    Predicate restrictions = criteriaBuilder.conjunction();
    restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forMessage")),
            criteriaBuilder.equal(root.get("isDraft"), true));
    if (sender != null) {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("sender"), sender));
    } else {
        restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("sender")));
    }
    criteriaQuery.where(restrictions);
    return super.findPage(criteriaQuery, pageable);
}

From source file:net.groupbuy.dao.impl.MessageDaoImpl.java

public Page<Message> findPage(Member member, Pageable pageable) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Message> criteriaQuery = criteriaBuilder.createQuery(Message.class);
    Root<Message> root = criteriaQuery.from(Message.class);
    criteriaQuery.select(root);/* w w  w.j a va  2  s. c  om*/
    Predicate restrictions = criteriaBuilder.conjunction();
    restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forMessage")),
            criteriaBuilder.equal(root.get("isDraft"), false));
    if (member != null) {
        restrictions = criteriaBuilder.and(restrictions,
                criteriaBuilder.or(
                        criteriaBuilder.and(criteriaBuilder.equal(root.get("sender"), member),
                                criteriaBuilder.equal(root.get("senderDelete"), false)),
                        criteriaBuilder.and(criteriaBuilder.equal(root.get("receiver"), member),
                                criteriaBuilder.equal(root.get("receiverDelete"), false))));
    } else {
        restrictions = criteriaBuilder.and(restrictions,
                criteriaBuilder.or(
                        criteriaBuilder.and(criteriaBuilder.isNull(root.get("sender")),
                                criteriaBuilder.equal(root.get("senderDelete"), false)),
                        criteriaBuilder.and(criteriaBuilder.isNull(root.get("receiver")),
                                criteriaBuilder.equal(root.get("receiverDelete"), false))));
    }
    criteriaQuery.where(restrictions);
    return super.findPage(criteriaQuery, pageable);

}

From source file:net.groupbuy.dao.impl.MessageDaoImpl.java

public Long count(Member member, Boolean read) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Message> criteriaQuery = criteriaBuilder.createQuery(Message.class);
    Root<Message> root = criteriaQuery.from(Message.class);
    criteriaQuery.select(root);//from   w w w  .jav a 2s  . co  m
    Predicate restrictions = criteriaBuilder.conjunction();
    restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.isNull(root.get("forMessage")),
            criteriaBuilder.equal(root.get("isDraft"), false));
    if (member != null) {
        if (read != null) {
            restrictions = criteriaBuilder.and(restrictions,
                    criteriaBuilder.or(
                            criteriaBuilder.and(criteriaBuilder.equal(root.get("sender"), member),
                                    criteriaBuilder.equal(root.get("senderDelete"), false),
                                    criteriaBuilder.equal(root.get("senderRead"), read)),
                            criteriaBuilder.and(criteriaBuilder.equal(root.get("receiver"), member),
                                    criteriaBuilder.equal(root.get("receiverDelete"), false),
                                    criteriaBuilder.equal(root.get("receiverRead"), read))));
        } else {
            restrictions = criteriaBuilder.and(restrictions,
                    criteriaBuilder.or(
                            criteriaBuilder.and(criteriaBuilder.equal(root.get("sender"), member),
                                    criteriaBuilder.equal(root.get("senderDelete"), false)),
                            criteriaBuilder.and(criteriaBuilder.equal(root.get("receiver"), member),
                                    criteriaBuilder.equal(root.get("receiverDelete"), false))));
        }
    } else {
        if (read != null) {
            restrictions = criteriaBuilder.and(restrictions,
                    criteriaBuilder.or(
                            criteriaBuilder.and(criteriaBuilder.isNull(root.get("sender")),
                                    criteriaBuilder.equal(root.get("senderDelete"), false),
                                    criteriaBuilder.equal(root.get("senderRead"), read)),
                            criteriaBuilder.and(criteriaBuilder.isNull(root.get("receiver")),
                                    criteriaBuilder.equal(root.get("receiverDelete"), false),
                                    criteriaBuilder.equal(root.get("receiverRead"), read))));
        } else {
            restrictions = criteriaBuilder.and(restrictions,
                    criteriaBuilder.or(
                            criteriaBuilder.and(criteriaBuilder.isNull(root.get("sender")),
                                    criteriaBuilder.equal(root.get("senderDelete"), false)),
                            criteriaBuilder.and(criteriaBuilder.isNull(root.get("receiver")),
                                    criteriaBuilder.equal(root.get("receiverDelete"), false))));
        }
    }
    criteriaQuery.where(restrictions);
    return super.count(criteriaQuery, null);
}

From source file:com.dbs.sdwt.jpa.ByPropertySelectorUtil.java

private <E> void byObjectAndModeSelector(Root<E> root, CriteriaBuilder builder, List<Predicate> predicates,
        SearchParameters sp, PropertySelector<? super E, ?> selector) {
    List<Predicate> selectorPredicates = newArrayList();
    List<?> selected = selector.getSelected();
    if (selected.contains(null)) {
        selected = newArrayList(selector.getSelected());
        selected.remove(null);//from w w  w . ja v  a 2s.co  m
        selectorPredicates.add(builder.isNull(jpaUtil.getPath(root, selector.getAttributes())));
    }
    for (Object selection : selected) {
        Path<?> path = jpaUtil.getPath(root, selector.getAttributes());
        if (selection instanceof Identifiable) {
            selectorPredicates.add(builder.equal(path.get("id"), ((Identifiable<?>) selection).getId()));
        } else {
            selectorPredicates.add(builder.equal(path, selection));
        }
    }
    predicates.add(jpaUtil.andPredicate(builder, selectorPredicates));
}