Search in sources :

Example 56 with DiscoveryStringId

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

the class BaseTestNoAutoInc_7_BATCH method testBatchDelete.

public void testBatchDelete() {
    Object[] discs = new DiscoveryStringId[100];
    for (int i = 0; i < 100; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
    }
    pm.insert(discs);
    List<DiscoveryStringId> res = pm.createQuery(DiscoveryStringId.class).fetch();
    assertEquals(discs.length, res.size());
    int nb = pm.delete(discs);
    assertEquals(discs.length, nb);
    res = pm.createQuery(DiscoveryStringId.class).fetch();
    assertEquals(0, res.size());
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 57 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatelessPaginate2.

public void testOffsetLimitStatelessPaginate2() {
    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).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 + 13], 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 + 10], res.get(i));
    }
    res = query.paginate(6).fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 6], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 12], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 6], res.get(i));
    }
    res = query.offset(10).fetch(10);
    assertEquals(10, res.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(discs[i + 10], 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], res.get(i));
        }
        res = query.nextPage().fetch();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 8], res.get(i));
        }
        return;
    }
    fail();
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 58 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetStatefulKeys.

public void testOffsetStatefulKeys() {
    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).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 59 with DiscoveryStringId

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

the class BaseTestNoAutoInc_2_FETCH method testFetchLimitOffsetReal.

public void testFetchLimitOffsetReal() {
    DiscoveryStringId[] discs = new DiscoveryStringId[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + i, StringID_CURIE);
        pm.insert(discs[i]);
    }
    List<DiscoveryStringId> res = pm.createQuery(DiscoveryStringId.class).order("name").fetch(3, 5);
    assertNotNull(res);
    assertEquals(3, res.size());
    assertEquals(discs[5], res.get(0));
    assertEquals(discs[6], res.get(1));
    assertEquals(discs[7], res.get(2));
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 60 with DiscoveryStringId

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

the class BaseTestNoAutoInc_2_FETCH method testFetchLotsOfEntitiesStatefulMixed2.

public void testFetchLotsOfEntitiesStatefulMixed2() {
    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.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.paginate(50).fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], res.get(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