Example usage for javax.persistence.criteria CriteriaQuery from

List of usage examples for javax.persistence.criteria CriteriaQuery from

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaQuery from.

Prototype

<X> Root<X> from(Class<X> entityClass);

Source Link

Document

Create and add a query root corresponding to the given entity, forming a cartesian product with any existing roots.

Usage

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

@Override
public UserLogin findByUsernameAndPassword(String username, String password) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<UserLogin> query = builder.createQuery(UserLogin.class);

    Root<UserLogin> root = query.from(UserLogin.class);

    query.where(builder.equal(root.get("username"), username), builder.equal(root.get("password"), password));

    return getEntityManager().createQuery(query).getSingleResult();
}

From source file:com.toptal.dao.UserDaoImpl.java

@Override
public final User findByName(final String name) {
    final CriteriaBuilder builder = this.manager.getCriteriaBuilder();
    final CriteriaQuery<User> query = builder.createQuery(User.class);
    final Root<User> root = query.from(User.class);
    query.where(builder.equal(root.get(NAME_FIELD), name));
    return this.getSingleResult(query);
}

From source file:de.logicline.splash.dao.ContactDaoImpl.java

public List<ContactEntity> findByName(String name) {

    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<ContactEntity> cq = cb.createQuery(ContactEntity.class);
    Root<ContactEntity> userInfo = cq.from(ContactEntity.class);
    cq.select(userInfo);/*  w  ww . j av  a2s.  c o  m*/
    cq.where(cb.like(userInfo.<String>get("lastName"), "%" + name + "%"));
    List<ContactEntity> result = getEntityManager().createQuery(cq).getResultList();
    return result;
}

From source file:net.osgiliath.jpa.repository.impl.HelloJpaRepository.java

@Override
public Collection<? extends HelloEntity> findByHelloObjectMessage(String message_p) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<HelloEntity> cq = cb.createQuery(HelloEntity.class);
    Root<HelloEntity> helloObject = cq.from(HelloEntity.class);
    cq.select(helloObject);/*from ww w  . j  a  v a 2  s. co m*/
    Predicate where = cb.equal(helloObject.get("helloMessage"), message_p);
    cq.where(where);
    TypedQuery<HelloEntity> q = entityManager.createQuery(cq);
    List<HelloEntity> result = q.getResultList();
    return result;
}

From source file:core.commonapp.server.dao.contact.PartyContactMechDaoHibernateImpl.java

@Override
public Set<PartyContactMech> findByContactMechId(Integer contactMechId) {
    log.debug("PartyContactMechDaoHibernateImpl.findByContactMechId({0})", contactMechId);

    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<PartyContactMech> query = builder.createQuery(PartyContactMech.class);
    Root<PartyContactMech> root = query.from(PartyContactMech.class);
    builder.equal(root.get("contactMechId"), contactMechId);
    builder.isNull(root.get("thruDate"));

    return (Set<PartyContactMech>) new HashSet(getEntityManager().createQuery(query).getResultList());
}

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

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

    if (!includeOld) {
        query.where(builder.isNull(root.get("thruDate")));
    }//from   www  .  java  2s .  c  o  m

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

From source file:de.logicline.splash.dao.ContactDaoImpl.java

public ContactEntity getContactByUserId(String userId) {

    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<ContactEntity> cq = cb.createQuery(ContactEntity.class);
    Root<ContactEntity> userInfo = cq.from(ContactEntity.class);
    cq.select(userInfo);//from  www.j a  va  2 s.  c o  m
    cq.where(cb.equal(userInfo.get("userIdFk"), userId));
    List<ContactEntity> resultList = em.createQuery(cq).getResultList();

    ContactEntity result = null;
    if (resultList != null && resultList.size() > 0) {
        result = resultList.get(0);
    }

    return result;
}

From source file:dtu.ds.warnme.dao.impl.AbstractGenericDao.java

@Override
@Transactional(readOnly = true)//  w w  w . j a  v  a 2s.co  m
public List<T> getAll() {
    CriteriaBuilder builder = manager.getCriteriaBuilder();
    CriteriaQuery<T> criteria = builder.createQuery(entityClazz);
    Root<T> root = criteria.from(entityClazz);
    criteria.select(root);
    return manager.createQuery(criteria).getResultList();
}

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

public List<Promotion> findList(Boolean hasBegun, Boolean hasEnded, Integer count, List<Filter> filters,
        List<Order> orders) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Promotion> criteriaQuery = criteriaBuilder.createQuery(Promotion.class);
    Root<Promotion> root = criteriaQuery.from(Promotion.class);
    criteriaQuery.select(root);//from w w w.j  a v a2s  . c  om
    Predicate restrictions = criteriaBuilder.conjunction();
    if (hasBegun != null) {
        if (hasBegun) {
            restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("beginDate").isNull(),
                    criteriaBuilder.lessThanOrEqualTo(root.<Date>get("beginDate"), new Date())));
        } else {
            restrictions = criteriaBuilder.and(restrictions, root.get("beginDate").isNotNull(),
                    criteriaBuilder.greaterThan(root.<Date>get("beginDate"), new Date()));
        }
    }
    if (hasEnded != null) {
        if (hasEnded) {
            restrictions = criteriaBuilder.and(restrictions, root.get("endDate").isNotNull(),
                    criteriaBuilder.lessThan(root.<Date>get("endDate"), new Date()));
        } else {
            restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(root.get("endDate").isNull(),
                    criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("endDate"), new Date())));
        }
    }
    criteriaQuery.where(restrictions);
    return super.findList(criteriaQuery, null, count, filters, orders);
}

From source file:vn.edu.vnuk.tasks_jpa.dao.TaskDao.java

public List<Task> read() throws SQLException {

    EntityManager manager = getEntityManager();

    CriteriaQuery criteria = manager.getCriteriaBuilder().createQuery();
    criteria.select(criteria.from(Task.class));

    return manager.createQuery(criteria).getResultList();

}