Search in sources :

Example 21 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseAsyncTest method testOffsetLimitStatefulPaginateIter.

public void testOffsetLimitStatefulPaginateIter() {
    Discovery[] discs = new Discovery[300];
    for (int i = 0; i < 300; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).stateful().order("id");
    SienaFuture<Iterable<Discovery>> future = query.paginate(50).iter();
    Iterable<Discovery> iter = future.get();
    Iterator<Discovery> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    future = query.nextPage().iter();
    iter = future.get();
    it = iter.iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.limit(50).iter();
    iter = future.get();
    it = iter.iterator();
    i = 50;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.offset(50).iter();
    iter = future.get();
    it = iter.iterator();
    i = 150;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(200, i);
    future = query.offset(50).limit(25).iter();
    iter = future.get();
    it = iter.iterator();
    i = 250;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(275, i);
    try {
        future = query.previousPage().iter();
    } catch (SienaException ex) {
        return;
    }
    fail();
}
Also used : Discovery(siena.base.test.model.Discovery) SienaException(siena.SienaException)

Example 22 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseAsyncTest method testOffsetLimitStatefulPaginate.

public void testOffsetLimitStatefulPaginate() {
    Discovery[] discs = new Discovery[300];
    for (int i = 0; i < 300; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).order("id").stateful();
    SienaFuture<List<Discovery>> future = query.paginate(50).fetch();
    List<Discovery> res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    future = query.nextPage().fetch();
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    future = query.limit(50).fetch();
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    future = query.offset(50).fetch();
    res = future.get();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 150], res.get(i));
    }
    future = query.offset(50).limit(25).fetch();
    res = future.get();
    assertEquals(25, res.size());
    for (int i = 0; i < 25; i++) {
        assertEquals(discs[i + 250], res.get(i));
    }
    try {
        future = query.previousPage().fetch();
    } catch (SienaException ex) {
        return;
    }
    fail();
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List) SienaException(siena.SienaException)

Example 23 with SienaException

use of siena.SienaException in project siena by mandubian.

the class LifeCycleUtils method executeMethods.

public static void executeMethods(LifeCyclePhase lcp, ClassInfo ci, Object obj) {
    List<Method> methods = ci.getLifeCycleMethod(lcp);
    if (methods == null)
        return;
    try {
        for (Method m : methods) {
            // injects lifeCyclePhase if it is the FIRST param
            Class<?>[] params = m.getParameterTypes();
            boolean wasAccessible = true;
            if (!m.isAccessible()) {
                wasAccessible = false;
                m.setAccessible(true);
            }
            if (params != null && params.length != 0) {
                if (LifeCyclePhase.class.isAssignableFrom(params[0])) {
                    m.invoke(obj, lcp);
                }
            } else {
                m.invoke(obj);
            }
            if (!wasAccessible) {
                m.setAccessible(false);
            }
        }
    } catch (IllegalArgumentException e) {
        throw new SienaException(e);
    } catch (IllegalAccessException e) {
        throw new SienaException(e);
    } catch (InvocationTargetException e) {
        throw new SienaException(e);
    }
}
Also used : Method(java.lang.reflect.Method) SienaException(siena.SienaException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 with SienaException

use of siena.SienaException in project siena by mandubian.

the class GaeModelTest method testTransactionSaveFailure.

public void testTransactionSaveFailure() {
    TransactionAccountFromModel accFrom = new TransactionAccountFromModel(1000L);
    accFrom.insert();
    try {
        accFrom.getPersistenceManager().beginTransaction();
        accFrom.amount -= 100L;
        accFrom.save();
        throw new SienaException("test");
    } catch (SienaException e) {
        accFrom.getPersistenceManager().rollbackTransaction();
    } finally {
        accFrom.getPersistenceManager().closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(1000L == accFromAfter.amount);
}
Also used : TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException) TransactionAccountFromModel(siena.base.test.model.TransactionAccountFromModel)

Example 25 with SienaException

use of siena.SienaException in project siena by mandubian.

the class GaeTest method testTransactionUpdateBatchFailure.

public void testTransactionUpdateBatchFailure() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    pm.insert(accFrom);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount -= 100L;
        throw new SienaException("test");
    } catch (SienaException e) {
        pm.rollbackTransaction();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(1000L == accFromAfter.amount);
}
Also used : 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