List of usage examples for javax.persistence Query setFirstResult
Query setFirstResult(int startPosition);
From source file:com.grummages.app.rest.entity.service.AddonRESTFacade.java
private List<Addon> find(boolean all, int maxResults, int firstResult) { try {/*from w w w . j av a2s .co m*/ Query query = entityManager.createQuery("SELECT object(o) FROM Addon 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.UsersRESTFacade.java
private List<Users> find(boolean all, int maxResults, int firstResult) { try {/* www . ja v a2 s . com*/ Query query = entityManager.createQuery("SELECT object(o) FROM Users AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:org.compass.gps.device.jpa.indexer.DefaultJpaIndexEntitiesIndexer.java
public void performIndex(CompassSession session, IndexEntity[] entities) { for (IndexEntity indexEntity : entities) { EntityInformation entityInformation = (EntityInformation) indexEntity; if (jpaGpsDevice.isFilteredForIndex(entityInformation.getName())) { continue; }//from w ww. j ava2s .com int fetchCount = jpaGpsDevice.getFetchCount(); int current = 0; while (true) { if (!jpaGpsDevice.isRunning()) { return; } EntityManagerWrapper wrapper = jpaGpsDevice.getEntityManagerWrapper().newInstance(); try { wrapper.open(); EntityManager entityManager = wrapper.getEntityManager(); if (log.isDebugEnabled()) { log.debug(jpaGpsDevice.buildMessage("Indexing entities [" + entityInformation.getName() + "] range [" + current + "-" + (current + fetchCount) + "] using query [" + entityInformation.getQueryProvider() + "]")); } Query query = entityInformation.getQueryProvider().createQuery(entityManager, entityInformation); query.setFirstResult(current); query.setMaxResults(fetchCount); List results = query.getResultList(); for (Object result : results) { session.create(result); } session.evictAll(); entityManager.clear(); wrapper.close(); if (results.size() < fetchCount) { break; } current += fetchCount; } catch (Exception e) { log.error(jpaGpsDevice.buildMessage("Failed to index the database"), e); wrapper.closeOnError(); if (!(e instanceof JpaGpsDeviceException)) { throw new JpaGpsDeviceException(jpaGpsDevice.buildMessage("Failed to index the database"), e); } throw (JpaGpsDeviceException) e; } } } }
From source file:com.grummages.app.rest.entity.service.AddressRESTFacade.java
private List<Address> find(boolean all, int maxResults, int firstResult) { try {//from w w w.j a v a 2 s .c o m Query query = entityManager.createQuery("SELECT object(o) FROM Address 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.ListingRESTFacade.java
private List<Listing> find(boolean all, int maxResults, int firstResult) { try {//from w w w . j a v a 2s. c o m Query query = entityManager.createQuery("SELECT object(o) FROM Listing 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.PaymentRESTFacade.java
private List<Payment> find(boolean all, int maxResults, int firstResult) { try {/*from ww w . ja v a 2 s .c o m*/ Query query = entityManager.createQuery("SELECT object(o) FROM Payment AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:service.ItemRESTFacade.java
private List<Item> find(boolean all, int maxResults, int firstResult) { try {//from w w w .j a v a2s . c om Query query = entityManager.createQuery("SELECT object(o) FROM Item AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }
From source file:de.berlios.jhelpdesk.dao.jpa.TicketDAOJpa.java
public List<Ticket> getTicketsWithFilter(final TicketFilter ticketFilter, final int limit, final int offset) throws DAOException { return (List<Ticket>) this.jpaTemplate.execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query q = new QueryBuilder(ticketFilter, em).getFilteredQuery(false); q.setMaxResults(limit);/*from w ww. j a v a 2 s. com*/ q.setFirstResult(offset); return q.getResultList(); } }); }
From source file:service.ResourceRESTFacade.java
private List<Resource> find(boolean all, int maxResults, int firstResult) { try {/*from w ww.ja va2s. c o m*/ Query query = entityManager.createQuery("SELECT object(o) FROM Resource 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.CreditCardRESTFacade.java
private List<CreditCard> find(boolean all, int maxResults, int firstResult) { try {// w w w. j a v a2s . c om Query query = entityManager.createQuery("SELECT object(o) FROM CreditCard AS o"); if (!all) { query.setMaxResults(maxResults); query.setFirstResult(firstResult); } return query.getResultList(); } finally { entityManager.close(); } }