use of siena.SienaException in project siena by mandubian.
the class BaseTest method testOffsetLimitStatefulPaginate2Iter.
public void testOffsetLimitStatefulPaginate2Iter() {
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).stateful().order("id");
Iterable<Discovery> iter = query.limit(50).offset(12).iter();
Iterator<Discovery> it = iter.iterator();
int i = 12;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(62, i);
iter = query.offset(13).limit(30).iter();
it = iter.iterator();
i = 75;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(105, i);
iter = query.offset(10).limit(30).iter(15);
it = iter.iterator();
i = 115;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(130, i);
iter = query.paginate(6).iter();
it = iter.iterator();
i = 130;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(136, i);
iter = query.nextPage().iter();
it = iter.iterator();
i = 136;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(142, i);
iter = query.nextPage().iter();
it = iter.iterator();
i = 142;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(148, i);
iter = query.previousPage().iter();
it = iter.iterator();
i = 136;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(142, i);
iter = query.offset(10).iter(10);
it = iter.iterator();
i = 146;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(156, i);
try {
iter = query.nextPage().iter();
} catch (SienaException ex) {
iter = query.paginate(8).iter();
it = iter.iterator();
i = 156;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(164, i);
iter = query.nextPage().iter();
it = iter.iterator();
i = 164;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(172, i);
return;
}
fail();
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testOffsetLimitStatefulPaginateKeys.
public void testOffsetLimitStatefulPaginateKeys() {
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).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 50].id, res.get(i).id);
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].id, res.get(i).id);
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].id, res.get(i).id);
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].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
try {
res = query.previousPage().fetch();
} catch (SienaException ex) {
return;
}
fail();
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testOffsetLimitStatefulPaginate2Keys.
public void testOffsetLimitStatefulPaginate2Keys() {
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.limit(50).offset(12).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 12].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(13).limit(30).fetchKeys();
assertEquals(30, res.size());
for (int i = 0; i < 30; i++) {
assertEquals(discs[i + 75].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(10).limit(30).fetchKeys(15);
assertEquals(15, res.size());
for (int i = 0; i < 15; i++) {
assertEquals(discs[i + 115].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.paginate(6).fetchKeys();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 130].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 136].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 142].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.previousPage().fetchKeys();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 136].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(10).fetchKeys(10);
assertEquals(10, res.size());
for (int i = 0; i < 10; i++) {
assertEquals(discs[i + 146].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
try {
res = query.nextPage().fetchKeys();
} catch (SienaException ex) {
res = query.paginate(8).fetchKeys();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i + 156].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.nextPage().fetchKeys();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i + 164].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
}
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testOffsetLimitStatelessPaginate2.
public void testOffsetLimitStatelessPaginate2() {
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");
List<Discovery> res = query.limit(50).offset(12).fetch();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 12], res.get(i));
}
res = query.offset(13).limit(30).fetch();
assertEquals(30, res.size());
for (int i = 0; i < 30; i++) {
assertEquals(discs[i + 13], res.get(i));
}
res = query.offset(10).limit(30).fetch(15);
assertEquals(15, res.size());
for (int i = 0; i < 15; i++) {
assertEquals(discs[i + 10], res.get(i));
}
res = query.paginate(6).fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 6], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 12], res.get(i));
}
res = query.previousPage().fetch();
assertEquals(6, res.size());
for (int i = 0; i < 6; i++) {
assertEquals(discs[i + 6], res.get(i));
}
res = query.offset(10).fetch(10);
assertEquals(10, res.size());
for (int i = 0; i < 10; i++) {
assertEquals(discs[i + 10], res.get(i));
}
try {
res = query.nextPage().fetch();
} catch (SienaException ex) {
res = query.paginate(8).fetch();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i], res.get(i));
}
res = query.nextPage().fetch();
assertEquals(8, res.size());
for (int i = 0; i < 8; i++) {
assertEquals(discs[i + 8], res.get(i));
}
return;
}
fail();
}
use of siena.SienaException in project siena by mandubian.
the class BaseTest method testTransactionDeleteFailure.
public void testTransactionDeleteFailure() {
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);
}
Aggregations