List of usage examples for javax.persistence.criteria CriteriaBuilder createQuery
<T> CriteriaQuery<T> createQuery(Class<T> resultClass);
CriteriaQuery
object with the specified result type. From source file:core.commonapp.server.dao.security.UserLoginDaoHibernateImpl.java
@Override public List<UserLogin> findAllLikeUsername(String username) { CriteriaBuilder builder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<UserLogin> query = builder.createQuery(UserLogin.class); Root<UserLogin> root = query.from(UserLogin.class); query.where(builder.like(root.<String>get("username"), "%" + username + "%")); return getEntityManager().createQuery(query).getResultList(); }
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.ttech.cordovabuild.domain.application.ApplicationRepositoryImpl.java
@Override public ApplicationBuilt getLatestBuilt(Application application) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ApplicationBuilt> cq = cb.createQuery(ApplicationBuilt.class); Root<ApplicationBuilt> from = cq.from(ApplicationBuilt.class); cq = cq.where(cb.equal(from.get(ApplicationBuilt_.application), application)) .orderBy(cb.desc(from.get(ApplicationBuilt_.startDate))); try {/*from w w w . ja va 2s .c o m*/ return em.createQuery(cq).setMaxResults(1).getSingleResult(); } catch (NoResultException e) { throw new ApplicationBuiltNotFoundException(e); } }
From source file:com.datapine.dao.impl.ItemDAOImpl.java
@Override @PostFilter("hasRole('ROLE_ADMIN') or hasPermission(filterObject, 'read')") public final List<Item> findAllOrderById() { final CriteriaBuilder builder = this.manager.getCriteriaBuilder(); final CriteriaQuery<Item> query = builder.createQuery(Item.class); final Root<Item> root = query.from(Item.class); query.select(root).orderBy(builder.asc(root.get("id"))); return this.manager.createQuery(query).getResultList(); }
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:net.dontdrinkandroot.persistence.dao.NumericEntityDaoTest.java
@Test @Transactional/*www.j a v a 2s . c o m*/ public void testQuot() { NumericEntity entity2 = new NumericEntity(); entity2.setLongField(2L); entity2.setIntField(3); entity2 = this.save(entity2); final CriteriaBuilder builder = this.getCriteriaBuilder(); final CriteriaQuery<Number> criteriaQuery = builder.createQuery(Number.class); final Root<NumericEntity> root = criteriaQuery.from(NumericEntity.class); final Expression<Number> quot = builder.quot( builder.prod(builder.literal(1f), root.get(NumericEntity_.intField)), root.get(NumericEntity_.longField)); criteriaQuery.select(quot); final Number result = this.findSingle(criteriaQuery); Assert.assertEquals(Float.class, result.getClass()); Assert.assertEquals(3 / 2f, result); }
From source file:org.businessmanager.dao.security.UserDaoImpl.java
@Override public User findUserByName(String username) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<User> query = queryBuilder.createQuery(User.class); Root<User> userQuery = query.from(User.class); query.select(userQuery).where(queryBuilder.equal(userQuery.get(User_.username), username)); try {/*from w w w .j av a 2 s. c o m*/ return getEntityManager().createQuery(query).getSingleResult(); } catch (NoResultException e) { return null; } }
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"))); }//from w ww .j a v a 2s. c om return (List<UserLoginSecurityGroup>) getEntityManager().createQuery(query).getResultList(); }
From source file:br.com.sementesdoamanha.repository.Servidores.java
public List<Servidor> filtrados(ServidorFilter filtro) { //select, from, where, like... --> select(), from(), where() //JPQL: from Servidor //JPQL: select s from Servidor s where c.nome like = 'Joo%' and c.cpf = like '046.244.901-77' CriteriaBuilder builder = manager.getCriteriaBuilder(); CriteriaQuery<Servidor> criteriaQuery = builder.createQuery(Servidor.class); Root<Servidor> s = criteriaQuery.from(Servidor.class); criteriaQuery.select(s);//from w w w . ja va2s . co m List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(filtro.getCpf())) { predicates.add(builder.equal(s.<String>get("cpf"), filtro.getCpf())); } if (StringUtils.isNotBlank(filtro.getNome())) { predicates .add(builder.like(builder.upper(s.<String>get("nome")), filtro.getNome().toUpperCase() + "%")); } criteriaQuery.where(predicates.toArray(new Predicate[0])); TypedQuery<Servidor> query = manager.createQuery(criteriaQuery); return query.getResultList(); }
From source file:eu.uqasar.service.company.CompanyService.java
public List<Company> getAllCompanys() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Company> query = cb.createQuery(Company.class); query.from(Company.class); return em.createQuery(query).getResultList(); }