Search in sources :

Example 46 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testLimitStatelessKeys.

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

Example 47 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetStatefulIter.

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

Example 48 with DiscoveryStringId

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

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testFetchPaginateStatelessTwice.

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

Example 49 with DiscoveryStringId

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

the class BaseTestNoAutoInc_5_PAGINATE method testFetchKeysPaginateStatefulPreviousPageFromScratch.

public void testFetchKeysPaginateStatefulPreviousPageFromScratch() {
    DiscoveryStringId[] discs = new DiscoveryStringId[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%02d", i), StringID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).paginate(5).stateful().order("name");
    List<DiscoveryStringId> res = query.previousPage().fetchKeys();
    assertEquals(0, res.size());
    res = query.previousPage().fetchKeys();
    assertEquals(0, res.size());
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 50 with DiscoveryStringId

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

the class BaseTestNoAutoInc_DEFAULT method testFetchLimitReal.

/*	
	@Deprecated
	public void testCountLimit() {
		assertEquals(1, pm.createQuery(PersonUUID.class).filter("n<", 3).count(1));
	}
*/
public void testFetchLimitReal() {
    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);
    assertNotNull(res);
    assertEquals(3, res.size());
    assertEquals(discs[0], res.get(0));
    assertEquals(discs[1], res.get(1));
    assertEquals(discs[2], res.get(2));
}
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