Compare commits

...
7 changed files with 161 additions and 39 deletions
+2 -2
View File
@@ -9,7 +9,7 @@
<groupId>org.avaje.ebean</groupId>
<artifactId>ebean</artifactId>
<version>8.2.3</version>
<version>8.3.1</version>
<packaging>jar</packaging>
<name>ebean</name>
@@ -37,7 +37,7 @@
<scm>
<developerConnection>scm:git:https://github.com/ebean-orm/ebean.git</developerConnection>
<tag>ebean-8.2.3</tag>
<tag>ebean-8.3.1</tag>
</scm>
<dependencies>
+8 -21
View File
@@ -112,13 +112,6 @@ public interface PagedList<T> {
*/
void loadCount();
/**
* Deprecated in favor of loadCount().
*
* @deprecated
*/
void loadRowCount();
/**
* Return the Future row count. You might get this if you wish to cancel the total row count query
* or specify a timeout for the row count query.
@@ -147,13 +140,6 @@ public interface PagedList<T> {
*/
Future<Integer> getFutureCount();
/**
* Deprecated in favor of getFutureCount().
*
* @deprecated
*/
Future<Integer> getFutureRowCount();
/**
* Return the list of entities for this page.
*/
@@ -186,13 +172,6 @@ public interface PagedList<T> {
*/
int getTotalCount();
/**
* Deprecated in favor of getTotalCount().
*
* @deprecated
*/
int getTotalRowCount();
/**
* Return the total number of pages based on the page size and total row count.
* <p>
@@ -207,6 +186,14 @@ public interface PagedList<T> {
*/
int getPageSize();
/**
* Return the index position of this page (Zero based).
* <p>
* This is a calculated value based on firstRow/maxRows.
* </p>
*/
int getPageIndex();
/**
* Return true if there is a next page.
* <p>
@@ -1814,7 +1814,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
* properties that make up the unique id.
*/
public Object getId(EntityBean bean) {
return (idProperty == null) ? null : idProperty.getValue(bean);
return (idProperty == null) ? null : idProperty.getValueIntercept(bean);
}
@Override
@@ -47,10 +47,6 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
getFutureCount();
}
public void loadRowCount() {
loadCount();
}
public Future<Integer> getFutureCount() {
synchronized (monitor) {
if (futureRowCount == null) {
@@ -60,10 +56,6 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
}
}
public Future<Integer> getFutureRowCount() {
return getFutureCount();
}
public List<T> getList() {
synchronized (monitor) {
if (list == null) {
@@ -73,6 +65,14 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
}
}
@Override
public int getPageIndex() {
if (firstRow == 0) {
return 0;
}
return ((firstRow - 1) / maxRows) + 1;
}
public int getTotalPageCount() {
int rowCount = getTotalCount();
@@ -102,10 +102,6 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
}
}
public int getTotalRowCount() {
return getTotalCount();
}
public boolean hasNext() {
return (firstRow + maxRows) < getTotalCount();
}
@@ -0,0 +1,105 @@
package com.avaje.ebeaninternal.server.query;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.tests.model.basic.Order;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class LimitOffsetPagedListTest {
private EbeanServer server = Ebean.getDefaultServer();
@Test
public void getPageIndex_when_firstRowsZero() throws Exception {
assertEquals(limit(0, 10).getPageIndex(), 0);
}
@Test
public void getPageIndex_when_10_10() {
assertEquals(limit(10, 10).getPageIndex(), 1);
}
@Test
public void getPageIndex_when_20_10() {
assertEquals(limit(20, 10).getPageIndex(), 2);
}
@Test
public void getPageIndex_when_1_10() throws Exception {
assertEquals(limit(1, 10).getPageIndex(), 1);
}
@Test
public void getPageIndex_when_9_10() throws Exception {
assertEquals(limit(1, 10).getPageIndex(), 1);
}
@Test
public void getPageIndex_when_10_4() {
assertEquals(limit(10, 4).getPageIndex(), 3);
}
@Test
public void getPageIndex_when_10_5() {
assertEquals(limit(10, 5).getPageIndex(), 2);
}
@Test
public void getPageIndex_when_10_9() {
assertEquals(limit(10, 9).getPageIndex(), 2);
}
@Test
public void getPageIndex_when_10_11() {
assertEquals(limit(10, 11).getPageIndex(), 1);
}
@Test
public void getPageIndex_when_21_10() {
assertEquals(limit(21, 10).getPageIndex(), 3);
}
@Test
public void getPageIndex_when_29_10() {
assertEquals(limit(29, 10).getPageIndex(), 3);
}
@Test
public void getPageIndex_when_30_10() {
assertEquals(limit(30, 10).getPageIndex(), 3);
}
@Test
public void getPageIndex_when_31_10() {
assertEquals(limit(31, 10).getPageIndex(), 4);
}
@Test
public void getPageIndex_when_40_10() {
assertEquals(limit(40, 10).getPageIndex(), 4);
}
private LimitOffsetPagedList<Order> limit(int first, int max) {
return limitQuery(queryWith(first, max));
}
private LimitOffsetPagedList<Order> limitQuery(SpiQuery<Order> query) {
return new LimitOffsetPagedList<Order>(server, query);
}
private SpiQuery<Order> queryWith(int first, int max) {
SpiQuery<Order> query = query();
query.setFirstRow(first);
query.setMaxRows(max);
return query;
}
private SpiQuery<Order> query() {
return (SpiQuery<Order>) server.find(Order.class);
}
}
@@ -0,0 +1,34 @@
package com.avaje.tests.batchinsert;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.annotation.Transactional;
import com.avaje.tests.model.basic.Customer;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
public class TestBatchSaveWithGetBeanId extends BaseTestCase {
/**
* Making this transaction with batchSize means that the insert
* below does not occur immediately ... and the getBeanId()
* should invoke the flush (and hence trigger the insert).
*/
@Transactional(batchSize = 10)
@Test
public void test() {
EbeanServer server = Ebean.getDefaultServer();
Customer model = new Customer();
model.setName("foo");
server.insert(model);
// should invoke a flush which then means the
// insert occurs and the bean has an Id value
Object beanId = server.getBeanId(model);
assertNotNull(beanId);
}
}
@@ -58,11 +58,11 @@ public class TestQueryFindPagedList extends BaseTestCase {
.setMaxRows(3)
.findPagedList();
Future<Integer> rowCount = pagedList.getFutureRowCount();
Future<Integer> rowCount = pagedList.getFutureCount();
List<Order> orders = pagedList.getList();
// these are each getting the total row count
int totalRowCount = pagedList.getTotalRowCount();
int totalRowCount = pagedList.getTotalCount();
Integer totalRowCountWithTimeout = rowCount.get(30, TimeUnit.SECONDS);
Integer totalRowCountViaFuture = rowCount.get();
@@ -81,7 +81,7 @@ public class TestQueryFindPagedList extends BaseTestCase {
.setMaxRows(3)
.findPagedList();
pagedList.loadRowCount();
pagedList.loadCount();
List<Order> orders = pagedList.getList();
int totalRowCount = pagedList.getTotalCount();