本文整理了Java中com.j256.ormlite.dao.Dao.iterator()
方法的一些代码示例,展示了Dao.iterator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.iterator()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:iterator
[英]This satisfies the Iterable interface for the class and allows you to iterate through the objects in the table using SQL. You can use code similar to the following:
for (Account account : accountDao) { ... }
WARNING: because the Iterator#hasNext(), Iterator#next(), etc. methods can only throw RuntimeException, the code has to wrap any SQLException with IllegalStateException. Make sure to catch IllegalStateException and look for a SQLException cause.
WARNING: The underlying results object will only be closed if you page all the way to the end of the iterator using the for() loop or if you call CloseableIterator#close() directly. You can also call the #closeLastIterator() if you are not iterating across this DAO in multiple threads.
NOTE: With this iterator you can only move forward through the object collection. See the #iterator(int) method to create a cursor that can go both directions.
[中]这满足了类的Iterable接口,并允许您使用SQL迭代表中的对象。您可以使用类似于以下内容的代码:
for (Account account : accountDao) { ... }
警告:由于迭代器#hasNext()、迭代器#next()等方法只能抛出RuntimeException,因此代码必须用IllegalStateException包装任何SQLException。确保捕获IllegalStateException并查找SQLException原因。
警告:只有使用for()循环将页面一直分页到迭代器的末尾,或者直接调用CloseableIterator#close()时,基础结果对象才会关闭。如果没有在多个线程中迭代此DAO,也可以调用#closeLastIterator()。
注意:使用此迭代器,您只能在对象集合中前进。请参阅#迭代器(int)方法来创建可以双向移动的游标。
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#iterator(int)
*/
@Override
public CloseableIterator<T> iterator(int resultFlags) {
return dao.iterator(resultFlags);
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#iterator()
*/
@Override
public CloseableIterator<T> iterator() {
return dao.iterator();
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#iterator()
*/
@Override
public CloseableIterator<T> iterator() {
return dao.iterator();
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#iterator(int)
*/
@Override
public CloseableIterator<T> iterator(int resultFlags) {
return dao.iterator(resultFlags);
}
代码示例来源:origin: j256/ormlite-core
/**
* A short cut to {@link Dao#iterator(PreparedQuery)}.
*/
public CloseableIterator<T> iterator() throws SQLException {
return dao.iterator(prepare());
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#iterator(PreparedQuery)
*/
@Override
public CloseableIterator<T> iterator(PreparedQuery<T> preparedQuery) {
try {
return dao.iterator(preparedQuery);
} catch (SQLException e) {
logMessage(e, "iterator threw exception on: " + preparedQuery);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#iterator(PreparedQuery, int)
*/
@Override
public CloseableIterator<T> iterator(PreparedQuery<T> preparedQuery, int resultFlags) {
try {
return dao.iterator(preparedQuery, resultFlags);
} catch (SQLException e) {
logMessage(e, "iterator threw exception on: " + preparedQuery);
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#iterator(PreparedQuery)
*/
@Override
public CloseableIterator<T> iterator(PreparedQuery<T> preparedQuery) {
try {
return dao.iterator(preparedQuery);
} catch (SQLException e) {
logMessage(e, "iterator threw exception on: " + preparedQuery);
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* A short cut to {@link Dao#iterator(PreparedQuery)}.
*/
public CloseableIterator<T> iterator() throws SQLException {
return dao.iterator(prepare());
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#iterator(PreparedQuery, int)
*/
@Override
public CloseableIterator<T> iterator(PreparedQuery<T> preparedQuery, int resultFlags) {
try {
return dao.iterator(preparedQuery, resultFlags);
} catch (SQLException e) {
logMessage(e, "iterator threw exception on: " + preparedQuery);
throw new RuntimeException(e);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = RuntimeException.class)
public void testIteratorThrow() throws Exception {
@SuppressWarnings("unchecked")
Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
expect(dao.iterator(null)).andThrow(new SQLException("Testing catch"));
replay(dao);
rtDao.iterator(null);
verify(dao);
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testIteratorNoResults() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
Iterator<Foo> iterator = fooDao.iterator();
assertFalse(iterator.hasNext());
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testRemoveAfterDone() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
Iterator<Foo> iterator = fooDao.iterator();
assertFalse(iterator.hasNext());
try {
iterator.remove();
fail("expected exception");
} catch (IllegalStateException e) {
// expected
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalStateException.class)
public void testIteratorRemoveNoNext() throws Exception {
Dao<Foo, Object> dao = createDao(Foo.class, true);
CloseableIterator<Foo> iterator = dao.iterator();
try {
iterator.remove();
} finally {
iterator.close();
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testHasNextAfterDone() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
CloseableIterator<Foo> iterator = fooDao.iterator();
try {
while (iterator.hasNext()) {
}
assertFalse(iterator.hasNext());
} finally {
iterator.close();
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testIteratorGetRawResults() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
assertEquals(1, dao.create(foo1));
assertEquals(1, dao.queryForAll().size());
@SuppressWarnings("unchecked")
SelectIterator<Foo, String> iterator = (SelectIterator<Foo, String>) dao.iterator();
DatabaseResults results = iterator.getRawResults();
assertTrue(results.next());
iterator.close();
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = IllegalStateException.class)
public void testIteratorThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.iterator();
} finally {
connectionSource.releaseConnection(conn);
}
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testIteratorPreparedThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
dao.iterator(dao.queryBuilder().prepare());
} finally {
connectionSource.releaseConnection(conn);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testIteratorLastClose() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
assertEquals(1, dao.create(foo1));
CloseableIterator<Foo> iterator = dao.iterator();
assertTrue(iterator.hasNext());
Foo foo3 = iterator.next();
assertEquals(foo1.id, foo3.id);
assertFalse(iterator.hasNext());
dao.closeLastIterator();
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testMultipleHasNext() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
assertEquals(1, dao.create(foo1));
CloseableIterator<Foo> iterator = dao.iterator();
assertTrue(iterator.hasNext());
assertTrue(iterator.hasNext());
assertTrue(iterator.hasNext());
iterator.moveToNext();
assertFalse(iterator.hasNext());
}
内容来源于网络,如有侵权,请联系作者删除!