KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smallsql > database > ViewResult


1 /* =============================================================
2  * SmallSQL : a free Java DBMS library for the Java(tm) platform
3  * =============================================================
4  *
5  * (C) Copyright 2004-2006, by Volker Berlin.
6  *
7  * Project Info: http://www.smallsql.de/
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------
28  * ViewResult.java
29  * ---------------
30  * Author: Volker Berlin
31  *
32  * Created on 05.06.2004
33  */

34 package smallsql.database;
35
36 import java.sql.*;
37
38
39 /**
40  * @author Volker Berlin
41  */

42 class ViewResult extends TableViewResult {
43     
44     final private View view;
45     final private Expressions columnExpressions;
46     final private CommandSelect commandSelect;
47
48
49     ViewResult(View view){
50         this.view = view;
51         this.columnExpressions = view.commandSelect.columnExpressions;
52         this.commandSelect = view.commandSelect;
53     }
54     
55
56     /**
57      * Constructor is used for UNION
58      * @throws Exception
59      *
60      */

61     ViewResult(SSConnection con, CommandSelect commandSelect) throws SQLException{
62         try{
63             this.view = new View( con, commandSelect);
64             this.columnExpressions = commandSelect.columnExpressions;
65             this.commandSelect = commandSelect;
66         }catch(Exception JavaDoc e){
67             throw Utils.createSQLException(e);
68         }
69     }
70     
71     
72     /**
73      * Is used for compile() of different Commands
74      *
75      * @param con
76      * @return true if now init; false if already init
77      * @throws Exception
78      */

79     boolean init( SSConnection con ) throws Exception JavaDoc{
80         if(super.init(con)){
81             commandSelect.compile(con);
82             return true;
83         }
84         return false;
85     }
86
87
88
89
90 /*=====================================================================
91  *
92  * Methods of base class TableViewResult
93  *
94  ====================================================================*/

95     
96     TableView getTableView(){
97         return view;
98     }
99     
100     
101     void deleteRow() throws SQLException{
102         commandSelect.deleteRow(con);
103     }
104
105     void updateRow(Expression[] updateValues) throws Exception JavaDoc{
106         commandSelect.updateRow(con, updateValues);
107     }
108     
109     void insertRow(Expression[] updateValues) throws Exception JavaDoc{
110         commandSelect.insertRow(con, updateValues);
111     }
112
113 /*=====================================================================
114  *
115  * Methods of interface DataSource
116  *
117  ====================================================================*/

118     boolean isNull(int colIdx) throws Exception JavaDoc {
119         return columnExpressions.get(colIdx).isNull();
120     }
121
122
123     boolean getBoolean(int colIdx) throws Exception JavaDoc {
124         return columnExpressions.get(colIdx).getBoolean();
125     }
126
127
128     int getInt(int colIdx) throws Exception JavaDoc {
129         return columnExpressions.get(colIdx).getInt();
130     }
131
132
133     long getLong(int colIdx) throws Exception JavaDoc {
134         return columnExpressions.get(colIdx).getLong();
135     }
136
137
138     float getFloat(int colIdx) throws Exception JavaDoc {
139         return columnExpressions.get(colIdx).getFloat();
140     }
141
142
143     double getDouble(int colIdx) throws Exception JavaDoc {
144         return columnExpressions.get(colIdx).getDouble();
145     }
146
147
148     long getMoney(int colIdx) throws Exception JavaDoc {
149         return columnExpressions.get(colIdx).getMoney();
150     }
151
152
153     MutableNumeric getNumeric(int colIdx) throws Exception JavaDoc {
154         return columnExpressions.get(colIdx).getNumeric();
155     }
156
157
158     Object JavaDoc getObject(int colIdx) throws Exception JavaDoc {
159         return columnExpressions.get(colIdx).getObject();
160     }
161
162
163     String JavaDoc getString(int colIdx) throws Exception JavaDoc {
164         return columnExpressions.get(colIdx).getString();
165     }
166
167
168     byte[] getBytes(int colIdx) throws Exception JavaDoc {
169         return columnExpressions.get(colIdx).getBytes();
170     }
171
172
173     int getDataType(int colIdx) {
174         return columnExpressions.get(colIdx).getDataType();
175     }
176
177
178     /*=====================================================
179      *
180      * Methods of the interface RowSource
181      *
182      =====================================================*/

183     
184     void beforeFirst() throws Exception JavaDoc {
185         commandSelect.beforeFirst();
186     }
187
188
189     boolean isBeforeFirst() throws SQLException{
190         return commandSelect.isBeforeFirst();
191     }
192     
193     
194     boolean isFirst() throws SQLException{
195         return commandSelect.isFirst();
196     }
197     
198     
199     boolean first() throws Exception JavaDoc {
200         return commandSelect.first();
201     }
202
203
204     boolean previous() throws Exception JavaDoc{
205         return commandSelect.previous();
206     }
207     
208     
209     boolean next() throws Exception JavaDoc {
210         return commandSelect.next();
211     }
212
213
214     boolean last() throws Exception JavaDoc{
215         return commandSelect.last();
216     }
217     
218     
219     boolean isLast() throws Exception JavaDoc{
220         return commandSelect.isLast();
221     }
222
223
224     boolean isAfterLast() throws Exception JavaDoc{
225         return commandSelect.isAfterLast();
226     }
227     
228
229     void afterLast() throws Exception JavaDoc{
230         commandSelect.afterLast();
231     }
232     
233     
234     boolean absolute(int row) throws Exception JavaDoc{
235         return commandSelect.absolute(row);
236     }
237     
238     
239     boolean relative(int rows) throws Exception JavaDoc{
240         return commandSelect.relative(rows);
241     }
242     
243     
244     int getRow() throws Exception JavaDoc{
245         return commandSelect.getRow();
246     }
247     
248     
249     long getRowPosition() {
250         return commandSelect.join.getRowPosition();
251     }
252
253
254     void setRowPosition(long rowPosition) throws Exception JavaDoc {
255         commandSelect.join.setRowPosition(rowPosition);
256     }
257
258
259     final boolean rowInserted(){
260         return commandSelect.join.rowInserted();
261     }
262     
263     
264     final boolean rowDeleted(){
265         return commandSelect.join.rowDeleted();
266     }
267     
268     
269     void nullRow() {
270         commandSelect.join.nullRow();
271
272     }
273
274
275     void noRow() {
276         commandSelect.join.noRow();
277     }
278
279     
280     final void execute() throws Exception JavaDoc{
281         commandSelect.join.execute();
282     }
283 }
284
Popular Tags