1 | /* |
---|
2 | Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
---|
3 | |
---|
4 | |
---|
5 | The MySQL Connector/J is licensed under the terms of the GPLv2 |
---|
6 | <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors. |
---|
7 | There are special exceptions to the terms and conditions of the GPLv2 as it is applied to |
---|
8 | this software, see the FLOSS License Exception |
---|
9 | <http://www.mysql.com/about/legal/licensing/foss-exception.html>. |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under the terms |
---|
12 | of the GNU General Public License as published by the Free Software Foundation; version 2 |
---|
13 | of the License. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
---|
16 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
17 | See the GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License along with this |
---|
20 | program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth |
---|
21 | Floor, Boston, MA 02110-1301 USA |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | */ |
---|
26 | package com.mysql.jdbc; |
---|
27 | |
---|
28 | import java.sql.SQLException; |
---|
29 | |
---|
30 | /** |
---|
31 | * This interface abstracts away how row data is accessed by the result set. It |
---|
32 | * is meant to allow a static implementation (Current version), and a streaming |
---|
33 | * one. |
---|
34 | * |
---|
35 | * @author dgan |
---|
36 | */ |
---|
37 | public interface RowData { |
---|
38 | |
---|
39 | /** |
---|
40 | * What's returned for the size of a result set when its size can not be |
---|
41 | * determined. |
---|
42 | */ |
---|
43 | public static final int RESULT_SET_SIZE_UNKNOWN = -1; |
---|
44 | |
---|
45 | /** |
---|
46 | * Adds a row to this row data. |
---|
47 | * |
---|
48 | * @param row |
---|
49 | * the row to add |
---|
50 | * @throws SQLException |
---|
51 | * if a database error occurs |
---|
52 | */ |
---|
53 | void addRow(ResultSetRow row) throws SQLException; |
---|
54 | |
---|
55 | /** |
---|
56 | * Moves to after last. |
---|
57 | * |
---|
58 | * @throws SQLException |
---|
59 | * if a database error occurs |
---|
60 | */ |
---|
61 | void afterLast() throws SQLException; |
---|
62 | |
---|
63 | /** |
---|
64 | * Moves to before first. |
---|
65 | * |
---|
66 | * @throws SQLException |
---|
67 | * if a database error occurs |
---|
68 | */ |
---|
69 | void beforeFirst() throws SQLException; |
---|
70 | |
---|
71 | /** |
---|
72 | * Moves to before last so next el is the last el. |
---|
73 | * |
---|
74 | * @throws SQLException |
---|
75 | * if a database error occurs |
---|
76 | */ |
---|
77 | void beforeLast() throws SQLException; |
---|
78 | |
---|
79 | /** |
---|
80 | * We're done. |
---|
81 | * |
---|
82 | * @throws SQLException |
---|
83 | * if a database error occurs |
---|
84 | */ |
---|
85 | void close() throws SQLException; |
---|
86 | |
---|
87 | /** |
---|
88 | * Only works on non dynamic result sets. |
---|
89 | * |
---|
90 | * @param index |
---|
91 | * row number to get at |
---|
92 | * @return row data at index |
---|
93 | * @throws SQLException |
---|
94 | * if a database error occurs |
---|
95 | */ |
---|
96 | ResultSetRow getAt(int index) throws SQLException; |
---|
97 | |
---|
98 | /** |
---|
99 | * Returns the current position in the result set as a row number. |
---|
100 | * |
---|
101 | * @return the current row number |
---|
102 | * @throws SQLException |
---|
103 | * if a database error occurs |
---|
104 | */ |
---|
105 | int getCurrentRowNumber() throws SQLException; |
---|
106 | |
---|
107 | /** |
---|
108 | * Returns the result set that 'owns' this RowData |
---|
109 | */ |
---|
110 | ResultSetInternalMethods getOwner(); |
---|
111 | |
---|
112 | /** |
---|
113 | * Returns true if another row exsists. |
---|
114 | * |
---|
115 | * @return true if more rows |
---|
116 | * @throws SQLException |
---|
117 | * if a database error occurs |
---|
118 | */ |
---|
119 | boolean hasNext() throws SQLException; |
---|
120 | |
---|
121 | /** |
---|
122 | * Returns true if we got the last element. |
---|
123 | * |
---|
124 | * @return true if after last row |
---|
125 | * @throws SQLException |
---|
126 | * if a database error occurs |
---|
127 | */ |
---|
128 | boolean isAfterLast() throws SQLException; |
---|
129 | |
---|
130 | /** |
---|
131 | * Returns if iteration has not occured yet. |
---|
132 | * |
---|
133 | * @return true if before first row |
---|
134 | * @throws SQLException |
---|
135 | * if a database error occurs |
---|
136 | */ |
---|
137 | boolean isBeforeFirst() throws SQLException; |
---|
138 | |
---|
139 | /** |
---|
140 | * Returns true if the result set is dynamic. |
---|
141 | * |
---|
142 | * This means that move back and move forward won't work because we do not |
---|
143 | * hold on to the records. |
---|
144 | * |
---|
145 | * @return true if this result set is streaming from the server |
---|
146 | * @throws SQLException |
---|
147 | * if a database error occurs |
---|
148 | */ |
---|
149 | boolean isDynamic() throws SQLException; |
---|
150 | |
---|
151 | /** |
---|
152 | * Has no records. |
---|
153 | * |
---|
154 | * @return true if no records |
---|
155 | * @throws SQLException |
---|
156 | * if a database error occurs |
---|
157 | */ |
---|
158 | boolean isEmpty() throws SQLException; |
---|
159 | |
---|
160 | /** |
---|
161 | * Are we on the first row of the result set? |
---|
162 | * |
---|
163 | * @return true if on first row |
---|
164 | * @throws SQLException |
---|
165 | * if a database error occurs |
---|
166 | */ |
---|
167 | boolean isFirst() throws SQLException; |
---|
168 | |
---|
169 | /** |
---|
170 | * Are we on the last row of the result set? |
---|
171 | * |
---|
172 | * @return true if on last row |
---|
173 | * @throws SQLException |
---|
174 | * if a database error occurs |
---|
175 | */ |
---|
176 | boolean isLast() throws SQLException; |
---|
177 | |
---|
178 | /** |
---|
179 | * Moves the current position relative 'rows' from the current position. |
---|
180 | * |
---|
181 | * @param rows |
---|
182 | * the relative number of rows to move |
---|
183 | * @throws SQLException |
---|
184 | * if a database error occurs |
---|
185 | */ |
---|
186 | void moveRowRelative(int rows) throws SQLException; |
---|
187 | |
---|
188 | /** |
---|
189 | * Returns the next row. |
---|
190 | * |
---|
191 | * @return the next row value |
---|
192 | * @throws SQLException |
---|
193 | * if a database error occurs |
---|
194 | */ |
---|
195 | ResultSetRow next() throws SQLException; |
---|
196 | |
---|
197 | /** |
---|
198 | * Removes the row at the given index. |
---|
199 | * |
---|
200 | * @param index |
---|
201 | * the row to move to |
---|
202 | * @throws SQLException |
---|
203 | * if a database error occurs |
---|
204 | */ |
---|
205 | void removeRow(int index) throws SQLException; |
---|
206 | |
---|
207 | /** |
---|
208 | * Moves the current position in the result set to the given row number. |
---|
209 | * |
---|
210 | * @param rowNumber |
---|
211 | * row to move to |
---|
212 | * @throws SQLException |
---|
213 | * if a database error occurs |
---|
214 | */ |
---|
215 | void setCurrentRow(int rowNumber) throws SQLException; |
---|
216 | |
---|
217 | /** |
---|
218 | * Set the result set that 'owns' this RowData |
---|
219 | * |
---|
220 | * @param rs |
---|
221 | * the result set that 'owns' this RowData |
---|
222 | */ |
---|
223 | void setOwner(ResultSetImpl rs); |
---|
224 | |
---|
225 | /** |
---|
226 | * Only works on non dynamic result sets. |
---|
227 | * |
---|
228 | * @return the size of this row data |
---|
229 | * @throws SQLException |
---|
230 | * if a database error occurs |
---|
231 | */ |
---|
232 | int size() throws SQLException; |
---|
233 | |
---|
234 | /** |
---|
235 | * Did this result set have no rows? |
---|
236 | */ |
---|
237 | boolean wasEmpty(); |
---|
238 | |
---|
239 | /** |
---|
240 | * Sometimes the driver doesn't have metadata until after |
---|
241 | * the statement has the result set in-hand (because it's cached), |
---|
242 | * so it can call this to set it after the fact. |
---|
243 | * |
---|
244 | * @param metadata field-level metadata for the result set |
---|
245 | */ |
---|
246 | void setMetadata(Field[] metadata); |
---|
247 | } |
---|