Search in sources :

Example 61 with DiscoveryStringId

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

the class BaseTestNoAutoInc_3_ITER method testIterLotsOfEntitiesStateful.

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

Example 62 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testIterPerPageStateful.

public void testIterPerPageStateful() {
    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);
    int i = 0;
    for (DiscoveryStringId disc : iter) {
        assertEquals(discs[i++], disc);
    }
    assertEquals(500, i);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 63 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testLimitStateless.

public void testLimitStateless() {
    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");
    List<DiscoveryStringId> res = query.limit(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.limit(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.paginate(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 64 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginate2Keys.

public void testOffsetLimitStatefulPaginate2Keys() {
    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).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 12].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(13).limit(30).fetchKeys();
    assertEquals(30, res.size());
    for (int i = 0; i < 30; i++) {
        assertEquals(discs[i + 75].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(10).limit(30).fetchKeys(15);
    assertEquals(15, res.size());
    for (int i = 0; i < 15; i++) {
        assertEquals(discs[i + 115].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.paginate(6).fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 130].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 136].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 142].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.previousPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 136].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(10).fetchKeys(10);
    assertEquals(10, res.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(discs[i + 146].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    try {
        res = query.nextPage().fetchKeys();
    } catch (SienaException ex) {
        res = query.paginate(8).fetchKeys();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 156].name, res.get(i).name);
            assertTrue(res.get(i).isOnlyIdFilled());
        }
        res = query.nextPage().fetchKeys();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 164].name, res.get(i).name);
            assertTrue(res.get(i).isOnlyIdFilled());
        }
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 65 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatelessPaginate2Keys.

public void testOffsetLimitStatelessPaginate2Keys() {
    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");
    List<DiscoveryStringId> res = query.limit(50).offset(12).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 12].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(13).limit(30).fetchKeys();
    assertEquals(30, res.size());
    for (int i = 0; i < 30; i++) {
        assertEquals(discs[i + 13].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(10).limit(30).fetchKeys(15);
    assertEquals(15, res.size());
    for (int i = 0; i < 15; i++) {
        assertEquals(discs[i + 10].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.paginate(6).fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 6].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 12].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.previousPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 6].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(10).fetchKeys(10);
    assertEquals(10, res.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(discs[i + 10].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    try {
        res = query.nextPage().fetchKeys();
    } catch (SienaException ex) {
        res = query.paginate(8).fetch();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i].name, res.get(i).name);
        }
        res = query.nextPage().fetchKeys();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 8].name, res.get(i).name);
        }
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Aggregations

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