use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testLimitStatelessIter.
public void testLimitStatelessIter() {
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).stateless().order("name");
Iterable<DiscoveryStringId> iter = query.limit(50).iter();
Iterator<DiscoveryStringId> it = iter.iterator();
int i = 0;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
iter = query.limit(50).iter();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
iter = query.iter(50);
it = iter.iterator();
i = 0;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
iter = query.paginate(50).iter();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testFetchPaginateStatelessTwiceKeys.
public void testFetchPaginateStatelessTwiceKeys() {
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).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].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(7, res.size());
for (int i = 0; i < 7; i++) {
assertEquals(discs[i + 8].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 testOffsetLimitStatelessPaginateKeys.
public void testOffsetLimitStatelessPaginateKeys() {
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).order("name");
List<DiscoveryStringId> res = query.paginate(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.limit(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(50).fetchKeys();
assertEquals(100, res.size());
for (int i = 0; i < 100; i++) {
assertEquals(discs[i + 50].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(50).limit(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].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 testOffsetLimitStatefulPaginateKeys.
public void testOffsetLimitStatefulPaginateKeys() {
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.paginate(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.limit(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 150].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(50).limit(25).fetchKeys();
assertEquals(25, res.size());
for (int i = 0; i < 25; i++) {
assertEquals(discs[i + 250].name, res.get(i).name);
assertTrue(res.get(i).isOnlyIdFilled());
}
try {
res = query.previousPage().fetch();
} catch (SienaException ex) {
return;
}
fail();
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testIterPerPageStateless3.
public void testIterPerPageStateless3() {
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).order("name");
Iterable<DiscoveryStringId> iter = query.offset(25).iterPerPage(50);
Iterator<DiscoveryStringId> it = iter.iterator();
int i = 25;
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
assertEquals(500, i);
}
Aggregations