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 for single type.
11: */
12: class DbListOneIterator<T> implements Iterator<T> {
13:
14: protected DbOrmQuery query;
15: protected ResultSetMapper resultSetMapper;
16: protected boolean closeOnEnd;
17: protected Class type;
18: protected boolean one;
19:
20: // ---------------------------------------------------------------- ctors
21:
22: DbListOneIterator(DbOrmQuery query, Class<T> type) {
23: this (query, type, true);
24: }
25:
26: DbListOneIterator(DbOrmQuery query, Class<T> type,
27: boolean closeOnEnd) {
28: this .query = query;
29: this .resultSetMapper = query.buildResultSetMapper();
30: this .type = type;
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: @SuppressWarnings({"unchecked"})
54: public T next() {
55: return (T) resultSetMapper.parseOneObject(type);
56: }
57:
58: }
|