From 09f8967459783b7304a86e23fbc2186909707d50 Mon Sep 17 00:00:00 2001 From: rbygrave Date: Mon, 1 Dec 2014 21:52:40 +1300 Subject: [PATCH] #215 - Remove findPagingList() ... it has been deprecated for a while, please migrate to findPagedList() --- .../java/com/avaje/ebean/EbeanServer.java | 7 - .../java/com/avaje/ebean/ExpressionList.java | 19 -- src/main/java/com/avaje/ebean/PagingList.java | 127 ---------- src/main/java/com/avaje/ebean/Query.java | 7 - .../server/core/DefaultServer.java | 22 -- .../server/expression/JunctionExpression.java | 4 - .../server/query/LimitOffsetList.java | 225 ------------------ .../server/query/LimitOffsetPage.java | 107 --------- .../server/query/LimitOffsetPagingQuery.java | 137 ----------- .../server/querydefn/DefaultOrmQuery.java | 4 - .../util/DefaultExpressionList.java | 4 - .../util/FilterExpressionList.java | 22 +- .../ebeaninternal/api/TDSpiEbeanServer.java | 5 - .../com/avaje/tests/basic/TestPaging.java | 188 --------------- 14 files changed, 5 insertions(+), 873 deletions(-) delete mode 100644 src/main/java/com/avaje/ebean/PagingList.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetList.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPage.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPagingQuery.java delete mode 100644 src/test/java/com/avaje/tests/basic/TestPaging.java diff --git a/src/main/java/com/avaje/ebean/EbeanServer.java b/src/main/java/com/avaje/ebean/EbeanServer.java index 4f535a96e..bab70c33e 100644 --- a/src/main/java/com/avaje/ebean/EbeanServer.java +++ b/src/main/java/com/avaje/ebean/EbeanServer.java @@ -578,13 +578,6 @@ public interface EbeanServer { */ public SqlFutureList findFutureList(SqlQuery query, Transaction transaction); - /** - * Find using a PagingList with explicit transaction and pageSize. - * Deprecated in favour of findPagedList(). - * @deprecated - */ - public PagingList findPagingList(Query query, Transaction transaction, int pageSize); - /** * Return a PagedList for this query. *

