001: /*
002: Copyright (C) 2002-2007 MySQL AB
003:
004: This program is free software; you can redistribute it and/or modify
005: it under the terms of version 2 of the GNU General Public License as
006: published by the Free Software Foundation.
007:
008: There are special exceptions to the terms and conditions of the GPL
009: as it is applied to this software. View the full text of the
010: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
011: software distribution.
012:
013: This program is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with this program; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021:
022:
023:
024: */
025: package com.mysql.jdbc;
026:
027: import java.sql.SQLException;
028:
029: /**
030: * This interface abstracts away how row data is accessed by the result set. It
031: * is meant to allow a static implementation (Current version), and a streaming
032: * one.
033: *
034: * @author dgan
035: */
036: public interface RowData {
037:
038: /**
039: * What's returned for the size of a result set when its size can not be
040: * determined.
041: */
042: public static final int RESULT_SET_SIZE_UNKNOWN = -1;
043:
044: /**
045: * Adds a row to this row data.
046: *
047: * @param row
048: * the row to add
049: * @throws SQLException
050: * if a database error occurs
051: */
052: void addRow(ResultSetRow row) throws SQLException;
053:
054: /**
055: * Moves to after last.
056: *
057: * @throws SQLException
058: * if a database error occurs
059: */
060: void afterLast() throws SQLException;
061:
062: /**
063: * Moves to before first.
064: *
065: * @throws SQLException
066: * if a database error occurs
067: */
068: void beforeFirst() throws SQLException;
069:
070: /**
071: * Moves to before last so next el is the last el.
072: *
073: * @throws SQLException
074: * if a database error occurs
075: */
076: void beforeLast() throws SQLException;
077:
078: /**
079: * We're done.
080: *
081: * @throws SQLException
082: * if a database error occurs
083: */
084: void close() throws SQLException;
085:
086: /**
087: * Only works on non dynamic result sets.
088: *
089: * @param index
090: * row number to get at
091: * @return row data at index
092: * @throws SQLException
093: * if a database error occurs
094: */
095: ResultSetRow getAt(int index) throws SQLException;
096:
097: /**
098: * Returns the current position in the result set as a row number.
099: *
100: * @return the current row number
101: * @throws SQLException
102: * if a database error occurs
103: */
104: int getCurrentRowNumber() throws SQLException;
105:
106: /**
107: * Returns the result set that 'owns' this RowData
108: */
109: ResultSetInternalMethods getOwner();
110:
111: /**
112: * Returns true if another row exsists.
113: *
114: * @return true if more rows
115: * @throws SQLException
116: * if a database error occurs
117: */
118: boolean hasNext() throws SQLException;
119:
120: /**
121: * Returns true if we got the last element.
122: *
123: * @return true if after last row
124: * @throws SQLException
125: * if a database error occurs
126: */
127: boolean isAfterLast() throws SQLException;
128:
129: /**
130: * Returns if iteration has not occured yet.
131: *
132: * @return true if before first row
133: * @throws SQLException
134: * if a database error occurs
135: */
136: boolean isBeforeFirst() throws SQLException;
137:
138: /**
139: * Returns true if the result set is dynamic.
140: *
141: * This means that move back and move forward won't work because we do not
142: * hold on to the records.
143: *
144: * @return true if this result set is streaming from the server
145: * @throws SQLException
146: * if a database error occurs
147: */
148: boolean isDynamic() throws SQLException;
149:
150: /**
151: * Has no records.
152: *
153: * @return true if no records
154: * @throws SQLException
155: * if a database error occurs
156: */
157: boolean isEmpty() throws SQLException;
158:
159: /**
160: * Are we on the first row of the result set?
161: *
162: * @return true if on first row
163: * @throws SQLException
164: * if a database error occurs
165: */
166: boolean isFirst() throws SQLException;
167:
168: /**
169: * Are we on the last row of the result set?
170: *
171: * @return true if on last row
172: * @throws SQLException
173: * if a database error occurs
174: */
175: boolean isLast() throws SQLException;
176:
177: /**
178: * Moves the current position relative 'rows' from the current position.
179: *
180: * @param rows
181: * the relative number of rows to move
182: * @throws SQLException
183: * if a database error occurs
184: */
185: void moveRowRelative(int rows) throws SQLException;
186:
187: /**
188: * Returns the next row.
189: *
190: * @return the next row value
191: * @throws SQLException
192: * if a database error occurs
193: */
194: ResultSetRow next() throws SQLException;
195:
196: /**
197: * Removes the row at the given index.
198: *
199: * @param index
200: * the row to move to
201: * @throws SQLException
202: * if a database error occurs
203: */
204: void removeRow(int index) throws SQLException;
205:
206: /**
207: * Moves the current position in the result set to the given row number.
208: *
209: * @param rowNumber
210: * row to move to
211: * @throws SQLException
212: * if a database error occurs
213: */
214: void setCurrentRow(int rowNumber) throws SQLException;
215:
216: /**
217: * Set the result set that 'owns' this RowData
218: *
219: * @param rs
220: * the result set that 'owns' this RowData
221: */
222: void setOwner(ResultSetImpl rs);
223:
224: /**
225: * Only works on non dynamic result sets.
226: *
227: * @return the size of this row data
228: * @throws SQLException
229: * if a database error occurs
230: */
231: int size() throws SQLException;
232:
233: /**
234: * Did this result set have no rows?
235: */
236: boolean wasEmpty();
237:
238: /**
239: * Sometimes the driver doesn't have metadata until after
240: * the statement has the result set in-hand (because it's cached),
241: * so it can call this to set it after the fact.
242: *
243: * @param metadata field-level metadata for the result set
244: */
245: void setMetadata(Field[] metadata);
246: }
|