use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStateful.
public void testOffsetLimitStateful() {
DiscoveryStringId[] discs = new DiscoveryStringId[150];
for (int i = 0; i < 150; i++) {
discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
}
pm.insert((Object[]) discs);
Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().order("name");
List<DiscoveryStringId> res = query.offset(50).limit(50).fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50], res.get(i));
}
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulIter.
public void testOffsetLimitStatefulIter() {
DiscoveryStringId[] discs = new DiscoveryStringId[150];
for (int i = 0; i < 150; i++) {
discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
}
pm.insert((Object[]) discs);
Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().order("name");
Iterable<DiscoveryStringId> iter = query.offset(50).limit(50).iter();
Iterator<DiscoveryStringId> it = iter.iterator();
int i = 50;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(100, i);
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testFetchPaginateStatefulTwiceKeys.
public void testFetchPaginateStatefulTwiceKeys() {
DiscoveryStringId[] discs = new DiscoveryStringId[15];
for (int i = 0; i < 15; i++) {
discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
}
pm.insert((Object[]) discs);
Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().paginate(5).order("name");
List<DiscoveryStringId> res = query.fetchKeys();
assertEquals(5, res.size());
for (int i = 0; i < 5; i++) {
assertEquals(discs[i].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(5, res.size());
for (int i = 0; i < 5; i++) {
assertEquals(discs[i + 5].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.paginate(8).fetchKeys();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i + 5].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(2, res.size());
for (int i = 0; i < 2; i++) {
assertEquals(discs[i + 13].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testIterPerPageStateful2.
public void testIterPerPageStateful2() {
DiscoveryStringId[] discs = new DiscoveryStringId[500];
for (int i = 0; i < 500; i++) {
discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
}
pm.insert((Object[]) discs);
Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().order("name");
Iterable<DiscoveryStringId> iter = query.iterPerPage(50);
Iterator<DiscoveryStringId> it = iter.iterator();
int i = 0;
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
assertEquals(500, i);
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginate2.
public void testOffsetLimitStatefulPaginate2() {
DiscoveryStringId[] discs = new DiscoveryStringId[300];
for (int i = 0; i < 300; i++) {
discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
}
pm.insert((Object[]) discs);
Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).order("name").stateful();
List<DiscoveryStringId> res = query.limit(50).offset(12).fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 12], res.get(i));
}
res = query.offset(13).limit(30).fetch();
assertEquals(30, res.size());
for (int i = 0; i < 30; i++) {
assertEquals(discs[i + 75], res.get(i));
}
res = query.offset(10).limit(30).fetch(15);
assertEquals(15, res.size());
for (int i = 0; i < 15; i++) {
assertEquals(discs[i + 115], res.get(i));
}
res = query.paginate(6).fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 130], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 136], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 142], res.get(i));
}
res = query.previousPage().fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 136], res.get(i));
}
res = query.offset(10).fetch(10);
assertEquals(10, res.size());
for (int i = 0; i < 10; i++) {
assertEquals(discs[i + 146], res.get(i));
}
try {
res = query.nextPage().fetch();
} catch (SienaException ex) {
res = query.paginate(8).fetch();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i + 156], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i + 164], res.get(i));
}
}
}
Aggregations