Search in sources :

Example 91 with DiscoveryStringId

use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatelessKeys.

public void testOffsetLimitStatelessKeys() {
    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.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());
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 92 with DiscoveryStringId

use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testFetchPaginateStatelessTwiceIter.

public void testFetchPaginateStatelessTwiceIter() {
    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");
    Iterable<DiscoveryStringId> iter = query.iter();
    Iterator<DiscoveryStringId> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(5, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 5;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(10, i);
    iter = query.paginate(8).iter();
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(8, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 8;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(15, i);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 93 with DiscoveryStringId

use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetStatelessKeys.

public void testOffsetStatelessKeys() {
    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.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());
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 94 with DiscoveryStringId

use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatelessPaginateIter.

public void testOffsetLimitStatelessPaginateIter() {
    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");
    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 = 0;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    iter = query.offset(50).iter();
    it = iter.iterator();
    i = 50;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(150, i);
    iter = query.offset(50).limit(50).iter();
    it = iter.iterator();
    i = 50;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 95 with DiscoveryStringId

use of siena.base.test.model.DiscoveryStringId in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatelessIter.

public void testOffsetLimitStatelessIter() {
    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");
    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);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Aggregations

DiscoveryStringId (siena.base.test.model.DiscoveryStringId)98 SienaException (siena.SienaException)9 ArrayList (java.util.ArrayList)6