Source code: com/mysql/jdbc/RowData.java
1 /*
2 Copyright (C) 2002-2004 MySQL AB
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of version 2 of the GNU General Public License as
6 published by the Free Software Foundation.
7
8
9 There are special exceptions to the terms and conditions of the GPL
10 as it is applied to this software. View the full text of the
11 exception exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
12 software distribution.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23 */
24 package com.mysql.jdbc;
25
26 import java.sql.SQLException;
27
28
29 /**
30 * This interface abstracts away how row data is accessed by
31 * the result set. It is meant to allow a static implementation
32 * (Current version), and a streaming one.
33 *
34 * @author dgan
35 */
36 public interface RowData {
37 /**
38 * What's returned for the size of a result set
39 * when its size can not be determined.
40 */
41 public static final int RESULT_SET_SIZE_UNKNOWN = -1;
42
43 /**
44 * Returns true if we got the last element.
45 *
46 * @return true if after last row
47 * @throws SQLException if a database error occurs
48 */
49 boolean isAfterLast() throws SQLException;
50
51 /**
52 * Only works on non dynamic result sets.
53 *
54 * @param index row number to get at
55 * @return row data at index
56 * @throws SQLException if a database error occurs
57 */
58 byte[][] getAt(int index) throws SQLException;
59
60 /**
61 * Returns if iteration has not occured yet.
62 *
63 * @return true if before first row
64 * @throws SQLException if a database error occurs
65 */
66 boolean isBeforeFirst() throws SQLException;
67
68 /**
69 * Moves the current position in the result set to
70 * the given row number.
71 *
72 * @param rowNumber row to move to
73 * @throws SQLException if a database error occurs
74 */
75 void setCurrentRow(int rowNumber) throws SQLException;
76
77 /**
78 * Returns the current position in the result set as
79 * a row number.
80 *
81 * @return the current row number
82 * @throws SQLException if a database error occurs
83 */
84 int getCurrentRowNumber() throws SQLException;
85
86 /**
87 * Returns true if the result set is dynamic.
88 *
89 * This means that move back and move forward won't work
90 * because we do not hold on to the records.
91 *
92 * @return true if this result set is streaming from the server
93 * @throws SQLException if a database error occurs
94 */
95 boolean isDynamic() throws SQLException;
96
97 /**
98 * Has no records.
99 *
100 * @return true if no records
101 * @throws SQLException if a database error occurs
102 */
103 boolean isEmpty() throws SQLException;
104
105 /**
106 * Are we on the first row of the result set?
107 *
108 * @return true if on first row
109 * @throws SQLException if a database error occurs
110 */
111 boolean isFirst() throws SQLException;
112
113 /**
114 * Are we on the last row of the result set?
115 *
116 * @return true if on last row
117 * @throws SQLException if a database error occurs
118 */
119 boolean isLast() throws SQLException;
120
121 /**
122 * Adds a row to this row data.
123 *
124 * @param row the row to add
125 * @throws SQLException if a database error occurs
126 */
127 void addRow(byte[][] row) throws SQLException;
128
129 /**
130 * Moves to after last.
131 *
132 * @throws SQLException if a database error occurs
133 */
134 void afterLast() throws SQLException;
135
136 /**
137 * Moves to before first.
138 *
139 * @throws SQLException if a database error occurs
140 */
141 void beforeFirst() throws SQLException;
142
143 /**
144 * Moves to before last so next el is the last el.
145 *
146 * @throws SQLException if a database error occurs
147 */
148 void beforeLast() throws SQLException;
149
150 /**
151 * We're done.
152 *
153 * @throws SQLException if a database error occurs
154 */
155 void close() throws SQLException;
156
157 /**
158 * Returns true if another row exsists.
159 *
160 * @return true if more rows
161 * @throws SQLException if a database error occurs
162 */
163 boolean hasNext() throws SQLException;
164
165 /**
166 * Moves the current position relative 'rows' from
167 * the current position.
168 *
169 * @param rows the relative number of rows to move
170 * @throws SQLException if a database error occurs
171 */
172 void moveRowRelative(int rows) throws SQLException;
173
174 /**
175 * Returns the next row.
176 *
177 * @return the next row value
178 * @throws SQLException if a database error occurs
179 */
180 byte[][] next() throws SQLException;
181
182 /**
183 * Removes the row at the given index.
184 *
185 * @param index the row to move to
186 * @throws SQLException if a database error occurs
187 */
188 void removeRow(int index) throws SQLException;
189
190 /**
191 * Only works on non dynamic result sets.
192 *
193 * @return the size of this row data
194 * @throws SQLException if a database error occurs
195 */
196 int size() throws SQLException;
197
198 /**
199 * Set the result set that 'owns' this RowData
200 *
201 * @param rs the result set that 'owns' this RowData
202 */
203 void setOwner(ResultSet rs);
204
205 /**
206 * Returns the result set that 'owns' this RowData
207 *
208 * @return the result set that 'owns' this RowData
209 */
210 ResultSet getOwner();
211
212 }