use of siena.SienaException in project siena by mandubian.
the class BaseTest method testTransactionUpdateBatchFailure.
public void testTransactionUpdateBatchFailure() {
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);
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testTransactionSaveBatch.
public void testTransactionSaveBatch() {
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);
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest 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);
Query<Discovery> query = pm.createQuery(Discovery.class).order("id").stateful();
List<Discovery> 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();
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testTransactionUpdateFailure.
public void testTransactionUpdateFailure() {
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);
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);
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testTransactionSave.
public void testTransactionSave() {
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.save(accFrom);
accTo.amount += 100L;
pm.save(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);
}
Aggregations