public void testThrowOutsideOwnerThread() throws InterruptedException { createQueryFromOtherThread(); try { queryFromOtherThread.count(); fail("Did not throw"); } catch (DaoException expected) { } try { queryFromOtherThread.setParameter(0, 42); fail("Did not throw"); } catch (DaoException expected) { } }
public void testCountQueryChangeParameter() { insert(3); String value = "not existing value"; CountQuery<TestEntity> query = dao.queryBuilder().where(Properties.SimpleString.eq(value)).buildCount(); assertEquals(0, query.count()); query.setParameter(0, getSimpleString(1)); assertEquals(1, query.count()); query.setParameter(0, getSimpleString(2)); assertEquals(1, query.count()); query.setParameter(0, "you won't find me either"); assertEquals(0, query.count()); }
public void testGetForCurrentThread_TwoThreads() throws InterruptedException { insert(3); createQueryFromOtherThread(); CountQuery<TestEntity> query = queryFromOtherThread.forCurrentThread(); assertNotSame(queryFromOtherThread, query); assertEquals(1, query.count()); query.setParameter(0, -10); assertEquals(0, query.count()); }
public void testGetForCurrentThread_ParametersAreReset() { insert(3); int value = getSimpleInteger(1); CountQuery<TestEntity> query = dao.queryBuilder().where(Properties.SimpleInteger.eq(value)).buildCount(); query.setParameter(0, value + 100); assertEquals(0, query.count()); query = query.forCurrentThread(); assertEquals(1, query.count()); }