KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smallsql > database > NoFromResult


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  * .java
29  * ---------------
30  * Author: Volker Berlin
31  *
32  * Created on 17.04.2004
33  */

34 package smallsql.database;
35
36 /**
37  * This class is used for SELECT command without FROM clause.
38  *
39  * @author Volker Berlin
40  */

41 final class NoFromResult extends RowSource {
42
43     private int rowPos; // 0-before; 1-on row; 2-after last
44

45
46     final boolean isScrollable(){
47         return true;
48     }
49     
50     
51     final void beforeFirst(){
52         rowPos = 0;
53     }
54
55     final boolean isBeforeFirst(){
56         return rowPos <= 0;
57     }
58     
59     final boolean isFirst(){
60         return rowPos == 1;
61     }
62     
63     final boolean first(){
64         rowPos = 1;
65         return true;
66     }
67
68     final boolean previous(){
69         rowPos--;
70         return rowPos == 1;
71     }
72     
73     
74     final boolean next(){
75         rowPos++;
76         return rowPos == 1;
77     }
78
79     final boolean last(){
80         rowPos = 1;
81         return true;
82     }
83     
84     final boolean isLast(){
85         return rowPos == 1;
86     }
87     
88     final boolean isAfterLast(){
89         return rowPos > 1;
90     }
91     
92     final void afterLast(){
93         rowPos = 2;
94     }
95     
96     final boolean absolute(int row){
97         rowPos = (row > 0) ?
98             Math.min( row, 1 ) :
99             Math.min( row +1, -1 );
100         return rowPos == 1;
101     }
102     
103     final boolean relative(int rows){
104         if(rows == 0) return rowPos == 1;
105         rowPos = Math.min( Math.max( rowPos + rows, -1), 1);
106         return rowPos == 1;
107     }
108     
109     final int getRow(){
110         return rowPos == 1 ? 1 : 0;
111     }
112     
113     final long getRowPosition() {
114         return rowPos;
115     }
116     
117
118     final void setRowPosition(long rowPosition){
119         rowPos = (int)rowPosition;
120     }
121     
122
123     final boolean rowInserted(){
124         return false;
125     }
126     
127     
128     final boolean rowDeleted(){
129         return false;
130     }
131     
132     
133     final void nullRow() {
134         throw new Error JavaDoc();
135     }
136     
137
138     final void noRow() {
139         throw new Error JavaDoc();
140     }
141
142
143     final void execute() throws Exception JavaDoc{/* can be empty, nothing to do */}
144 }
145
Popular Tags