List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:com.pingdu.dao.licenseDao.LicenseDao.java
public Integer sum(int rows) { String jpql = "select lic from License lic where 1=1"; TypedQuery<License> query = em().createQuery(jpql, License.class); //query.setHint(QueryHints.RESULT_TYPE, ResultType.Map); int SUM = ((query.getResultList().size()) - 1) / rows + 1; return SUM;/* w w w . j a v a 2 s. c om*/ }
From source file:com.qpark.eip.core.spring.auth.dao.AuthorityDao.java
/** * Get the {@link AuthenticationType}s out of the database. * * @param enabled/* w w w.j a v a2s.c o m*/ * if not <code>null</code> and <code>true</code> only the * enabled {@link AuthenticationType}s are replied. * @return the list of {@link AuthenticationType}s. */ @Transactional(value = EipPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED) public List<AuthenticationType> getAuthenticationTypes(final Boolean enabled) { CriteriaBuilder cb = this.em.getCriteriaBuilder(); CriteriaQuery<AuthenticationType> q = cb.createQuery(AuthenticationType.class); Root<AuthenticationType> c = q.from(AuthenticationType.class); Predicate ands = cb.conjunction(); ands.getExpressions().add(cb.equal(c.<String>get(AuthenticationType_.context), this.getContextName())); if (enabled != null) { ands.getExpressions().add(cb.equal(c.<Boolean>get(AuthenticationType_.enabled), enabled)); } q.where(ands); q.orderBy(cb.asc(c.<String>get(AuthenticationType_.userName))); TypedQuery<AuthenticationType> typedQuery = this.em.createQuery(q); List<AuthenticationType> list = typedQuery.getResultList(); for (AuthenticationType auth : list) { for (GrantedAuthorityType gr : auth.getGrantedAuthority()) { gr.getRoleName(); } for (int i = 0; i < auth.getGrantedAuthority().size(); i++) { // eager loading... auth.getGrantedAuthority().get(i); } } return list; }
From source file:org.mitre.openid.connect.repository.impl.JpaWhitelistedSiteRepository.java
@Override @Transactional(value = "defaultTransactionManager") public Collection<WhitelistedSite> getByCreator(String creatorId) { TypedQuery<WhitelistedSite> query = manager.createNamedQuery(WhitelistedSite.QUERY_BY_CREATOR, WhitelistedSite.class); query.setParameter(WhitelistedSite.PARAM_USER_ID, creatorId); return query.getResultList(); }
From source file:eu.domibus.common.dao.MessagingDao.java
public UserMessage findUserMessageByMessageId(final String messageId) { final TypedQuery<UserMessage> query = this.em.createNamedQuery("Messaging.findUserMessageByMessageId", UserMessage.class); query.setParameter("MESSAGE_ID", messageId); return DataAccessUtils.singleResult(query.getResultList()); }
From source file:eu.domibus.common.dao.ErrorLogDao.java
public List<ErrorLogEntry> getErrorsForMessage(String messageId) { final TypedQuery<ErrorLogEntry> query = this.em.createNamedQuery("ErrorLogEntry.findErrorsByMessageId", ErrorLogEntry.class); query.setParameter("MESSAGE_ID", messageId); return query.getResultList(); }
From source file:com.plan.proyecto.repositorios.DaoCuentaImpl.java
@Override public Boolean sonAmigos(Cuenta origen, Cuenta amigo) { TypedQuery<Cuenta> query = em.createNamedQuery("Cuenta.findAmigos", Cuenta.class); query.setParameter("idorigen", origen.getId()); query.setParameter("idamigo", amigo); List<Cuenta> temp = query.getResultList(); return !query.getResultList().isEmpty(); }
From source file:csns.model.site.dao.jpa.SiteDaoImpl.java
@Override public List<Site> getSites(Course course, User instructor, int maxResults) { String query = "select s from Site s join s.section.instructors i " + "where s.section.course = :course and (s.shared = true or i = :instructor) " + "order by s.section.quarter desc, s.section.number asc"; TypedQuery<Site> typedQuery = entityManager.createQuery(query, Site.class).setParameter("course", course) .setParameter("instructor", instructor); if (maxResults > 0) typedQuery.setMaxResults(maxResults); return typedQuery.getResultList(); }
From source file:net.navasoft.madcoin.backend.model.controller.helper.impl.JPAHelper.java
/** * Gets the allby query./*from w w w.j av a2 s . c om*/ * * @param em * the em * @param target * the target * @return the allby query * @since 28/08/2014, 11:20:27 PM */ protected List<Entity> getAllbyQuery(EntityManager em, Class<Entity> target) { TypedQuery<Entity> query = em.createNamedQuery(target.getSimpleName() + ".findAll", target); return query.getResultList(); }
From source file:com.epam.training.taranovski.web.project.repository.implementation.EmployerRepositoryImplementation.java
@Override public List<Vacancy> getActiveVacancys(Employer employer) { EntityManager em = entityManagerFactory.createEntityManager(); List<Vacancy> list = new LinkedList<>(); try {// w ww.j a v a2s. c o m em.getTransaction().begin(); TypedQuery<Vacancy> query = em.createNamedQuery("Vacancy.findActiveByEmployer", Vacancy.class); query.setParameter("employer", employer); list = query.getResultList(); em.getTransaction().commit(); } catch (RuntimeException e) { Logger.getLogger(BasicSkillRepositoryImplementation.class.getName()).info(e); } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } return list; }
From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryReferenceCheckImpl.java
@Override public void perform(long now) { logger.debug("{}", name); EntityManager em = datastore.getEntityManager(); try {/*from w ww. ja va 2 s . c o m*/ em.getTransaction().begin(); TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllPublic", VirtualCollection.class); q.setLockMode(LockModeType.PESSIMISTIC_WRITE); for (VirtualCollection vc : q.getResultList()) { checkValidityOfReferences(vc); } em.getTransaction().commit(); } catch (RuntimeException e) { logger.error("unexpected error while doing " + name, e); } finally { datastore.closeEntityManager(); } }