use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_7_BATCH method testBatchGetList.
public void testBatchGetList() {
DiscoveryStringId[] discs = new DiscoveryStringId[100];
for (int i = 0; i < 100; i++) {
discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
}
pm.insert((Object[]) discs);
List<DiscoveryStringId> discs2Get = new ArrayList<DiscoveryStringId>();
for (int i = 0; i < 100; i++) {
DiscoveryStringId disc = new DiscoveryStringId();
disc.name = discs[i].name;
discs2Get.add(disc);
}
int nb = pm.get(discs2Get);
assertEquals(nb, discs.length);
int i = 0;
for (DiscoveryStringId disc : discs2Get) {
assertEquals(discs[i++], disc);
}
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetStateful.
public void testOffsetStateful() {
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).fetch();
assertEquals(100, res.size());
for (int i = 0; i < 100; 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 testLimitStatefulIter.
public void testLimitStatefulIter() {
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.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.iter(50);
it = iter.iterator();
i = 50;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(100, i);
iter = query.paginate(50).iter(25);
it = iter.iterator();
i = 100;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(150, i);
}
use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.
the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginate.
public void testOffsetLimitStatefulPaginate() {
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).fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50], res.get(i));
}
res = query.limit(50).fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50], res.get(i));
}
res = query.offset(50).fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 150], res.get(i));
}
res = query.offset(50).limit(25).fetch();
assertEquals(25, res.size());
for (int i = 0; i < 25; i++) {
assertEquals(discs[i + 250], res.get(i));
}
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 testOffsetLimitStatefulPaginateIter.
public void testOffsetLimitStatefulPaginateIter() {
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).stateful().order("name");
Iterable<DiscoveryStringId> iter = query.paginate(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.nextPage().iter();
it = iter.iterator();
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(100, i);
iter = query.limit(50).iter();
it = iter.iterator();
i = 50;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(100, i);
iter = query.offset(50).iter();
it = iter.iterator();
i = 150;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(200, i);
iter = query.offset(50).limit(25).iter();
it = iter.iterator();
i = 250;
while (it.hasNext()) {
DiscoveryStringId disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(275, i);
try {
iter = query.previousPage().iter();
} catch (SienaException ex) {
return;
}
fail();
}
Aggregations