/** * Executes the query and returns the result as a list iterator; make sure to close it to close the underlying * cursor. The cursor is closed once the iterator is fully iterated through. */ public CloseableListIterator<T> listIterator() { return listLazyUncached().listIteratorAutoClose(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#listLazyUncached() listLazyUncached()}; see * {@link Query#listLazyUncached()} for details. To execute a query more than once, you should build the query and * keep the {@link Query} object for efficiency reasons. */ public LazyList<T> listLazyUncached() { return build().listLazyUncached(); }
@Override public void call(Subscriber<? super T> subscriber) { try { LazyList<T> lazyList = query.forCurrentThread().listLazyUncached(); try { for (T entity : lazyList) { if (subscriber.isUnsubscribed()) { break; } subscriber.onNext(entity); } } finally { lazyList.close(); } if (!subscriber.isUnsubscribed()) { subscriber.onCompleted(); } } catch (Throwable e) { Exceptions.throwIfFatal(e); subscriber.onError(e); } } });
public void testSublistUncached() { ArrayList<TestEntity> list = insert(10); LazyList<TestEntity> listLazy = dao.queryBuilder().orderAsc(Properties.SimpleInteger).build().listLazyUncached(); try { assertIds(list.subList(2,7), listLazy.subList(2,7)); } catch (DaoException e) { assertEquals("This operation only works with cached lazy lists", e.getMessage()); } }
public void testIteratorUncached() { ArrayList<TestEntity> list = insert(100); LazyList<TestEntity> listLazy = dao.queryBuilder().orderAsc(Properties.SimpleInteger).build() .listLazyUncached(); testIterator(list, listLazy, true); assertFalse(listLazy.isClosed()); listLazy.close(); }
public void testGetAll100Uncached() { ArrayList<TestEntity> list = insert(100); LazyList<TestEntity> listLazy = dao.queryBuilder().orderAsc(Properties.SimpleInteger).build() .listLazyUncached(); assertIds(list, listLazy); assertFalse(listLazy.isClosed()); listLazy.close(); }
public void testAutoClose() { insert(10); LazyList<TestEntity> lazyList = dao.queryBuilder().build().listLazyUncached(); CloseableListIterator<TestEntity> iterator = lazyList.listIteratorAutoClose(); while (iterator.hasNext()) { assertFalse(lazyList.isClosed()); iterator.next(); } assertTrue(lazyList.isClosed()); }
public void testGetForCurrentThread_TwoThreads() throws InterruptedException { insert(3); createQueryFromOtherThread(); Query<TestEntity> query = queryFromOtherThread.forCurrentThread(); assertNotSame(queryFromOtherThread, query); query.setLimit(10); query.setOffset(0); assertEquals(getSimpleInteger(1), (int) query.uniqueOrThrow().getSimpleInteger()); int expected = getSimpleInteger(2); query.setParameter(0, expected); assertEquals(expected, (int) query.list().get(0).getSimpleInteger()); assertEquals(expected, (int) query.listLazy().get(0).getSimpleInteger()); assertEquals(expected, (int) query.listLazyUncached().get(0).getSimpleInteger()); assertEquals(expected, (int) query.unique().getSimpleInteger()); assertEquals(expected, (int) query.uniqueOrThrow().getSimpleInteger()); }
public void testUncached() { insert(1); LazyList<TestEntity> listLazy = dao.queryBuilder().build().listLazyUncached(); assertFalse(listLazy.isEmpty()); assertFalse(listLazy.isClosed()); TestEntity entity1 = listLazy.get(0); TestEntity entity2 = listLazy.get(0); assertEquals(entity1.getId(), entity2.getId()); if (identityScopeForDao == null) { assertNotSame(entity1, entity2); } else { assertSame(entity1, entity2); } assertFalse(listLazy.isClosed()); try { listLazy.loadRemaining(); fail("Not empty"); } catch (DaoException expected) { // Expected, OK } listLazy.close(); assertTrue(listLazy.isClosed()); }
queryFromOtherThread.listLazyUncached(); fail("Did not throw"); } catch (DaoException expected) {
/** * Executes the query and returns the result as a list iterator; make sure to close it to close the underlying * cursor. The cursor is closed once the iterator is fully iterated through. */ public CloseableListIterator<T> listIterator() { return listLazyUncached().listIteratorAutoClose(); }
/** * Shorthand for {@link QueryBuilder#build() build()}.{@link Query#listLazyUncached() listLazyUncached()}; see * {@link Query#listLazyUncached()} for details. To execute a query more than once, you should build the query and * keep the {@link Query} object for efficiency reasons. */ public LazyList<T> listLazyUncached() { return build().listLazyUncached(); }
@Override public void call(Subscriber<? super T> subscriber) { try { LazyList<T> lazyList = query.forCurrentThread().listLazyUncached(); try { for (T entity : lazyList) { if (subscriber.isUnsubscribed()) { break; } subscriber.onNext(entity); } } finally { lazyList.close(); } if (!subscriber.isUnsubscribed()) { subscriber.onCompleted(); } } catch (Throwable e) { Exceptions.throwIfFatal(e); subscriber.onError(e); } } });