List of usage examples for javax.persistence Query setMaxResults
Query setMaxResults(int maxResult);
From source file:de.inetsource.jsfforum.db.ThreadFacade.java
private Post getPost(Thread t, boolean last) { try {//from ww w .j av a 2s . co m String sort = "asc"; if (last) { sort = "desc"; } Query q = em.createQuery("SELECT p FROM Post p where p.threadId = :thread order by p.created " + sort, Post.class); q.setParameter("thread", t); q.setMaxResults(1); return (Post) q.getSingleResult(); } catch (NoResultException nre) { return null; } }
From source file:org.cleverbus.core.common.asynch.confirm.ConfirmationPollExecutorTest.java
@SuppressWarnings("unchecked") @Nullable//www.jav a 2s.c om private ExternalCall findConfirmation(String correlationId) { String jSql = "SELECT c " + "FROM ExternalCall c " + "WHERE c.entityId = ?1"; Query q = em.createQuery(jSql); q.setParameter(1, correlationId); q.setMaxResults(1); List<ExternalCall> extCalls = (List<ExternalCall>) q.getResultList(); if (extCalls.isEmpty()) { return null; } else { return extCalls.get(0); } }
From source file:com.webbfontaine.valuewebb.search.ShippingLinesFinder.java
public String select() { String sql = "select rimmShipLine from RimmShipLine rimmShipLine where " + "lower(rimmShipLine.cod) like lower(concat(:codParam, '%')) and "; if (FR.equals(Utils.getLanguage())) { sql += "lower(rimmShipLine.dscFr) like lower(concat(:dscParam, '%')) "; } else {//from w ww . j a va 2 s. c om sql += "lower(rimmShipLine.dsc) like lower(concat(:dscParam, '%')) "; } Query query = Utils.setDirectRead(entityManager.createQuery(sql)) .setParameter("codParam", rimmCriteria.getCod()).setParameter("dscParam", rimmCriteria.getDsc()); resultList = query.setMaxResults(Constants.MAX_RECORDS_IN_ATTACHED_FINDER).getResultList(); return null; }
From source file:com.mothsoft.alexis.dao.ModelDaoImpl.java
@Override public Long findAndMarkOne(ModelState current, ModelState toSet) { final Query query = this.em.createQuery("SELECT m FROM Model m WHERE m.state =:state ORDER BY m.id ASC"); query.setParameter("state", current); query.setMaxResults(1); @SuppressWarnings("unchecked") final List<Model> models = (List<Model>) query.getResultList(); if (models == null || models.isEmpty()) { return null; } else {/*from w ww . ja v a 2s. com*/ final Model model = models.get(0); model.setState(toSet); return model.getId(); } }
From source file:org.zkbase.dao.BasicDao.java
/** * Retrieves a paged query.//from www . j a va 2s. c om */ @SuppressWarnings("unchecked") public <T> List<T> find(String queryString, int firstResult, int maxResults, Object... params) { Query query = entityManager.createQuery(queryString); query.setFirstResult(firstResult); query.setMaxResults(maxResults); setParameters(query, params); return query.getResultList(); }
From source file:com.sct.descubriendoturuta.service.UsuarioServiceImpl.java
@Override @Transactional/*from www .j a v a 2 s . c om*/ public Usuario buscarUsuario(Integer id) { Query query = em.createQuery("select u from Usuario u Where u.id = :fid order by u.id"); query.setMaxResults(1); query.setParameter("fid", id); List<Usuario> r = query.getResultList(); return r.isEmpty() ? null : r.get(0); }
From source file:org.zkbase.dao.BasicDao.java
/** * Retrieves a non-paged query/*ww w . j a va2 s.c om*/ */ @SuppressWarnings("unchecked") public <T> List<T> findNamedQuery(final String namedQuery, int firstResult, int maxResult, Object... params) { Query query = entityManager.createNamedQuery(namedQuery); query.setFirstResult(firstResult); query.setMaxResults(maxResult); setParameters(query, params); return query.getResultList(); }
From source file:org.oscarehr.ticklers.service.TicklersDao.java
@SuppressWarnings("unchecked") public List<Tickler> getTicklers(TicklerQuery ticklerQuery) { StringBuilder sql = this.generateQuery(ticklerQuery, false); Query query = entityManager.createQuery(sql.toString()); query.setFirstResult(ticklerQuery.getStart()); query.setMaxResults(ticklerQuery.getLimit()); return query.getResultList(); }
From source file:es.alvsanand.webpage.db.dao.DAOHelper.java
protected Query getNamedQuery(EntityManager entityManager, String queryName, QueryBean queryBean) { Query q = entityManager.createNamedQuery(queryName); if (queryBean != null) { if (queryBean.getLimit() > 0) { q.setMaxResults(queryBean.getLimit()); }// w ww . ja v a 2 s .co m if (queryBean.getOffset() > 0) { q.setFirstResult(queryBean.getOffset()); } } return q; }
From source file:eu.xipi.bro4xipi.brokermodel.BrokerJpaController.java
@SuppressWarnings("unchecked") public List<Broker> read(int firstResult, int maxResults) { Query q = entityManager.createQuery("SELECT m FROM Broker m"); q.setFirstResult(firstResult);//ww w . java 2 s. c o m q.setMaxResults(maxResults); return q.getResultList(); }