List of usage examples for javax.persistence Query setFirstResult
Query setFirstResult(int startPosition);
From source file:com.grummages.app.rest.entity.service.ListingAddonRESTFacade.java
private List<ListingAddon> find(boolean all, int maxResults, int firstResult) { try {/*from ww w . j a v a 2s . c o m*/ Query query = entityManager.createQuery("SELECT object(o) FROM ListingAddon AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:com.grummages.app.rest.entity.service.ListingPaymentRESTFacade.java
private List<ListingPayment> find(boolean all, int maxResults, int firstResult) { try {/*from ww w . ja v a2s . c o m*/ Query query = entityManager.createQuery("SELECT object(o) FROM ListingPayment AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:com.mothsoft.alexis.dao.ModelDaoImpl.java
@SuppressWarnings("unchecked") @Override//from ww w .j av a2 s.c o m public DataRange<Model> listByOwner(Long userId, int first, int count) { final Query query = this.em .createQuery("SELECT m FROM Model m JOIN m.topic t WHERE t.userId = :userId ORDER BY m.name ASC"); query.setParameter("userId", userId); query.setFirstResult(first); query.setMaxResults(count); final Query query2 = this.em .createQuery("SELECT COUNT(m.id) FROM Model m JOIN m.topic t WHERE t.userId = :userId"); query2.setParameter("userId", userId); int total = ((Number) query2.getSingleResult()).intValue(); final List<Model> list = query.getResultList(); final DataRange<Model> range = new DataRange<Model>(list, first, total); return range; }
From source file:de.hska.ld.content.persistence.repository.custom.impl.DocumentRepositoryImpl.java
@Override @Transactional//from ww w .j a v a2s.c om @SuppressWarnings("unchecked") public Page<Document> searchDocumentByTitleOrDescription(String searchTerm, Pageable pageable) { FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em); // create native Lucene query unsing the query DSL // alternatively you can write the Lucene query using the Lucene query parser // or the Lucene programmatic API. The Hibernate Search DSL is recommended though QueryBuilder searchQb = fullTextEntityManager.getSearchFactory().buildQueryBuilder() .forEntity(Document.class).get(); org.apache.lucene.search.Query luceneQuery = searchQb.phrase().onField("title").andField("description") //.onFields("title", "description") .sentence(searchTerm) //.matching(searchTerm) .createQuery(); // wrap Lucene query in a javax.persistence.Query javax.persistence.Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, Document.class); long total = jpaQuery.getResultList().size(); jpaQuery.setMaxResults(pageable.getPageSize()); jpaQuery.setFirstResult(pageable.getOffset()); // execute search List result = jpaQuery.getResultList(); return new PageImpl<Document>(result, pageable, total); }
From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithEMImpl.java
@Override public List<E> find(int from, int size, String configure) { String jpql = "SELECT e FROM " + entityClass.getName() + " e "; if (configure != null) { jpql = jpql + configure;/*from ww w. j av a 2 s . c o m*/ } Query query = entityManager.createQuery(jpql); if (from != -1) { query.setFirstResult(from); query.setMaxResults(size); } return query.getResultList(); }
From source file:cn.guoyukun.spring.jpa.repository.callback.DefaultSearchCallback.java
public void setPageable(Query query, Searchable search) { if (search.hasPageable()) { Pageable pageable = search.getPage(); query.setFirstResult(pageable.getOffset()); query.setMaxResults(pageable.getPageSize()); }//from w w w . j av a 2s . c o m }
From source file:com.bizintelapps.bugtracker.dao.impl.GenericDaoImpl.java
private List<T> executeQueryReturnList(final String jpql, final PagingParams pagingParams, final Object... params) throws DataAccessException { Query query = entityManager.createQuery(jpql); if (pagingParams != null) { query.setFirstResult((int) pagingParams.getStart()); query.setMaxResults(pagingParams.getMaxLimit()); }//from w w w . ja v a 2 s . co m int i = 1; for (Object param : params) { query.setParameter(i++, param); } try { List result = query.getResultList(); return result; } catch (RuntimeException re) { log.debug(re); return null; } }
From source file:com.panguso.lc.analysis.format.dao.impl.DaoImpl.java
@Override public List<T> search(T condition, int pageNo, int pageSize) { StringBuilder qString = new StringBuilder("select model from " + entityClass.getSimpleName() + " model"); StringBuilder qWhere = new StringBuilder(" where "); StringBuilder qCondition = new StringBuilder(); PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(entityClass); for (int i = 0, count = propertyDescriptors.length; i < count; i++) { PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; String name = propertyDescriptor.getName(); Class<?> type = propertyDescriptor.getPropertyType(); String value = null;/* w w w . j a va 2 s . c om*/ try { value = BeanUtils.getProperty(condition, name); } catch (Exception e) { // ? continue; } if (value == null || name.equals("class")) { continue; } if ("java.lang.String".equals(type.getName())) { qCondition.append("model."); qCondition.append(name); qCondition.append(" like "); qCondition.append("'%"); qCondition.append(value); qCondition.append("%'"); } else { qCondition.append("model."); qCondition.append(name); qCondition.append("="); qCondition.append(value); } qCondition.append(" and "); } if (qCondition.length() != 0) { qString.append(qWhere).append(qCondition); if (qCondition.toString().endsWith(" and ")) { qString.delete(qString.length() - " and ".length(), qString.length()); } } Query query = em.createQuery(qString.toString()); query.setFirstResult(pageNo * pageSize); query.setMaxResults(pageSize); return query.getResultList(); }
From source file:models.Expert.java
@SuppressWarnings("unchecked") public static List<Expert> getPartExpert(String p, Integer pageSize, Long i, String s, String cf, String ssf, String ef, String gf, String o, String ot) { StringBuffer joinBuffer = new StringBuffer("from Expert e join fetch e.user u "); StringBuffer whereStr = new StringBuffer("where (e.userName is not null and u.isEnable = true) "); StringBuffer orderStr = new StringBuffer(); if (null != i) { joinBuffer.append("left join fetch e.inTags i "); whereStr.append("and i.id = :industryId "); }/*from w ww.jav a2s .c o m*/ if (StringUtils.isNotBlank(o)) { if (o.equals("averageScore")) orderStr.append(" order by e.averageScore desc,e.joinDate desc"); if (o.equals("dealNum")) orderStr.append(" order by e.dealNum desc,e.joinDate desc"); if (o.equals("commentNum")) { orderStr.append(" order by e.commentNum desc,e.joinDate desc"); } } else { orderStr.append(" order by e.joinDate desc"); } if (StringUtils.isNotBlank(cf)) whereStr.append(" and e.country = '").append(cf).append("'"); if (StringUtils.isNotBlank(ef)) { if (ef.equals("0")) { whereStr.append(" and e.payType = 0 "); } else if (ef.equals("1")) { whereStr.append(" and e.payType = 1 "); } } if (StringUtils.isNotBlank(gf)) whereStr.append(" and e.gender = ").append(gf); if (s != null) { whereStr.append(" and e.skillsTags like :skilltags "); } joinBuffer.append(whereStr).append(orderStr); Query query = JPA.em().createQuery(joinBuffer.toString()); if (null != i) { query.setParameter("industryId", i); } if (s != null) { return (List<Expert>) query.setParameter("skilltags", "%" + s + "%") .setFirstResult((Integer.parseInt(p) - 1) * pageSize).setMaxResults(pageSize).getResultList(); } else { return (List<Expert>) query.setFirstResult((Integer.parseInt(p) - 1) * pageSize).setMaxResults(pageSize) .getResultList(); } }
From source file:org.orcid.persistence.dao.impl.OrgDisambiguatedDaoImpl.java
@SuppressWarnings("unchecked") @Override/*from w w w.ja v a 2 s. co m*/ @Cacheable("orgs") public List<OrgDisambiguatedEntity> getOrgs(String searchTerm, int firstResult, int maxResults) { String qStr = "select od.*, COUNT(*) as countAll from org_disambiguated od left join org_affiliation_relation oa on od.id = oa.org_id" + " where lower(name) like '%' || lower(:searchTerm) || '%' group by od.id " + " order by position(lower(:searchTerm) in lower(name)), char_length(name), countAll DESC, od.name"; Query query = entityManager.createNativeQuery(qStr, OrgDisambiguatedEntity.class); query.setParameter("searchTerm", searchTerm); query.setFirstResult(firstResult); query.setMaxResults(maxResults); return query.getResultList(); }