Search in sources :

Example 96 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginate2Iter.

public void testOffsetLimitStatefulPaginate2Iter() {
    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.limit(50).offset(12).iter();
    Iterator<DiscoveryStringId> it = iter.iterator();
    int i = 12;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(62, i);
    iter = query.offset(13).limit(30).iter();
    it = iter.iterator();
    i = 75;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(105, i);
    iter = query.offset(10).limit(30).iter(15);
    it = iter.iterator();
    i = 115;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(130, i);
    iter = query.paginate(6).iter();
    it = iter.iterator();
    i = 130;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(136, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 136;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(142, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 142;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(148, i);
    iter = query.previousPage().iter();
    it = iter.iterator();
    i = 136;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(142, i);
    iter = query.offset(10).iter(10);
    it = iter.iterator();
    i = 146;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(156, i);
    try {
        iter = query.nextPage().iter();
    } catch (SienaException ex) {
        iter = query.paginate(8).iter();
        it = iter.iterator();
        i = 156;
        while (it.hasNext()) {
            DiscoveryStringId disc = it.next();
            assertEquals(discs[i++], disc);
        }
        assertEquals(164, i);
        iter = query.nextPage().iter();
        it = iter.iterator();
        i = 164;
        while (it.hasNext()) {
            DiscoveryStringId disc = it.next();
            assertEquals(discs[i++], disc);
        }
        assertEquals(172, i);
        return;
    }
    fail();
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 97 with DiscoveryStringId

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

the class BaseTestNoAutoInc_DEFAULT method testQueryDelete.

public void testQueryDelete() {
    DiscoveryStringId radioactivity = new DiscoveryStringId("Radioactivity", StringID_CURIE);
    DiscoveryStringId relativity = new DiscoveryStringId("Relativity", StringID_EINSTEIN);
    DiscoveryStringId teslaCoil = new DiscoveryStringId("Tesla Coil", StringID_TESLA);
    pm.insert(radioactivity);
    pm.insert(relativity);
    pm.insert(teslaCoil);
    int n = pm.createQuery(DiscoveryStringId.class).delete();
    assertEquals(3, n);
    List<DiscoveryStringId> res = pm.createQuery(DiscoveryStringId.class).fetch();
    assertEquals(0, res.size());
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 98 with DiscoveryStringId

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

the class BaseTestNoAutoInc_DEFAULT method testQueryDeleteFiltered.

public void testQueryDeleteFiltered() {
    DiscoveryStringId radioactivity = new DiscoveryStringId("Radioactivity", StringID_CURIE);
    DiscoveryStringId relativity = new DiscoveryStringId("Relativity", StringID_EINSTEIN);
    DiscoveryStringId foo = new DiscoveryStringId("Foo", StringID_EINSTEIN);
    DiscoveryStringId teslaCoil = new DiscoveryStringId("Tesla Coil", StringID_TESLA);
    pm.insert(radioactivity);
    pm.insert(relativity);
    pm.insert(foo);
    pm.insert(teslaCoil);
    int n = pm.createQuery(DiscoveryStringId.class).filter("discoverer", StringID_EINSTEIN).delete();
    assertEquals(2, n);
    List<DiscoveryStringId> res = pm.createQuery(DiscoveryStringId.class).order("name").fetch();
    assertEquals(2, res.size());
    assertEquals(radioactivity, res.get(0));
    assertEquals(teslaCoil, res.get(1));
}
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