Search in sources :

Example 26 with TransactionAccountTo

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionSaveBatchFailure.

public void testTransactionSaveBatchFailure() {
    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);
            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 27 with TransactionAccountTo

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionInsert.

public void testTransactionInsert() {
    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);
            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)

Example 28 with TransactionAccountTo

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionDeleteFailure.

public void testTransactionDeleteFailure() {
    if (supportsTransaction()) {
        TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
        TransactionAccountTo accTo = new TransactionAccountTo(100L);
        pm.insert(accFrom, accTo);
        try {
            pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
            pm.delete(accFrom);
            pm.delete(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(100L == accToAfter.amount);
    }
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 29 with TransactionAccountTo

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionUpdateBatch.

public void testTransactionUpdateBatch() {
    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);
            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 30 with TransactionAccountTo

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionDeleteBatchFailure.

public void testTransactionDeleteBatchFailure() {
    if (supportsTransaction()) {
        TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
        TransactionAccountTo accTo = new TransactionAccountTo(100L);
        pm.insert(accFrom, accTo);
        try {
            pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
            pm.delete(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(100L == accToAfter.amount);
    }
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Aggregations

SienaException (siena.SienaException)34 TransactionAccountFrom (siena.base.test.model.TransactionAccountFrom)34 TransactionAccountTo (siena.base.test.model.TransactionAccountTo)34 TransactionAccountFromModel (siena.base.test.model.TransactionAccountFromModel)2 TransactionAccountToModel (siena.base.test.model.TransactionAccountToModel)2