01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.db.orm;
04:
05: import jodd.db.orm.mapper.ResultSetMapper;
06:
07: import java.util.Iterator;
08:
09: /**
10: * Internal database iterator.
11: * @see jodd.db.orm.DbListOneIterator
12: */
13: class DbListIterator implements Iterator<Object[]> {
14:
15: protected DbOrmQuery query;
16: protected ResultSetMapper resultSetMapper;
17: protected boolean closeOnEnd;
18: protected Class[] types;
19: protected boolean one;
20:
21: // ---------------------------------------------------------------- ctors
22:
23: DbListIterator(DbOrmQuery query, Class[] types) {
24: this (query, types, true);
25: }
26:
27: DbListIterator(DbOrmQuery query, Class[] types, boolean closeOnEnd) {
28: this .query = query;
29: this .resultSetMapper = query.buildResultSetMapper();
30: this .types = types;
31: this .closeOnEnd = closeOnEnd;
32: }
33:
34: // ---------------------------------------------------------------- iterate
35:
36: public void remove() {
37: throw new UnsupportedOperationException(
38: "Removing is not supported.");
39: }
40:
41: public boolean hasNext() {
42: if (resultSetMapper.next() == true) {
43: return true;
44: }
45: if (closeOnEnd == true) {
46: query.close();
47: } else {
48: query.close(resultSetMapper.getResultSet());
49: }
50: return false;
51: }
52:
53: public Object[] next() {
54: return resultSetMapper.parseObjects(types);
55: }
56:
57: }
|