Search in sources :

Example 41 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginateIter.

public void testOffsetLimitStatefulPaginateIter() {
    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.paginate(50).iter();
    Iterator<DiscoveryStringId> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    iter = query.limit(50).iter();
    it = iter.iterator();
    i = 50;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    iter = query.offset(50).iter();
    it = iter.iterator();
    i = 150;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(200, i);
    iter = query.offset(50).limit(25).iter();
    it = iter.iterator();
    i = 250;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(275, i);
    try {
        iter = query.previousPage().iter();
    } catch (SienaException ex) {
        return;
    }
    fail();
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 42 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginate.

public void testOffsetLimitStatefulPaginate() {
    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.paginate(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.limit(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.offset(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 150], res.get(i));
    }
    res = query.offset(50).limit(25).fetch();
    assertEquals(25, res.size());
    for (int i = 0; i < 25; i++) {
        assertEquals(discs[i + 250], res.get(i));
    }
    try {
        res = query.previousPage().fetch();
    } catch (SienaException ex) {
        return;
    }
    fail();
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 43 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_9_FETCH_ITER_PAGINATE method testOffsetLimitStatefulPaginateKeys.

public void testOffsetLimitStatefulPaginateKeys() {
    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.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());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50].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 + 50].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(50).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 150].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(50).limit(25).fetchKeys();
    assertEquals(25, res.size());
    for (int i = 0; i < 25; i++) {
        assertEquals(discs[i + 250].name, res.get(i).name);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    try {
        res = query.previousPage().fetch();
    } catch (SienaException ex) {
        return;
    }
    fail();
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId) SienaException(siena.SienaException)

Example 44 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTest method testTransactionUpdate.

public void testTransactionUpdate() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    TransactionAccountTo accTo = new TransactionAccountTo(1000L);
    pm.insert(accFrom, accTo);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount -= 100L;
        pm.update(accFrom);
        accTo.amount += 100L;
        pm.update(accTo);
        pm.commitTransaction();
    } catch (SienaException e) {
        pm.rollbackTransaction();
        fail();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(900L == accFromAfter.amount);
    TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
    assertTrue(1100L == accToAfter.amount);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 45 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTest method testTransactionInsert.

public void testTransactionInsert() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    TransactionAccountTo accTo = new TransactionAccountTo(1000L);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount = 1000L;
        accTo.amount = 100L;
        pm.insert(accFrom);
        pm.insert(accTo);
        pm.commitTransaction();
    } catch (SienaException e) {
        pm.rollbackTransaction();
        fail();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(1000L == accFromAfter.amount);
    TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
    assertTrue(100L == accToAfter.amount);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Aggregations

SienaException (siena.SienaException)214 Field (java.lang.reflect.Field)65 TransactionAccountFrom (siena.base.test.model.TransactionAccountFrom)52 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)40 SQLException (java.sql.SQLException)38 TransactionAccountTo (siena.base.test.model.TransactionAccountTo)34 SienaRestrictedApiException (siena.SienaRestrictedApiException)33 PreparedStatement (java.sql.PreparedStatement)25 ClassInfo (siena.ClassInfo)21 HashMap (java.util.HashMap)19 List (java.util.List)18 Discovery (siena.base.test.model.Discovery)18 Entity (com.google.appengine.api.datastore.Entity)15 Key (com.google.appengine.api.datastore.Key)14 ResultSet (java.sql.ResultSet)14 Id (siena.Id)14 AmazonClientException (com.amazonaws.AmazonClientException)12 Collection (java.util.Collection)10 DiscoveryStringId (siena.base.test.model.DiscoveryStringId)9