Add PagedList was part of #96

This commit is contained in:
Rob Bygrave
2014-05-16 01:41:56 +12:00
parent 1a4192b40f
commit 41f3173adf
11 changed files with 367 additions and 45 deletions
@@ -8,7 +8,6 @@ import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Update;
import com.avaje.tests.model.basic.EBasic;
public class TestExplicitInsert extends BaseTestCase {
@@ -16,9 +15,6 @@ public class TestExplicitInsert extends BaseTestCase {
@Test
public void test() {
// GlobalProperties.put("ebean.classes",
// ""+LDPerson.class.toString()+","+EBasic.class.toString());
EBasic b = new EBasic();
b.setName("exp insert");
b.setDescription("explicit insert");
@@ -38,28 +34,9 @@ public class TestExplicitInsert extends BaseTestCase {
Assert.assertNotNull(b2.getId());
Assert.assertTrue(!b.getId().equals(b2.getId()));
List<EBasic> list = server.find(EBasic.class).setMaxRows(10).findList();
List<EBasic> list = server.find(EBasic.class).where().in("id",b.getId(), b2.getId()).findList();
Assert.assertTrue(list.size() >= 2);
int firstRow = 1;
List<EBasic> list2 = server.find(EBasic.class).order().asc("id").setFirstRow(firstRow)
.setMaxRows(10).findList();
int expectedCount = list.size() - firstRow;
if (expectedCount > 0) {
Assert.assertEquals(expectedCount, list2.size());
} else {
Assert.assertTrue(list2.isEmpty());
}
Update<EBasic> update = Ebean.createUpdate(EBasic.class,
"update ebasic set description = 'test'");
int rows = update.execute();
Assert.assertTrue(rows > 0);
Ebean.externalModification("e_basic", true, false, true);
Assert.assertEquals(2, list.size());
}
}
@@ -0,0 +1,76 @@
package com.avaje.tests.query.other;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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.PagedList;
import com.avaje.ebean.Transaction;
import com.avaje.tests.model.basic.EBasic;
public class TestFindPagedList extends BaseTestCase {
@Test
public void test() throws InterruptedException, ExecutionException {
EbeanServer server = Ebean.getServer(null);
Transaction transaction = server.beginTransaction();
try {
transaction.setBatchMode(true);
transaction.setBatchSize(20);
for (int i = 0; i < 87; i++) {
EBasic dumbModel = new EBasic();
dumbModel.setName("HelloB0Bi");
server.save(dumbModel);
}
transaction.commit();
} finally {
transaction.end();
}
PagedList<EBasic> list1 = Ebean.find(EBasic.class)
.where().like("name", "HelloB0B%")
.findPagedList(0, 10);
list1.loadRowCount();
List<EBasic> list = list1.getList();
int totalRowCount = list1.getTotalRowCount();
int totalPageCount = list1.getTotalPageCount();
Assert.assertEquals(10, list.size());
Assert.assertEquals(87, totalRowCount);
Assert.assertEquals(9, totalPageCount);
PagedList<EBasic> list2 = Ebean.find(EBasic.class)
.where().like("name", "HelloB0B%")
.findPagedList(4, 10);
list = list2.getList();
Assert.assertEquals(10, list2.getList().size());
Assert.assertEquals(87, list2.getTotalRowCount());
Assert.assertEquals(9, list2.getTotalPageCount());
PagedList<EBasic> list3 = Ebean.find(EBasic.class)
.where().like("name", "HelloB0B%")
.findPagedList(8, 10);
Future<Integer> rowCount = list3.getFutureRowCount();
list = list3.getList();
Assert.assertEquals(Integer.valueOf(87), rowCount.get());
Assert.assertEquals(7, list3.getList().size());
Assert.assertEquals(87, list3.getTotalRowCount());
Assert.assertEquals(9, list3.getTotalPageCount());
}
}