List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:org.mitre.oauth2.repository.impl.JpaAuthorizationCodeRepository.java
@Override public Collection<AuthorizationCodeEntity> getExpiredCodes() { TypedQuery<AuthorizationCodeEntity> query = manager .createNamedQuery(AuthorizationCodeEntity.QUERY_EXPIRATION_BY_DATE, AuthorizationCodeEntity.class); query.setParameter(AuthorizationCodeEntity.PARAM_DATE, new Date()); // this gets anything that's already expired return query.getResultList(); }
From source file:com.aestheticsw.jobkeywords.service.termextractor.repository.TermFrequencyResultsRepositoryImpl.java
@Override public List<QueryKey> findDistinctQueryKeys() { // TODO convert queries into cacheable named queries with query-params TypedQuery<QueryKey> query = entityManager.createQuery( "select new com.aestheticsw.jobkeywords.service.termextractor.domain.QueryKey(key.query, key.locale, key.city) " + " from QueryKey key group by key.query, key.locale, key.city", QueryKey.class); List<QueryKey> results = query.getResultList(); return results; }
From source file:com.devicehive.dao.rdbms.DeviceClassDaoRdbmsImpl.java
@Override public List<DeviceClassWithEquipmentVO> list(String name, String namePattern, String sortField, Boolean sortOrderAsc, Integer take, Integer skip) { final CriteriaBuilder cb = criteriaBuilder(); final CriteriaQuery<DeviceClass> criteria = cb.createQuery(DeviceClass.class); final Root<DeviceClass> from = criteria.from(DeviceClass.class); final Predicate[] predicates = CriteriaHelper.deviceClassListPredicates(cb, from, ofNullable(name), ofNullable(namePattern));// ww w . j a va 2 s.c o m criteria.where(predicates); CriteriaHelper.order(cb, criteria, from, ofNullable(sortField), Boolean.TRUE.equals(sortOrderAsc)); final TypedQuery<DeviceClass> query = createQuery(criteria); ofNullable(take).ifPresent(query::setMaxResults); ofNullable(skip).ifPresent(query::setFirstResult); CacheHelper.cacheable(query); List<DeviceClass> resultList = query.getResultList(); Stream<DeviceClassWithEquipmentVO> objectStream = resultList.stream().map(DeviceClass::convertToVo); return objectStream.collect(Collectors.toList()); }
From source file:nl.waisda.services.EuropeanaImportServiceTest.java
@Test @Transactional//from w w w . j a va2s. co m @Rollback(value = true) public void testImportNoVideo() { HttpUriRequest overview = new HttpGet( "http://preview.europeana.eu/api/v2/search.json?wskey=XxxsEZoWj&query=dontcare&start=1&rows=12&profile=minimal"); HttpUriRequest details = new HttpGet("http://detail"); try { setup(); // setup http response setupHttpResponse("http://www.host.com/image.png", "", "http://www.host.com/webresource.mov"); // call the service service.importEuropeanaData("dontcare"); EntityManager em = entityManager;//Factory.getObject().createEntityManager(); TypedQuery q = em.createQuery("select v from Video v", Video.class); List<Video> result = q.getResultList(); Assert.assertEquals(0, result.size()); } catch (Exception e) { Assert.fail("Not supposed to fail"); LOG.error(e); } }
From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java
public List<OrganizationDTO> getOrganizationDTOList() { TypedQuery<OrganizationDTO> query = createEntityManager().createQuery("SELECT t FROM OrganizationDTO t", OrganizationDTO.class); return query.getResultList(); }
From source file:net.navasoft.madcoin.backend.model.controller.helper.impl.JPAHelper.java
/** * Find entities.//from w w w . jav a2 s . c o m * * @param em * the em * @param target * the target * @param all * the all * @param maxResults * the max results * @param firstResult * the first result * @return the list * @since 28/08/2014, 11:20:27 PM */ private List<Entity> findEntities(EntityManager em, Class<Entity> target, boolean all, int maxResults, int firstResult) { CriteriaQuery<Entity> cq = em.getCriteriaBuilder().createQuery(target); cq.select(cq.from(target)); TypedQuery<Entity> q = em.createQuery(cq); if (!all) { q.setMaxResults(maxResults); q.setFirstResult(firstResult); } return q.getResultList(); }
From source file:nl.waisda.services.EuropeanaImportServiceTest.java
@Test @Transactional//from w w w . j a v a 2 s . c om @Rollback(value = true) public void testImportAcceptMp4FromWebresource() { HttpUriRequest overview = new HttpGet( "http://preview.europeana.eu/api/v2/search.json?wskey=XxxsEZoWj&query=dontcare&start=1&rows=12&profile=minimal"); HttpUriRequest details = new HttpGet("http://detail"); try { setup(); // setup http response setupHttpResponse("http://www.host.com/image.png", "", "http://www.host.com/webresource.mp4"); // call the service service.importEuropeanaData("dontcare"); EntityManager em = entityManager;//Factory.getObject().createEntityManager(); TypedQuery q = em.createQuery("select v from Video v", Video.class); List<Video> result = q.getResultList(); Assert.assertEquals(1, result.size()); Assert.assertEquals("http://www.host.com/webresource.mp4", result.get(0).getSourceUrl()); Assert.assertEquals("http://www.host.com/image.png", result.get(0).getImageUrl()); } catch (Exception e) { Assert.fail("Not supposed to fail"); LOG.error(e); } }
From source file:org.businessmanager.dao.GenericDaoImpl.java
@Override public List<T> findByAttributes(Map<SingularAttribute<T, ?>, Object> theAttributes) { CriteriaBuilder queryBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = queryBuilder.createQuery(getPersistenceClass()); Root<T> rootQuery = criteriaQuery.from(getPersistenceClass()); CriteriaQuery<T> select = criteriaQuery.select(rootQuery); List<Predicate> aPredicateList = new ArrayList<Predicate>(); Iterator<SingularAttribute<T, ?>> anIterator = theAttributes.keySet().iterator(); while (anIterator.hasNext()) { SingularAttribute<T, ?> aKey = anIterator.next(); Object aValue = theAttributes.get(aKey); Predicate aPredicate = queryBuilder.equal(rootQuery.get(aKey), aValue); aPredicateList.add(aPredicate);/* w ww .j av a 2 s.co m*/ } select.where(aPredicateList.toArray(new Predicate[0])); TypedQuery<T> typedQuery = entityManager.createQuery(select); return typedQuery.getResultList(); }
From source file:org.businessmanager.dao.GenericDaoImpl.java
public List<T> findByAssignedEntity(ListAttribute<T, ?> listAttribute, Long entityId) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = queryBuilder.createQuery(getPersistenceClass()); Root<T> rootQuery = criteriaQuery.from(getPersistenceClass()); CriteriaQuery<T> select = criteriaQuery.select(rootQuery); Join<T, ?> memberJoin = rootQuery.join(listAttribute); Path<?> nameField = memberJoin.get("id"); Predicate nameEquals = queryBuilder.equal(nameField, entityId); criteriaQuery.where(nameEquals);/* w ww. jav a 2 s . c om*/ TypedQuery<T> typedQuery = getEntityManager().createQuery(select); return typedQuery.getResultList(); }
From source file:org.businessmanager.dao.GenericDaoImpl.java
public List<T> findByAssignedEntity(SetAttribute<T, ?> setAttribute, Long entityId) { CriteriaBuilder queryBuilder = getEntityManager().getCriteriaBuilder(); CriteriaQuery<T> criteriaQuery = queryBuilder.createQuery(getPersistenceClass()); Root<T> rootQuery = criteriaQuery.from(getPersistenceClass()); CriteriaQuery<T> select = criteriaQuery.select(rootQuery); Join<T, ?> memberJoin = rootQuery.join(setAttribute); Path<?> nameField = memberJoin.get("id"); Predicate nameEquals = queryBuilder.equal(nameField, entityId); criteriaQuery.where(nameEquals);//from w w w.j a va2 s.c o m TypedQuery<T> typedQuery = getEntityManager().createQuery(select); return typedQuery.getResultList(); }