List of usage examples for javax.persistence TypedQuery getResultList
List<X> getResultList();
From source file:org.openmeetings.app.data.user.dao.UserContactsDaoImpl.java
public List<UserContacts> getContactsByUserAndStatus(Long ownerId, Boolean pending) { try {// www . j av a2 s .c o m String hql = "select c from UserContacts c " + "where c.owner.user_id = :ownerId " + "AND c.pending = :pending " + "AND c.contact.deleted <> 'true'"; TypedQuery<UserContacts> query = em.createQuery(hql, UserContacts.class); query.setParameter("ownerId", ownerId); query.setParameter("pending", pending); List<UserContacts> ll = query.getResultList(); return ll; } catch (Exception e) { log.error("[getContactsByUserAndStatus]", e); } return null; }
From source file:org.openmeetings.app.data.user.dao.UserContactsDaoImpl.java
public List<UserContacts> getContactRequestsByUserAndStatus(Long user_id, Boolean pending) { try {/*from w w w .j a v a2 s . c o m*/ String hql = "select c from UserContacts c " + "where c.contact.user_id = :user_id " + "AND c.pending = :pending " + "AND c.contact.deleted <> 'true'"; TypedQuery<UserContacts> query = em.createQuery(hql, UserContacts.class); query.setParameter("user_id", user_id); query.setParameter("pending", pending); List<UserContacts> ll = query.getResultList(); return ll; } catch (Exception e) { log.error("[getContactRequestsByUserAndStatus]", e); } return null; }
From source file:com.softwarecorporativo.monitoriaifpe.funcionais.atividade.TesteAtividade.java
@Test public void testeConsultarAtividadesSemObservacoes() { TypedQuery<Atividade> query = super.entityManager .createQuery("SELECT a FROM Atividade a WHERE a.observacoes IS NULL", Atividade.class); List<Atividade> atividades = query.getResultList(); assertEquals(46, atividades.size()); for (Atividade atividade : atividades) { assertNull(atividade.getObservacoes()); }//from w w w . jav a2 s . com }
From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java
public List<VirtualMachine> findByVirtualMachineTemplate(final Integer virtualMachineTemplateId) { List<VirtualMachine> vmList = null; TypedQuery<VirtualMachine> query = getEntityManager().createNamedQuery("VIRTUAL_MACHINE.BY_VMT", VirtualMachine.class); query.setParameter("virtualMachineTplId", virtualMachineTemplateId); vmList = query.getResultList(); return vmList; }
From source file:com.healthcit.cacure.dao.FormDao.java
public Collection<FormLibraryForm> findLibraryForms(String query) { TypedQuery<FormLibraryForm> q = this.em.createQuery( "FROM FormLibraryForm form WHERE form.name LIKE :qString ORDER BY form.ord ASC", FormLibraryForm.class); q.setParameter("qString", "%" + query + "%"); return q.getResultList(); }
From source file:org.cleverbus.core.common.dao.MessageDaoJpaImpl.java
@Override public List<Message> findMessagesByContent(String substring) { Assert.hasText("the substring must not be empty", substring); String jSql = "SELECT m " + " FROM " + Message.class.getName() + " m " + " WHERE (m.payload like :substring) ORDER BY m.msgId DESC"; TypedQuery<Message> q = em.createQuery(jSql, Message.class); q.setParameter("substring", "%" + substring + "%"); q.setMaxResults(MAX_MESSAGES_IN_ONE_QUERY); return q.getResultList(); }
From source file:org.ow2.proactive.scheduling.api.graphql.fetchers.DatabaseConnectionFetcher.java
/** * Adaptation of the algorithm defined in the GraphQL specification. * <p>/*from w w w . java 2 s . c om*/ * Please look at the following link for more details: * https://facebook.github.io/relay/graphql/connections.htm#sec-Pagination-algorithm * <p> * The opaque cursor that is returned to the client makes use of the entity ID internally. */ protected ExtendedConnection createPaginatedConnection(DataFetchingEnvironment environment, Class<E> entityClass, Function<Root<E>, Path<? extends Number>> entityId, Comparator<E> entityComparator, BiFunction<CriteriaBuilder, Root<E>, List<Predicate[]>> criteria, CursorMapper<T, Integer> cursorMapper) { Integer first = environment.getArgument(FIRST.getName()); Integer last = environment.getArgument(LAST.getName()); Integer after = cursorMapper.getOffsetFromCursor(environment.getArgument(AFTER.getName())); Integer before = cursorMapper.getOffsetFromCursor(environment.getArgument(BEFORE.getName())); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<E> criteriaQuery = criteriaBuilder.createQuery(entityClass); Root<E> entityRoot = criteriaQuery.from(entityClass); Path<? extends Number> entityIdPath = entityId.apply(entityRoot); Predicate cursorPredicate = createCursorPredicate(criteriaBuilder, entityIdPath, after, before); int maxResults = applySlicing(criteriaQuery, criteriaBuilder, entityIdPath, first, last); CriteriaQuery<E> select = criteriaQuery.select(entityRoot); List<Predicate[]> predicates = criteria.apply(criteriaBuilder, entityRoot); Predicate[] wherePredicate = buildWherePredicate(predicates, cursorPredicate, criteriaBuilder); if (wherePredicate.length > 0) { select.where(wherePredicate); } TypedQuery<E> query = entityManager.createQuery(select); if (maxResults > -1) { query.setMaxResults(maxResults); } Stream<E> dataStream = query.getResultList().stream(); // if last is provided, reverse the stream // in order to get results sorted in ascending order based on entities ID if (last != null) { dataStream = dataStream.sorted(entityComparator); } Stream<T> data = dataMapping(dataStream); ExtendedConnection connection = createRelayConnection(entityManager, entityClass, criteriaBuilder, wherePredicate, cursorMapper, data, first, last); return connection; }
From source file:edu.sabanciuniv.sentilab.sare.models.setcover.DocumentSetCover.java
@Override public Iterable<byte[]> getDocumentIds(EntityManager em) { Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em"); TypedQuery<byte[]> query = em.createQuery( "SELECT scd.id FROM SetCoverDocument scd " + "WHERE scd.store=:sc " + "AND scd.flag=true", byte[].class); query.setParameter("sc", this); return query.getResultList(); }
From source file:org.openmeetings.app.data.user.dao.UserContactsDaoImpl.java
public List<UserContacts> getContactsByShareCalendar(Long contactId, Boolean shareCalendar) { try {/* ww w . j a va 2 s . c o m*/ String hql = "select c from UserContacts c " + "where c.contact.user_id = :contactId " + "AND c.shareCalendar = :shareCalendar " + "AND c.contact.deleted <> 'true'"; TypedQuery<UserContacts> query = em.createQuery(hql, UserContacts.class); query.setParameter("contactId", contactId); query.setParameter("shareCalendar", shareCalendar); List<UserContacts> ll = query.getResultList(); return ll; } catch (Exception e) { log.error("[getContactsByShareCalendar]", e); } return null; }
From source file:org.easyj.orm.jpa.SingleJPAEntityDao.java
@Override protected <E> List<E> getResultListByQuery(String query, Class<E> klazz, Map<String, Object> params, QueryType queryType) {/*from www . j a v a2s.c o m*/ List<E> result = new ArrayList<E>(); TypedQuery<E> q = null; try { if (QueryType.JPQL.equals(queryType)) { q = getEm().createQuery(query, klazz); } else if (QueryType.NAMED.equals(queryType)) { q = getEm().createNamedQuery(query, klazz); } if (setParameters(q, params)) { result = q.getResultList(); } } finally { closeEm(); } return result; }