01: package net.sourceforge.jaxor.impl;
02:
03: import net.sourceforge.jaxor.MetaRow;
04: import net.sourceforge.jaxor.api.EntityInterface;
05: import net.sourceforge.jaxor.api.EntityResultSet;
06: import net.sourceforge.jaxor.api.JaxorContext;
07: import net.sourceforge.jaxor.util.SystemException;
08:
09: import java.sql.ResultSet;
10: import java.sql.SQLException;
11:
12: /*
13: * User: Mike
14: * Date: Aug 18, 2003
15: * Time: 7:24:47 PM
16: */
17:
18: public class EntityResultSetImpl implements EntityResultSet {
19:
20: private final ResultSet _rs;
21: private final JaxorContext _context;
22: private final MetaRow _meta;
23:
24: private long _count = 0;
25:
26: public EntityResultSetImpl(ResultSet rs, JaxorContext context,
27: MetaRow meta) {
28: _rs = rs;
29: _context = context;
30: _meta = meta;
31: }
32:
33: public boolean hasNext() {
34: try {
35: return _rs.next();
36: } catch (SQLException e) {
37: throw new SystemException(e);
38: }
39: }
40:
41: public ResultSet getResultSet() {
42: return _rs;
43: }
44:
45: public EntityInterface next() {
46: _count++;
47: return load(_rs);
48: }
49:
50: public long count() {
51: return _count;
52: }
53:
54: public void close() {
55: try {
56: if (_rs != null)
57: _rs.close();
58: } catch (SQLException e) {
59: e.printStackTrace();
60: }
61: }
62:
63: public EntityInterface load(ResultSet rs) {
64: return _context.load(rs, _meta);
65: }
66:
67: }
|