Search in sources :

Example 36 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionInsertBatch.

public void testTransactionInsertBatch() {
    if (supportsTransaction()) {
        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, 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)

Example 37 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionSaveBatch.

public void testTransactionSaveBatch() {
    if (supportsTransaction()) {
        TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
        TransactionAccountTo accTo = new TransactionAccountTo(1000L);
        pm.insert(accFrom, accTo);
        try {
            pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
            accFrom.amount -= 100L;
            accTo.amount += 100L;
            pm.save(accFrom, 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 38 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionUpdateBatchFailure.

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

Example 39 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionDeleteBatch.

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

Example 40 with SienaException

use of siena.SienaException in project siena by mandubian.

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionInsertFailure.

public void testTransactionInsertFailure() {
    if (supportsTransaction()) {
        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, accTo);
            throw new SienaException("test");
        } catch (SienaException e) {
            pm.rollbackTransaction();
        } finally {
            pm.closeConnection();
        }
        TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
        assertNull(accFromAfter);
        TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
        assertNull(accToAfter);
    }
}
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