List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:nl.waisda.services.EuropeanaImportServiceTest.java
@Test @Transactional/* w ww. j a v a 2 s . c o m*/ @Rollback(value = true) public void testImportAcceptMP4() { 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/shownby.mp4", "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/shownby.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:nl.waisda.services.EuropeanaImportServiceTest.java
@Test @Transactional//from w w w. ja v a 2 s. co m @Rollback(value = true) public void testImportAcceptAVI() { 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/shownby.avi", "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/shownby.avi", 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:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java
public List<DesignPatternDTO> getDesignPatternDTOList() { TypedQuery<DesignPatternDTO> query = createEntityManager().createQuery("SELECT t FROM DesignPatternDTO t", DesignPatternDTO.class); return query.getResultList(); }
From source file:bq.jpa.demo.lock.service.LockService.java
/** * modify employees salary/* w w w. ja v a 2s . c o m*/ */ @Transactional public void doUpdateSalary() { try { lock.lock(); // let read thread run first, run after employees has been locked in reading thread writeCondition.await(); TypedQuery<Employee> query = em.createQuery("SELECT e FROM jpa_lock_employee e", Employee.class); List<Employee> results = query.getResultList(); for (Employee employee : results) { employee.setSalary(employee.getSalary() + 33); } // let read thread continue } catch (InterruptedException e) { e.printStackTrace(); } finally { readCondition.signal(); System.out.println("[Thread writing] modify employee salary!"); lock.unlock(); } }
From source file:net.dontdrinkandroot.persistence.dao.GenericJpaDao.java
/** * Finds all entities by the given {@link CriteriaQuery} and limit the result set. * /*from w ww .j av a2s . co m*/ * @param firstResult * Position of the first result to retrive. * @param maxResults * The maximum number of results to retrieve. */ protected <V> List<V> find(final CriteriaQuery<V> criteriaQuery, final int firstResult, final int maxResults) { final TypedQuery<V> query = this.getEntityManager().createQuery(criteriaQuery); query.setMaxResults(maxResults); query.setFirstResult(firstResult); return query.getResultList(); }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public List<UserCerts> findAllUserCerts() { TypedQuery<UserCerts> query = em.createNamedQuery("UserCerts.findAll", UserCerts.class); try {/*w ww. j a va 2s . co m*/ List<UserCerts> res = query.getResultList(); return res; } catch (EntityNotFoundException e) { Logger.getLogger(CertsFacade.class.getName()).log(Level.SEVERE, null, e); } return new ArrayList<>(); }
From source file:hr.diskobolos.persistence.impl.EvaluationAnswerPersistenceImpl.java
@Override public ConcurrentMap<TermsOfConditionStatus, AtomicLong> fetchTermsOfCompetitionStatistic() { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<EvaluationAnswer> cq = cb.createQuery(EvaluationAnswer.class); Root<EvaluationAnswer> evaluationAnswer = cq.from(EvaluationAnswer.class); Join<EvaluationAnswer, QuestionChoicesDef> choiceDef = evaluationAnswer.join(EvaluationAnswer_.answer); Join<QuestionChoicesDef, EvaluationQuestionDef> questionDef = choiceDef .join(QuestionChoicesDef_.evaluationQuestionDef); ParameterExpression<QuestionnaireType> questionnaireType = cb.parameter(QuestionnaireType.class, "questionnaireType"); cq.select(evaluationAnswer);//w w w .ja va 2 s. c o m cq.where(cb.equal(questionDef.get(EvaluationQuestionDef_.questionnaireType), questionnaireType)); TypedQuery<EvaluationAnswer> query = entityManager.createQuery(cq); query.setParameter("questionnaireType", QuestionnaireType.TERMS_OF_CONDITION); List<EvaluationAnswer> evaluationAnswers = query.getResultList(); ConcurrentMap<TermsOfConditionStatus, AtomicLong> distributionByTermsOfCompetitionStatus = new ConcurrentHashMap<>(); List<EvaluationQuestionnaireDefEnum> questionnaireDef = Arrays .asList(EvaluationQuestionnaireDefEnum.values()); long numberOfQuestion = questionnaireDef.stream() .filter(q -> q.getQuestionnaireType().equals(QuestionnaireType.TERMS_OF_CONDITION)) .collect(Collectors.counting()); List<MemberRegister> memberRegisters = evaluationAnswers.stream() .filter(StreamUtil.distinctByKey((EvaluationAnswer e) -> e.getMemberRegister().getId())) .map(EvaluationAnswer::getMemberRegister).collect(Collectors.toList()); memberRegisters.stream().forEach((memberRegister) -> { TermsOfConditionStatus termsOfConditionStatus = TermsOfConditionStatus.NONE; if (evaluationAnswers.stream().filter(m -> m.getMemberRegister().equals(memberRegister)) .count() == numberOfQuestion) { boolean isValid = evaluationAnswers.stream() .filter(m -> m.getMemberRegister().equals(memberRegister)) .allMatch(e -> e.getAnswer().getLabel() .equals(messageSource.getMessage("QuestionChoicesDef.yes", null, Locale.ENGLISH))); termsOfConditionStatus = isValid ? TermsOfConditionStatus.VALID : TermsOfConditionStatus.INVALID; } distributionByTermsOfCompetitionStatus.putIfAbsent(termsOfConditionStatus, new AtomicLong(0)); distributionByTermsOfCompetitionStatus.get(termsOfConditionStatus).incrementAndGet(); }); return distributionByTermsOfCompetitionStatus; }
From source file:top.knos.user.services.JpaDaoImpl.java
private UserDetails fillAuthority(UserDetails user) { TypedQuery<Authority> atq = em.createQuery(authoritiesByUsernameQuery, Authority.class).setParameter(1, user.getUsername());// w w w .j a va2 s . c o m List<Authority> Authorities = atq.getResultList(); List<SimpleGrantedAuthority> sgal = new ArrayList<SimpleGrantedAuthority>(); for (Authority a : Authorities) { sgal.add(new SimpleGrantedAuthority(a.getAuthority())); } User domain = (User) user; domain.setAuthorities(sgal); return user; }
From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java
public List<ApplicationDomain> getApplicationsDomainList() { TypedQuery<ApplicationDomain> query = createEntityManager().createQuery("SELECT t FROM ApplicationDomain t", ApplicationDomain.class); return query.getResultList(); }
From source file:br.ufrgs.inf.dsmoura.repository.model.dao.TypesDAO.java
public List<SourceCodeTypeDTO> getSourceCodeTypeDTOList() { TypedQuery<SourceCodeTypeDTO> query = createEntityManager().createQuery("SELECT t FROM SourceCodeTypeDTO t", SourceCodeTypeDTO.class); return query.getResultList(); }