Search in sources :

Example 71 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatelessPaginate2Iter.

public void testOffsetLimitStatelessPaginate2Iter() {
    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");
    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 = 13;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(43, i);
    iter = query.offset(10).limit(30).iter(15);
    it = iter.iterator();
    i = 10;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(25, i);
    iter = query.paginate(6).iter();
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(6, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 6;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(12, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 12;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(18, i);
    iter = query.previousPage().iter();
    it = iter.iterator();
    i = 6;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(12, i);
    iter = query.offset(10).iter(10);
    it = iter.iterator();
    i = 10;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(20, i);
    try {
        iter = query.nextPage().iter();
    } catch (SienaException ex) {
        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(16, i);
        return;
    }
    fail();
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 72 with DiscoveryStringId

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

the class BaseTestNoAutoInc_6_FETCH_ITER method testFetchIterLotsOfEntitiesStatefulMixed2.

public void testFetchIterLotsOfEntitiesStatefulMixed2() {
    DiscoveryStringId[] discs = new DiscoveryStringId[200];
    for (int i = 0; i < 200; 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));
    }
    Iterable<DiscoveryStringId> res2 = query.iter(50);
    Iterator<DiscoveryStringId> it2 = res2.iterator();
    int i = 50;
    while (it2.hasNext()) {
        DiscoveryStringId disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    res = query.fetch(50);
    assertEquals(50, res.size());
    for (i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res2 = query.iter(50);
    it2 = res2.iterator();
    i = 150;
    while (it2.hasNext()) {
        DiscoveryStringId disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(200, i);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 73 with DiscoveryStringId

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

the class BaseTestNoAutoInc_7_BATCH method testBatchUpdateList.

public void testBatchUpdateList() {
    List<DiscoveryStringId> discs = new ArrayList<DiscoveryStringId>();
    for (int i = 0; i < 100; i++) {
        discs.add(new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE));
    }
    int nb = pm.insert(discs);
    assertEquals(discs.size(), nb);
    List<DiscoveryStringId> res = pm.createQuery(DiscoveryStringId.class).fetch();
    assertEquals(discs.size(), res.size());
    for (DiscoveryStringId d : discs) {
        d.discoverer = StringID_EINSTEIN;
    }
    nb = pm.update(discs);
    assertEquals(discs.size(), nb);
    res = pm.createQuery(DiscoveryStringId.class).fetch();
    int i = 0;
    for (DiscoveryStringId disc : res) {
        assertEquals(discs.get(i++), disc);
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) ArrayList(java.util.ArrayList)

Example 74 with DiscoveryStringId

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

the class BaseTestNoAutoInc_7_BATCH method testBatchUpdate.

public void testBatchUpdate() {
    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());
    for (int i = 0; i < 100; i++) {
        ((DiscoveryStringId) discs[i]).discoverer = StringID_EINSTEIN;
    }
    int nb = pm.update(discs);
    assertEquals(discs.length, nb);
    res = pm.createQuery(DiscoveryStringId.class).fetch();
    int i = 0;
    for (DiscoveryStringId disc : res) {
        assertEquals(discs[i++], disc);
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 75 with DiscoveryStringId

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

the class BaseTestNoAutoInc_7_BATCH method testBatchDeleteByKeysLots.

public void testBatchDeleteByKeysLots() {
    List<DiscoveryStringId> discs = new ArrayList<DiscoveryStringId>();
    List<String> keys = new ArrayList<String>();
    for (int i = 0; i < 59; i++) {
        DiscoveryStringId disc = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
        discs.add(disc);
        keys.add(disc.name);
    }
    pm.insert(discs);
    int nb = pm.deleteByKeys(DiscoveryStringId.class, keys);
    assertEquals(discs.size(), nb);
    List<DiscoveryStringId> res = pm.createQuery(DiscoveryStringId.class).fetch();
    assertEquals(0, res.size());
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) ArrayList(java.util.ArrayList)

Aggregations

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