diff --git a/src/main/java/com/avaje/ebean/ExpressionList.java b/src/main/java/com/avaje/ebean/ExpressionList.java index a52a9bcb6..771adbb58 100644 --- a/src/main/java/com/avaje/ebean/ExpressionList.java +++ b/src/main/java/com/avaje/ebean/ExpressionList.java @@ -208,25 +208,6 @@ public interface ExpressionList extends Serializable { */ public FutureList findFutureList(); - /** - * Return a PagingList for this query. - *

- * This can be used to break up a query into multiple queries to fetch the - * data a page at a time. - *

- *

- * This typically works by using a query per page and setting - * {@link Query#setFirstRow(int)} and and {@link Query#setMaxRows(int)} on the - * query. This usually would translate into SQL that uses limit offset, rownum - * or row_number function to limit the result set. - *

- * - * @param pageSize - * the number of beans fetched per Page - * @deprecated - */ - public PagingList findPagingList(int pageSize); - /** * Return a PagedList for this query. *

diff --git a/src/main/java/com/avaje/ebean/PagingList.java b/src/main/java/com/avaje/ebean/PagingList.java deleted file mode 100644 index a2dc38f21..000000000 --- a/src/main/java/com/avaje/ebean/PagingList.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.avaje.ebean; - -import java.util.List; -import java.util.concurrent.Future; - -/** - * Used to page through a query result rather than fetching all the results in a - * single query. - *

- * Has the ability to use background threads to 'fetch ahead' the next page and - * get the total row count. - *

- *

- * If you are building a stateless web application and not keeping the - * PagingList over multiple requests then there is not much to be gained in - * using PagingList. Instead you can just use {@link Query#setFirstRow(int)} and - * {@link Query#setMaxRows(int)}. - *

- * - *

- * If you are using PagingList is a stateful web application where the - * PagingList is held over multiple requests then PagingList provides the extra - * benefits of - *

    - *
  • Fetch ahead - automatically fetching the next page via background query - * execution
  • - *
  • Automatic propagation of the persistence context
  • - *
- *

- *

- * So with PagingList when you use Page 2 it can automatically fetch Page 3 data - * in the background (using a findFutureList() query). It also automatically - * propagates the persistence context so that all the queries executed by the - * PagingList all use the same persistence context. - *

- * - *
- * PagingList<TOne> pagingList =
- *     Ebean.find(TOne.class)
- *         .where().gt("name", "2")
- *         .findPagingList(10);
- * 
- * // get the row count in the background...
- * // ... otherwise it is fetched on demand
- * // ... when getRowCount() or getPageCount()
- * // ... is called
- * pagingList.getFutureRowCount();
- * 
- * // get the first page
- * Page<TOne> page = pagingList.getPage(0);
- * 
- * // get the beans from the page as a list
- * List<TOne> list = page.getList();
- * 
- * - * @author rbygrave - * - * @param - * the entity bean type - */ -public interface PagingList { - - /** - * Refresh will clear all the pages and row count forcing them to be - * re-fetched when next required. - */ - public void refresh(); - - // public void fetchAll(); - // public String? getOrderBy(); - // public void setOrderBy(String?); - - /** - * By default fetchAhead is true so use this to turn off fetchAhead. - *

- * Set this to false if you don't want to fetch ahead using background - * fetching. - *

- * If set to true (or left as to default) then the next page is fetched in the - * background as soon as the list is accessed. - *

- */ - public PagingList setFetchAhead(boolean fetchAhead); - - /** - * Return the Future for getting the total row count. - */ - public Future getFutureRowCount(); - - /** - * Return the data for all the pages in the form of a single List. - *

- * Iterating through this list will automatically fire the paging queries as - * required. - *

- */ - public List getAsList(); - - /** - * Return the page size. This is the number of rows per page. - */ - public int getPageSize(); - - /** - * Return the total row count. - *

- * This gets the result from getFutureRowCount and will wait until that query - * has completed. - *

- */ - public int getTotalRowCount(); - - /** - * Return the total page count. - *

- * This is based on the total row count. This will wait until the row count - * has returned if it has not already. - *

- */ - public int getTotalPageCount(); - - /** - * Return the page for a given page position (starting at 0). - */ - public Page getPage(int i); - -} diff --git a/src/main/java/com/avaje/ebean/Query.java b/src/main/java/com/avaje/ebean/Query.java index d6c44413e..fc26f05f2 100644 --- a/src/main/java/com/avaje/ebean/Query.java +++ b/src/main/java/com/avaje/ebean/Query.java @@ -684,13 +684,6 @@ public interface Query extends Serializable { */ public FutureList findFutureList(); - /** - * This is being deprecated in favour of the simplier {@link Query#findPagedList(int, int)}. - * - * @deprecated - */ - public PagingList findPagingList(int pageSize); - /** * Return a PagedList for this query. *

diff --git a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java index 134b7506b..3acd632d9 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java +++ b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultServer.java @@ -1338,28 +1338,6 @@ public final class DefaultServer implements SpiEbeanServer { return queryFuture; } - public PagingList findPagingList(Query query, Transaction t, int pageSize) { - - SpiQuery spiQuery = (SpiQuery) query; - - // we want to use a single PersistenceContext to be used - // for all the paging queries so we make sure there is a - // PersistenceContext on the query - PersistenceContext pc = spiQuery.getPersistenceContext(); - if (pc == null) { - SpiTransaction currentTransaction = getCurrentServerTransaction(); - if (currentTransaction != null) { - pc = currentTransaction.getPersistenceContext(); - } - if (pc == null) { - pc = new DefaultPersistenceContext(); - } - spiQuery.setPersistenceContext(pc); - } - - return new LimitOffsetPagingQuery(this, spiQuery, pageSize); - } - @Override public PagedList findPagedList(Query query, Transaction transaction, int pageIndex, int pageSize) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/expression/JunctionExpression.java b/src/main/java/com/avaje/ebeaninternal/server/expression/JunctionExpression.java index 3fd87cdc4..38ffba170 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/expression/JunctionExpression.java +++ b/src/main/java/com/avaje/ebeaninternal/server/expression/JunctionExpression.java @@ -247,10 +247,6 @@ abstract class JunctionExpression implements Junction, SpiExpression, Expr public Map findMap(String keyProperty, Class keyType) { return exprList.findMap(keyProperty, keyType); } - - public PagingList findPagingList(int pageSize) { - return exprList.findPagingList(pageSize); - } @Override public PagedList findPagedList(int pageIndex, int pageSize) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetList.java b/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetList.java deleted file mode 100644 index a61f9ffff..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetList.java +++ /dev/null @@ -1,225 +0,0 @@ -package com.avaje.ebeaninternal.server.query; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import com.avaje.ebean.Page; - -public class LimitOffsetList implements List { - - private final LimitOffsetPagingQuery owner; - - private List localCopy; - - public LimitOffsetList(LimitOffsetPagingQuery owner) { - this.owner = owner; - } - - private void ensureLocalCopy() { - if (localCopy == null){ - localCopy = new ArrayList(); - - int pgIndex = 0; - while(true){ - Page page = owner.getPage(pgIndex++); - List list = page.getList(); - localCopy.addAll(list); - if (!page.hasNext()){ - break; - } - } - } - } - - private boolean hasNext(int position){ - return owner.hasNext(position); - } - - public void clear() { - localCopy = new ArrayList(); - } - - public T get(int index) { - if (localCopy != null){ - return localCopy.get(index); - } else { - return owner.get(index); - } - } - - public boolean isEmpty() { - if (localCopy != null){ - return localCopy.isEmpty(); - } else { - return owner.getTotalRowCount() == 0; - } - } - - public int size() { - if (localCopy != null){ - return localCopy.size(); - } else { - return owner.getTotalRowCount(); - } - } - - public Iterator iterator() { - if (localCopy != null){ - return localCopy.iterator(); - } else { - return new ListItr(this, 0); - } - } - - public ListIterator listIterator() { - if (localCopy != null){ - return localCopy.listIterator(); - } else { - return new ListItr(this, 0); - } - } - - public ListIterator listIterator(int index) { - if (localCopy != null){ - return localCopy.listIterator(index); - } else { - return new ListItr(this, index); - } - } - - public List subList(int fromIndex, int toIndex) { - if (localCopy != null){ - return localCopy.subList(fromIndex, toIndex); - } else { - //FIXME: subList not implemented ... - throw new RuntimeException("Not implemented at this point"); - } - } - - public int lastIndexOf(Object o) { - ensureLocalCopy(); - return localCopy.lastIndexOf(o); - } - - public void add(int index, T element) { - ensureLocalCopy(); - localCopy.add(index, element); - } - - public boolean add(T o) { - ensureLocalCopy(); - return localCopy.add(o); - } - - public boolean addAll(Collection c) { - ensureLocalCopy(); - return localCopy.addAll(c); - } - - public boolean addAll(int index, Collection c) { - ensureLocalCopy(); - return localCopy.addAll(index, c); - } - - public boolean contains(Object o) { - ensureLocalCopy(); - return localCopy.contains(o); - } - - public boolean containsAll(Collection c) { - ensureLocalCopy(); - return localCopy.containsAll(c); - } - - public int indexOf(Object o) { - ensureLocalCopy(); - return localCopy.indexOf(o); - } - - public T remove(int index) { - ensureLocalCopy(); - return localCopy.remove(index); - } - - public boolean remove(Object o) { - ensureLocalCopy(); - return localCopy.remove(o); - } - - public boolean removeAll(Collection c) { - ensureLocalCopy(); - return localCopy.removeAll(c); - } - - public boolean retainAll(Collection c) { - ensureLocalCopy(); - return localCopy.retainAll(c); - } - - public T set(int index, T element) { - ensureLocalCopy(); - return localCopy.set(index, element); - } - - - public Object[] toArray() { - ensureLocalCopy(); - return localCopy.toArray(); - } - - public K[] toArray(K[] a) { - ensureLocalCopy(); - return localCopy.toArray(a); - } - - private class ListItr implements ListIterator { - - private LimitOffsetList ownerList; - private int position; - - ListItr(LimitOffsetList ownerList, int position) { - this.ownerList = ownerList; - this.position = position; - } - - public void add(T o) { - ownerList.add(position++, o); - } - - public boolean hasNext() { - return ownerList.hasNext(position); - } - - public boolean hasPrevious() { - return position > 0; - } - - public T next() { - return ownerList.get(position++); - } - - public int nextIndex() { - return position; - } - - public T previous() { - return get(--position); - } - - public int previousIndex() { - return position - 1; - } - - public void remove() { - throw new RuntimeException("Not supported yet"); - } - - public void set(T o) { - throw new RuntimeException("Not supported yet"); - } - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPage.java b/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPage.java deleted file mode 100644 index a18f60463..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPage.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.avaje.ebeaninternal.server.query; - -import java.util.List; - -import javax.persistence.PersistenceException; - -import com.avaje.ebean.FutureList; -import com.avaje.ebean.Page; -import com.avaje.ebean.bean.BeanCollection; -import com.avaje.ebean.bean.BeanCollectionTouched; -import com.avaje.ebeaninternal.api.SpiQuery; - -/** - * Page implementation based on limit offset types of queries. - * - * @author rbygrave - * - * @param - * the entity bean type - */ -public class LimitOffsetPage implements Page, BeanCollectionTouched { - - private final int pageIndex; - - private final LimitOffsetPagingQuery owner; - - private FutureList futureList; - - public LimitOffsetPage(int pageIndex, LimitOffsetPagingQuery owner) { - this.pageIndex = pageIndex; - this.owner = owner; - } - - public FutureList getFutureList() { - - if (futureList == null) { - SpiQuery originalQuery = owner.getSpiQuery(); - SpiQuery copy = originalQuery.copy(); - copy.setPersistenceContext(originalQuery.getPersistenceContext()); - - int pageSize = owner.getPageSize(); - copy.setFirstRow(pageIndex * pageSize); - copy.setMaxRows(pageSize); - copy.setBeanCollectionTouched(this); - futureList = owner.getServer().findFutureList(copy, null); - } - - return futureList; - } - - /** - * Perform fetch ahead when the list is first accessed. - */ - public void notifyTouched(BeanCollection c) { - if (hasNext()) { - owner.fetchAheadIfRequired(pageIndex); - } - } - - public List getList() { - try { - return getFutureList().get(); - } catch (Exception e) { - throw new PersistenceException(e); - } - } - - public boolean hasNext() { - return pageIndex < getTotalPageCount() - 1; - } - - public boolean hasPrev() { - return pageIndex > 0; - } - - public Page next() { - return owner.getPage(pageIndex + 1); - } - - public Page prev() { - return owner.getPage(pageIndex - 1); - } - - public int getPageIndex() { - return pageIndex; - } - - public int getTotalPageCount() { - return owner.getTotalPageCount(); - } - - public int getTotalRowCount() { - return owner.getTotalRowCount(); - } - - public String getDisplayXtoYofZ(String to, String of) { - - int first = pageIndex * owner.getPageSize() + 1; - int last = first + getList().size() - 1; - int total = getTotalRowCount(); - - return first+to+last+of+total; - } - - - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPagingQuery.java b/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPagingQuery.java deleted file mode 100644 index 915c037cc..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/query/LimitOffsetPagingQuery.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.avaje.ebeaninternal.server.query; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; - -import javax.persistence.PersistenceException; - -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.Page; -import com.avaje.ebean.PagingList; -import com.avaje.ebeaninternal.api.Monitor; -import com.avaje.ebeaninternal.api.SpiQuery; - -public class LimitOffsetPagingQuery implements PagingList { - - private transient EbeanServer server; - - private final SpiQuery query; - - private final List> pages = new ArrayList>(); - - private final Monitor monitor = new Monitor(); - - private final int pageSize; - - private boolean fetchAhead = true; - - private Future futureRowCount; - - public LimitOffsetPagingQuery(EbeanServer server, SpiQuery query, int pageSize) { - this.query = query; - this.pageSize = pageSize; - this.server = server; - } - - public EbeanServer getServer() { - return server; - } - - public void setServer(EbeanServer server) { - this.server = server; - } - - public SpiQuery getSpiQuery() { - return query; - } - - public PagingList setFetchAhead(boolean fetchAhead) { - this.fetchAhead = fetchAhead; - return this; - } - - public List getAsList() { - return new LimitOffsetList(this); - } - - public Future getFutureRowCount() { - synchronized (monitor) { - if (futureRowCount == null){ - futureRowCount = server.findFutureRowCount(query, null); - } - return futureRowCount; - } - } - - private LimitOffsetPage internalGetPage(int i){ - synchronized (monitor) { - int ps = pages.size(); - if (ps <= i){ - for (int j = ps; j <= i; j++) { - LimitOffsetPage p = new LimitOffsetPage(j, this); - pages.add(p); - } - } - return pages.get(i); - } - } - - protected void fetchAheadIfRequired(int pageIndex){ - synchronized (monitor) { - // Already checked in LimitOffsetPage that there is another page - if (fetchAhead){ - // fetchAhead is turned on so get the next page and trigger query - LimitOffsetPage nextPage = internalGetPage(pageIndex + 1); - nextPage.getFutureList(); - } - } - } - - public void refresh() { - synchronized (monitor) { - futureRowCount = null; - pages.clear(); - } - } - - public Page getPage(int i) { - return internalGetPage(i); - } - - protected boolean hasNext(int position){ - return position < getTotalRowCount(); - } - - protected T get(int rowIndex){ - int pg = rowIndex / pageSize; - int offset = rowIndex % pageSize; - - Page page = getPage(pg); - return page.getList().get(offset); - } - - public int getTotalPageCount() { - - int rowCount = getTotalRowCount(); - if (rowCount == 0){ - return 0; - } else { - return ((rowCount-1) / pageSize) + 1; - } - } - - public int getPageSize() { - return pageSize; - } - - public int getTotalRowCount() { - try { - return getFutureRowCount().get(); - } catch (Exception e) { - throw new PersistenceException(e); - } - } - - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/querydefn/DefaultOrmQuery.java b/src/main/java/com/avaje/ebeaninternal/server/querydefn/DefaultOrmQuery.java index f3fcaf2bc..ceb682952 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/querydefn/DefaultOrmQuery.java +++ b/src/main/java/com/avaje/ebeaninternal/server/querydefn/DefaultOrmQuery.java @@ -963,10 +963,6 @@ public class DefaultOrmQuery implements SpiQuery { return server.findFutureRowCount(this, null); } - public PagingList findPagingList(int pageSize) { - return server.findPagingList(this, null, pageSize); - } - @Override public PagedList findPagedList(int pageIndex, int pageSize) { return server.findPagedList(this, null, pageIndex, pageSize); diff --git a/src/main/java/com/avaje/ebeaninternal/util/DefaultExpressionList.java b/src/main/java/com/avaje/ebeaninternal/util/DefaultExpressionList.java index 44c81522a..fe6134976 100644 --- a/src/main/java/com/avaje/ebeaninternal/util/DefaultExpressionList.java +++ b/src/main/java/com/avaje/ebeaninternal/util/DefaultExpressionList.java @@ -143,10 +143,6 @@ public class DefaultExpressionList implements SpiExpressionList { return query.findFutureList(); } - public PagingList findPagingList(int pageSize) { - return query.findPagingList(pageSize); - } - @Override public PagedList findPagedList(int pageIndex, int pageSize) { return query.findPagedList(pageIndex, pageSize); diff --git a/src/main/java/com/avaje/ebeaninternal/util/FilterExpressionList.java b/src/main/java/com/avaje/ebeaninternal/util/FilterExpressionList.java index c6be63752..c2eeadd3b 100644 --- a/src/main/java/com/avaje/ebeaninternal/util/FilterExpressionList.java +++ b/src/main/java/com/avaje/ebeaninternal/util/FilterExpressionList.java @@ -1,22 +1,14 @@ package com.avaje.ebeaninternal.util; +import com.avaje.ebean.*; +import com.avaje.ebeaninternal.api.SpiExpressionList; +import com.avaje.ebeaninternal.server.expression.FilterExprPath; + +import javax.persistence.PersistenceException; import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.PersistenceException; - -import com.avaje.ebean.ExpressionFactory; -import com.avaje.ebean.ExpressionList; -import com.avaje.ebean.FutureIds; -import com.avaje.ebean.FutureList; -import com.avaje.ebean.FutureRowCount; -import com.avaje.ebean.OrderBy; -import com.avaje.ebean.PagingList; -import com.avaje.ebean.Query; -import com.avaje.ebeaninternal.api.SpiExpressionList; -import com.avaje.ebeaninternal.server.expression.FilterExprPath; - public class FilterExpressionList extends DefaultExpressionList { private static final long serialVersionUID = 2226895827150099020L; @@ -71,10 +63,6 @@ public class FilterExpressionList extends DefaultExpressionList { return rootQuery.findMap(); } - public PagingList findPagingList(int pageSize) { - return rootQuery.findPagingList(pageSize); - } - public int findRowCount() { return rootQuery.findRowCount(); } diff --git a/src/test/java/com/avaje/ebeaninternal/api/TDSpiEbeanServer.java b/src/test/java/com/avaje/ebeaninternal/api/TDSpiEbeanServer.java index d2a074738..4fb8f035f 100644 --- a/src/test/java/com/avaje/ebeaninternal/api/TDSpiEbeanServer.java +++ b/src/test/java/com/avaje/ebeaninternal/api/TDSpiEbeanServer.java @@ -438,11 +438,6 @@ public class TDSpiEbeanServer implements SpiEbeanServer { return null; } - @Override - public PagingList findPagingList(Query query, Transaction transaction, int pageSize) { - return null; - } - @Override public PagedList findPagedList(Query query, Transaction transaction, int pageIndex, int pageSize) { return null; diff --git a/src/test/java/com/avaje/tests/basic/TestPaging.java b/src/test/java/com/avaje/tests/basic/TestPaging.java deleted file mode 100644 index 0c618caf0..000000000 --- a/src/test/java/com/avaje/tests/basic/TestPaging.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.avaje.tests.basic; - -import java.util.List; -import java.util.Random; - -import org.junit.Assert; -import org.junit.Test; - -import com.avaje.ebean.BaseTestCase; -import com.avaje.ebean.Ebean; -import com.avaje.ebean.EbeanServer; -import com.avaje.ebean.Page; -import com.avaje.ebean.PagingList; -import com.avaje.ebean.Query; -import com.avaje.tests.model.basic.TOne; - -public class TestPaging extends BaseTestCase { - - - private void loadData() { - - int rowCount = Ebean.find(TOne.class).findRowCount(); - if (rowCount > 500){ - return; - } - - Random r = new Random(); - Ebean.beginTransaction(); - try { - for (int i = 0; i < 1000; i++) { - TOne o = new TOne(); - - int rvalue = r.nextInt(100000); - o.setName(rvalue+"name"); - o.setDescription(rvalue+""); - Ebean.save(o); - } - Ebean.commitTransaction(); - } finally { - Ebean.endTransaction(); - } - - } - - @Test - public void test() throws Exception { - - loadData(); - //checkLastPage(); - //bgFetchOne(); - pagingOne(); - } - -// private void checkLastPage() { -// -// -// PagingList pagingList = -// Ebean.find(TOne.class) -// .where().gt("name", "2") -// .findPagingList(10); -// -// -// pagingList.setFetchAhead(false); -// -// Page lastPage = pagingList.getPage(pagingList.getTotalPageCount() - 1); -// String displayLastPage = lastPage.getDisplayXtoYofZ(" to "," of "); -// System.out.println("LASTPAGE: "+displayLastPage); -// -// List list = lastPage.getList(); -// list.get(0); -// -// Assert.assertFalse(lastPage.hasNext()); -// -// } - -// @SuppressWarnings("unchecked") -// private void bgFetchOne() { -// -// -// Query query = Ebean.find(TOne.class) -// .setAutofetch(false) -// .select("id") -// .where().gt("name", "2") -// .setBackgroundFetchAfter(10) -// //.setMaxRows(20) -// .orderBy("id"); -// -// //query.findList(); -// //query.findIds(); -// -//// long t1 = System.currentTimeMillis(); -// -// List ids = query.findList(); -// //List ids = query.findIds(); -// -//// long t0 = System.currentTimeMillis(); -//// System.out.println("Got: "+ids.size()); -// BeanCollection bc = (BeanCollection)ids; -// bc.backgroundFetchWait(); -// -//// long ex0 = System.currentTimeMillis() - t0; -//// long ex1 = System.currentTimeMillis() - t1; -//// System.out.println("Got: "+ids.size()); -//// System.out.println("exetime t0:"+ex0+" t1:"+ex1); -// //System.out.println("done "+bc.size()); -// } - - private void pagingOne() throws InterruptedException { - - loadData(); - - int pageSize = 10; - - PagingList pagingList = - Ebean.find(TOne.class) - .select("id") - //.where().gt("name", "2") - .findPagingList(10); - - - // get the row count in the background... - // ... otherwise it is fetched on demand - // ... when getRowCount() or getPageCount() - // ... is called - pagingList.getFutureRowCount(); - - // get the first page - Page page = pagingList.getPage(0); - //String display0 = page.getDisplayXtoYofZ(" to "," of "); - //System.out.println("PAGE0: "+display0); - - // get the beans from the page as a list - List list = page.getList(); - Assert.assertTrue("page size ",list.size() == pageSize); - - int totalRows = pagingList.getTotalRowCount(); - Assert.assertTrue("page size ",totalRows >= list.size()); - - Thread.sleep(300); - - Page next = page.next(); - //String display1 = next.getDisplayXtoYofZ(" to "," of "); - //System.out.println("PAGE1: "+display1); - - List list2 = next.getList(); - - Assert.assertTrue("page size ",list2.size() == pageSize); - - if (page.hasNext()){ - Page next3 = page.next(); - List list3 = next3.getList(); - Assert.assertTrue("page size ",list3.size() == pageSize); - } - - - Page lastPage = pagingList.getPage(pagingList.getTotalPageCount() - 1); - //String displayLastPage = lastPage.getDisplayXtoYofZ(" to "," of "); - //System.out.println("LASTPAGE: "+displayLastPage); - - Assert.assertFalse(lastPage.hasNext()); - - checkForLoop(); - } - - private void checkForLoop() { - - EbeanServer server = Ebean.getServer(null); - - Query query = server.find(TOne.class) - .where().gt("name", "2") - .query(); - - int pageSize = 10; - - PagingList pagingList = server.findPagingList(query, null, pageSize); - - List asList = pagingList.getAsList(); - for (int i = 0; i < asList.size(); i++) { - if (i % 10 == 0){ - //System.out.println("here"); - } - TOne tOne = asList.get(i); - tOne.hashCode(); - //System.out.print("."); - } - } - -}