KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > RowDataStatic


1 /*
2    Copyright (C) 2002 MySQL AB
3
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8
9       This program is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12       GNU General Public License for more details.
13
14       You should have received a copy of the GNU General Public License
15       along with this program; if not, write to the Free Software
16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18  */

19 package com.mysql.jdbc;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24
25 /**
26  * Represents an in-memory result set
27  *
28  * @author dgan
29  * @version $Id: RowDataStatic.java,v 1.10.2.3 2003/10/03 16:29:44 mmatthew Exp $
30  */

31 public class RowDataStatic implements RowData {
32     private List JavaDoc rows;
33     private int index;
34     private ResultSet owner;
35
36     /**
37      * Creates a new RowDataStatic object.
38      *
39      * @param rows DOCUMENT ME!
40      */

41     public RowDataStatic(ArrayList JavaDoc rows) {
42         this.index = -1;
43         this.rows = rows;
44     }
45
46     /**
47      * Returns true if we got the last element.
48      * @return DOCUMENT ME!
49      */

50     public boolean isAfterLast() {
51         return this.index >= rows.size();
52     }
53
54     /**
55      * DOCUMENT ME!
56      *
57      * @param atIndex DOCUMENT ME!
58      *
59      * @return DOCUMENT ME!
60      */

61     public byte[][] getAt(int atIndex) {
62         if ((atIndex < 0) || (atIndex >= rows.size())) {
63             return null;
64         } else {
65             return (byte[][]) rows.get(atIndex);
66         }
67     }
68
69     /**
70      * Returns if iteration has not occured yet.
71      * @return DOCUMENT ME!
72      */

73     public boolean isBeforeFirst() {
74         return (this.index == -1) && (this.rows.size() != 0);
75     }
76
77     /**
78      * DOCUMENT ME!
79      *
80      * @param newIndex DOCUMENT ME!
81      */

82     public void setCurrentRow(int newIndex) {
83         this.index = newIndex;
84     }
85
86     /**
87      * @see com.mysql.jdbc.RowData#setOwner(com.mysql.jdbc.ResultSet)
88      */

89     public void setOwner(ResultSet rs) {
90         this.owner = rs;
91     }
92     
93     /**
94      * @see com.mysql.jdbc.RowData#getOwner()
95      */

96     public ResultSet getOwner() {
97         return this.owner;
98     }
99     
100     /**
101      * DOCUMENT ME!
102      *
103      * @return DOCUMENT ME!
104      */

105     public int getCurrentRowNumber() {
106         return this.index;
107     }
108
109     /**
110      * DOCUMENT ME!
111      *
112      * @return DOCUMENT ME!
113      */

114     public boolean isDynamic() {
115         return false;
116     }
117
118     /**
119      * DOCUMENT ME!
120      *
121      * @return DOCUMENT ME!
122      */

123     public boolean isEmpty() {
124         return rows.size() == 0;
125     }
126
127     /**
128      * DOCUMENT ME!
129      *
130      * @return DOCUMENT ME!
131      */

132     public boolean isFirst() {
133         return this.index == 0;
134     }
135
136     /**
137      * DOCUMENT ME!
138      *
139      * @return DOCUMENT ME!
140      */

141     public boolean isLast() {
142         //
143
// You can never be on the 'last' row of
144
// an empty result set
145
//
146
if (rows.size() == 0) {
147             return false;
148         }
149
150         return (this.index == (rows.size() - 1));
151     }
152
153     /**
154      * DOCUMENT ME!
155      *
156      * @param row DOCUMENT ME!
157      */

158     public void addRow(byte[][] row) {
159         rows.add(row);
160     }
161
162     /**
163      * Moves to after last.
164      */

165     public void afterLast() {
166         this.index = rows.size();
167     }
168
169     /**
170      * Moves to before first.
171      */

172     public void beforeFirst() {
173         this.index = -1;
174     }
175
176     /**
177      * DOCUMENT ME!
178      */

179     public void beforeLast() {
180         this.index = rows.size() - 2;
181     }
182
183     /**
184      * DOCUMENT ME!
185      */

186     public void close() {
187     }
188
189     /**
190      * DOCUMENT ME!
191      *
192      * @return DOCUMENT ME!
193      */

194     public boolean hasNext() {
195         boolean hasMore = (this.index + 1) < rows.size();
196
197         return hasMore;
198     }
199
200     /**
201      * DOCUMENT ME!
202      *
203      * @param rows DOCUMENT ME!
204      */

205     public void moveRowRelative(int rows) {
206         this.index += rows;
207     }
208
209     /**
210      * DOCUMENT ME!
211      *
212      * @return DOCUMENT ME!
213      */

214     public byte[][] next() {
215         this.index++;
216
217         if (this.index < rows.size()) {
218             return (byte[][]) rows.get(this.index);
219         } else {
220             return null;
221         }
222     }
223
224     /**
225      * DOCUMENT ME!
226      *
227      * @param atIndex DOCUMENT ME!
228      */

229     public void removeRow(int atIndex) {
230         rows.remove(atIndex);
231     }
232
233     /**
234      * DOCUMENT ME!
235      *
236      * @return DOCUMENT ME!
237      */

238     public int size() {
239         return rows.size();
240     }
241 }
242
Popular Tags