01: /*
02: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: * All rights reserved.
04: *
05: *
06: */
07:
08: //=======================================================================
09: // Package
10: package com.hp.hpl.jena.db.impl;
11:
12: //=======================================================================
13: // Imports
14: import java.util.ArrayList;
15:
16: //=======================================================================
17: /**
18: * Iterates over an SQL result set returning each row as an ArrayList of
19: * objects. The returned array is shared at each iteration so calling next() or even hasNext()
20: * changes the array contents. When the iterator terminates the resources
21: * are cleaned up and the underlying SQL PreparedStatement is returned to
22: * the SQLCache pool from whence it came.
23: *
24: * <p>Override the extractRow, getRow, and remove methods in subclasses
25: * to return an object collection derived from the row contents instead
26: * of the raw row contents.
27: *
28: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
29: * @version $Revision: 1.5 $ on $Date: 2008/01/02 12:08:23 $
30: */
31:
32: public class ResultSetNodeIterator extends ResultSetIterator {
33:
34: /**
35: * Extract the current row
36: * Override in subclasses.
37: */
38: protected void extractRow() throws Exception {
39: if (m_row == null) {
40: m_nCols = m_resultSet.getMetaData().getColumnCount();
41: m_row = new ArrayList(m_nCols);
42: for (int i = 0; i < m_nCols; i++)
43: m_row.add(null);
44: }
45: for (int i = 0; i < m_nCols; i++) {
46: m_row.set(i, m_resultSet.getString(i + 1));
47: }
48: }
49:
50: } // End class
51:
52: /*
53: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
54: * All rights reserved.
55: *
56: * Redistribution and use in source and binary forms, with or without
57: * modification, are permitted provided that the following conditions
58: * are met:
59: * 1. Redistributions of source code must retain the above copyright
60: * notice, this list of conditions and the following disclaimer.
61: * 2. Redistributions in binary form must reproduce the above copyright
62: * notice, this list of conditions and the following disclaimer in the
63: * documentation and/or other materials provided with the distribution.
64: * 3. The name of the author may not be used to endorse or promote products
65: * derived from this software without specific prior written permission.
66:
67: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
68: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
69: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
70: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
71: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
72: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
73: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
74: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
75: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
76: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77: */
|