Example usage for javax.persistence.criteria CriteriaBuilder createQuery

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

Introduction

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

Prototype

<T> CriteriaQuery<T> createQuery(Class<T> resultClass);

Source Link

Document

Create a CriteriaQuery object with the specified result type.

Usage

From source file:net.przemkovv.sphinx.dao.impl.DefaultUserDAO.java

@Override
public User getUser(String email) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> user = cq.from(User.class);
    cq.where(cb.equal(user.get(User_.email), email));
    return em.createQuery(cq).getSingleResult();
}

From source file:net.przemkovv.sphinx.dao.impl.DefaultUserDAO.java

@Override
public boolean existsByEmail(String email) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> cq = cb.createQuery(Long.class);
    Root<User> user = cq.from(User.class);
    cq.where(cb.equal(user.get(User_.email), email));
    cq.select(cb.count(user));/*from   w  w w.j a va 2 s  . c o  m*/
    return em.createQuery(cq).getSingleResult().intValue() == 1;
}

From source file:com.ttech.cordovabuild.domain.user.UserRepositoryImpl.java

@Override
public User findUserByEmail(String email) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> root = cq.from(User.class);
    return em.createQuery(cq.select(root).where(cb.equal(root.get(User_.email), email))).getSingleResult();
}

From source file:com.ttech.cordovabuild.domain.user.UserRepositoryImpl.java

@Override
public User findUserByUserName(String username) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<User> cq = cb.createQuery(User.class);
    Root<User> root = cq.from(User.class);
    return em.createQuery(cq.select(root).where(cb.equal(root.get(User_.username), username)))
            .getSingleResult();/*from   w  w  w.ja v  a 2 s  .c  o  m*/
}

From source file:fi.helsinki.opintoni.repository.CommonRepository.java

public <T> List<T> find(Class<T> entityClass, List<Long> ids) {
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<T> query = criteriaBuilder.createQuery(entityClass);
    Root<T> from = query.from(entityClass);
    query.select(from).where(from.get("id").in(ids));
    return entityManager.createQuery(query).getResultList();
}

From source file:net.przemkovv.sphinx.dao.impl.DefaultPermissionDAO.java

@Override
public List<Permission> getPermissionsForUser(User user) {

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Permission> cq = cb.createQuery(Permission.class);
    Root<Permission> permissions = cq.from(Permission.class);
    Join<Permission, Role> roles = permissions.join(Permission_.roles);
    Join<Role, User> users = roles.join(Role_.users);
    cq.where(cb.equal(users.get(User_.email), user.getEmail()));
    return em.createQuery(cq).getResultList();

}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.DBInitApplicationListener.java

protected boolean isDBEmpty() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Long> cq = cb.createQuery(Long.class);
    cq.select(cb.count(cq.from(ClaimEntity.class)));

    return em.createQuery(cq).getSingleResult() == 0;
}

From source file:example.springdata.jpa.showcase.snippets.AccountRepositoryImpl.java

@Override
public void removedExpiredAccounts(LocalDate reference) {

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Account> query = cb.createQuery(Account.class);
    Root<Account> account = query.from(Account.class);

    query.where(/* w ww .  ja  v a2  s.c  om*/
            cb.lessThan(account.get("expiryDate").as(Date.class), reference.toDateTimeAtStartOfDay().toDate()));

    for (Account each : em.createQuery(query).getResultList()) {
        em.remove(each);
    }
}

From source file:com.github.springtestdbunit.entity.EntityAssert.java

public void afterPropertiesSet() throws Exception {
    CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
    this.criteriaQuery = cb.createQuery(SampleEntity.class);
    Root<SampleEntity> from = this.criteriaQuery.from(SampleEntity.class);
    this.criteriaQuery.orderBy(cb.asc(from.get("value").as(String.class)));
}

From source file:core.commonapp.server.dao.geo.GeoDaoHibernateImpl.java

@Override
public List<Geo> findByGeoType(GeoType type) {
    CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
    CriteriaQuery query = builder.createQuery(Geo.class);

    Root<Geo> root = query.from(Geo.class);
    builder.equal(root.get("geoType"), type);
    return getEntityManager().createQuery(query).getResultList();
}