Source code: com/mysql/jdbc/RowDataStatic.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.util.ArrayList;
27 import java.util.List;
28
29
30 /**
31 * Represents an in-memory result set
32 *
33 * @author dgan
34 * @version $Id: RowDataStatic.java,v 1.10.2.5 2004/08/09 22:15:12 mmatthew Exp $
35 */
36 public class RowDataStatic implements RowData {
37 private List rows;
38 private int index;
39 private ResultSet owner;
40
41 /**
42 * Creates a new RowDataStatic object.
43 *
44 * @param rows DOCUMENT ME!
45 */
46 public RowDataStatic(ArrayList rows) {
47 this.index = -1;
48 this.rows = rows;
49 }
50
51 /**
52 * Returns true if we got the last element.
53 * @return DOCUMENT ME!
54 */
55 public boolean isAfterLast() {
56 return this.index >= rows.size();
57 }
58
59 /**
60 * DOCUMENT ME!
61 *
62 * @param atIndex DOCUMENT ME!
63 *
64 * @return DOCUMENT ME!
65 */
66 public byte[][] getAt(int atIndex) {
67 if ((atIndex < 0) || (atIndex >= rows.size())) {
68 return null;
69 } else {
70 return (byte[][]) rows.get(atIndex);
71 }
72 }
73
74 /**
75 * Returns if iteration has not occured yet.
76 * @return DOCUMENT ME!
77 */
78 public boolean isBeforeFirst() {
79 return (this.index == -1) && (this.rows.size() != 0);
80 }
81
82 /**
83 * DOCUMENT ME!
84 *
85 * @param newIndex DOCUMENT ME!
86 */
87 public void setCurrentRow(int newIndex) {
88 this.index = newIndex;
89 }
90
91 /**
92 * @see com.mysql.jdbc.RowData#setOwner(com.mysql.jdbc.ResultSet)
93 */
94 public void setOwner(ResultSet rs) {
95 this.owner = rs;
96 }
97
98 /**
99 * @see com.mysql.jdbc.RowData#getOwner()
100 */
101 public ResultSet getOwner() {
102 return this.owner;
103 }
104
105 /**
106 * DOCUMENT ME!
107 *
108 * @return DOCUMENT ME!
109 */
110 public int getCurrentRowNumber() {
111 return this.index;
112 }
113
114 /**
115 * DOCUMENT ME!
116 *
117 * @return DOCUMENT ME!
118 */
119 public boolean isDynamic() {
120 return false;
121 }
122
123 /**
124 * DOCUMENT ME!
125 *
126 * @return DOCUMENT ME!
127 */
128 public boolean isEmpty() {
129 return rows.size() == 0;
130 }
131
132 /**
133 * DOCUMENT ME!
134 *
135 * @return DOCUMENT ME!
136 */
137 public boolean isFirst() {
138 return this.index == 0;
139 }
140
141 /**
142 * DOCUMENT ME!
143 *
144 * @return DOCUMENT ME!
145 */
146 public boolean isLast() {
147 //
148 // You can never be on the 'last' row of
149 // an empty result set
150 //
151 if (rows.size() == 0) {
152 return false;
153 }
154
155 return (this.index == (rows.size() - 1));
156 }
157
158 /**
159 * DOCUMENT ME!
160 *
161 * @param row DOCUMENT ME!
162 */
163 public void addRow(byte[][] row) {
164 rows.add(row);
165 }
166
167 /**
168 * Moves to after last.
169 */
170 public void afterLast() {
171 this.index = rows.size();
172 }
173
174 /**
175 * Moves to before first.
176 */
177 public void beforeFirst() {
178 this.index = -1;
179 }
180
181 /**
182 * DOCUMENT ME!
183 */
184 public void beforeLast() {
185 this.index = rows.size() - 2;
186 }
187
188 /**
189 * DOCUMENT ME!
190 */
191 public void close() {
192 }
193
194 /**
195 * DOCUMENT ME!
196 *
197 * @return DOCUMENT ME!
198 */
199 public boolean hasNext() {
200 boolean hasMore = (this.index + 1) < rows.size();
201
202 return hasMore;
203 }
204
205 /**
206 * DOCUMENT ME!
207 *
208 * @param rows DOCUMENT ME!
209 */
210 public void moveRowRelative(int rows) {
211 this.index += rows;
212 }
213
214 /**
215 * DOCUMENT ME!
216 *
217 * @return DOCUMENT ME!
218 */
219 public byte[][] next() {
220 this.index++;
221
222 if (this.index < rows.size()) {
223 return (byte[][]) rows.get(this.index);
224 } else {
225 return null;
226 }
227 }
228
229 /**
230 * DOCUMENT ME!
231 *
232 * @param atIndex DOCUMENT ME!
233 */
234 public void removeRow(int atIndex) {
235 rows.remove(atIndex);
236 }
237
238 /**
239 * DOCUMENT ME!
240 *
241 * @return DOCUMENT ME!
242 */
243 public int size() {
244 return rows.size();
245 }
246 }