KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quadcap > sql > types > ValueNull


1 package com.quadcap.sql.types;
2
3 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import java.io.Externalizable JavaDoc;
42 import java.io.IOException JavaDoc;
43 import java.io.ObjectInput JavaDoc;
44 import java.io.ObjectOutput JavaDoc;
45
46 import com.quadcap.sql.io.ExternalizeProxy;
47
48 import com.quadcap.util.Debug;
49
50 /**
51  * A <b>NULL</b> value.
52  *
53  * @author Stan Bailes
54  */

55 public class ValueNull extends Value implements Externalizable JavaDoc, ExternalizeProxy {
56     boolean collatesLast = false;
57
58     public static ValueNull valueNull = new ValueNull();
59     public static ValueNull valueLastNull = new ValueNull(true);
60     
61     public ValueNull() {}
62
63     public ValueNull(boolean collatesLast) {
64     this.collatesLast = collatesLast;
65     }
66
67     public Value binop(int op, Value l) throws ValueException {
68     return l.binop(op, this);
69     }
70
71     public ValueInteger nullCmpVal() {
72     return collatesLast ? ValueInteger.PLUS_ONE : ValueInteger.MINUS_ONE;
73     }
74
75     public ValueInteger valCmpNull() {
76     return collatesLast ? ValueInteger.MINUS_ONE : ValueInteger.PLUS_ONE;
77     }
78
79     Value anyBinOp(int op, Value r) throws ValueException {
80     switch (op) {
81     case Op.COMPARE:
82         return nullCmpVal();
83         case Op.EQ:
84         case Op.GE:
85         case Op.GT:
86         case Op.LE:
87         case Op.LT:
88         case Op.NE:
89         return ValueUnknown.valueUnknown;
90     case Op.PLUS:
91     case Op.MINUS:
92     case Op.TIMES:
93     case Op.DIVIDE:
94     case Op.EXP:
95         return this;
96     default:
97         return ValueUnknown.valueUnknown;
98     }
99     }
100
101     public Value binop(int op, ValueBlob r) throws ValueException {
102     return anyBinOp(op, r);
103     }
104
105     public Value binop(int op, ValueBoolean r) throws ValueException {
106     return anyBinOp(op, r);
107     }
108
109     public Value binop(int op, ValueByte r) throws ValueException {
110     return anyBinOp(op, r);
111     }
112
113     public Value binop(int op, ValueClob r) throws ValueException {
114     return anyBinOp(op, r);
115     }
116
117     public Value binop(int op, ValueDate r) throws ValueException {
118     return anyBinOp(op, r);
119     }
120
121     public Value binop(int op, ValueDefault r) throws ValueException {
122     return anyBinOp(op, r);
123     }
124
125     public Value binop(int op, ValueDouble r) throws ValueException {
126     return anyBinOp(op, r);
127     }
128
129     public Value binop(int op, ValueInteger r) throws ValueException {
130     return anyBinOp(op, r);
131     }
132
133     public Value binop(int op, ValueInterval r) throws ValueException {
134     return anyBinOp(op, r);
135     }
136
137     public Value binop(int op, ValueLong r) throws ValueException {
138     return anyBinOp(op, r);
139     }
140
141     public Value binop(int op, ValueNull r) throws ValueException {
142     return ValueNull.binop(op, this, r);
143     }
144
145     public Value binop(int op, ValueOctets r) throws ValueException {
146     return anyBinOp(op, r);
147     }
148
149     public Value binop(int op, ValuePattern r) throws ValueException {
150     return anyBinOp(op, r);
151     }
152
153     public Value binop(int op, ValueScaledInteger r) throws ValueException {
154     return anyBinOp(op, r);
155     }
156
157     public Value binop(int op, ValueShort r) throws ValueException {
158     return anyBinOp(op, r);
159     }
160
161     public Value binop(int op, ValueString r) throws ValueException {
162     return anyBinOp(op, r);
163     }
164
165     public Value binop(int op, ValueTime r) throws ValueException {
166     return anyBinOp(op, r);
167     }
168
169     public Value binop(int op, ValueTimestamp r) throws ValueException {
170     return anyBinOp(op, r);
171     }
172
173     public Value binop(int op, ValueType r) throws ValueException {
174     return anyBinOp(op, r);
175     }
176
177     public Value binop(int op, ValueUnknown r) throws ValueException {
178     return anyBinOp(op, r);
179     }
180
181     public static final Value binop(int op, ValueNull e, ValueNull f)
182     throws ValueException
183     {
184     switch (op) {
185         case Op.EQ:
186         case Op.GE:
187         case Op.GT:
188         case Op.LE:
189         case Op.LT:
190         case Op.NE:
191         return ValueUnknown.valueUnknown;
192     case Op.PLUS:
193     case Op.MINUS:
194     case Op.TIMES:
195     case Op.DIVIDE:
196     case Op.EXP:
197         return f;
198     case Op.COMPARE:
199         return ValueInteger.ZERO;
200         
201     default:
202         return e;
203     }
204     }
205
206     public Value unop(int op) throws ValueException {
207     switch (op) {
208     case Op.NULL:
209         return new ValueBoolean(true);
210     case Op.PLUS:
211         return ValueUnknown.valueUnknown;
212     case Op.MINUS:
213         return ValueUnknown.valueUnknown;
214     default:
215         throw new ValueException("Unary op: " + Op.toString(op) +
216                      " not implemented for this type");
217     }
218     }
219
220     public String JavaDoc toString() {
221     return collatesLast ? "lastnull" : "null";
222     }
223
224     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc {
225     collatesLast = in.read() == 1;
226     }
227     
228     public void writeExternal(ObjectOutput JavaDoc out)
229     throws IOException JavaDoc
230     {
231     out.write(collatesLast ? 1 : 0);
232     }
233
234     public Object JavaDoc readObject(ObjectInput JavaDoc in)
235     throws IOException JavaDoc, ClassNotFoundException JavaDoc
236     {
237     int cl = in.readByte();
238     ValueNull v = new ValueNull(cl == 1);
239     return v;
240     }
241
242     public void writeObject(ObjectOutput JavaDoc out, Object JavaDoc object)
243     throws IOException JavaDoc
244     {
245     ValueNull v = (ValueNull)object;
246     out.write(v.collatesLast ? 1 : 0);
247     }
248
249     public Object JavaDoc asJavaObject() {
250     return null;
251     }
252
253     public void fromJavaObject(Object JavaDoc obj) throws ValueException {
254     if (obj != null) throw new ValueException("bad type: " + obj);
255     }
256
257     // grep alltypes
258
public Value convert(TypeBigInt type) { return this; }
259     public Value convert(TypeBinary type) { return this; }
260     public Value convert(TypeBlob type) { return this; }
261     public Value convert(TypeBoolean type) { return this; }
262     public Value convert(TypeChar type) { return this; }
263     public Value convert(TypeClob type) { return this; }
264     public Value convert(TypeDate type) { return this; }
265     public Value convert(TypeDecimal type) { return this; }
266     public Value convert(TypeInt type) { return this; }
267     public Value convert(TypeInterval type) { return this; }
268     public Value convert(TypeReal type) { return this; }
269     public Value convert(TypeSmallInt type) { return this; }
270     public Value convert(TypeTime type) { return this; }
271     public Value convert(TypeTimestamp type) { return this; }
272     public Value convert(TypeTinyInt type) { return this; }
273     public Value convert(TypeVarBinary type) { return this; }
274     public Value convert(TypeVarChar type) { return this; }
275
276     public Type getType() {
277     return TypeAny.any;
278     }
279
280     public void serializeKey(KeyStream out) throws IOException JavaDoc {
281     out.writeNull(collatesLast);
282     }
283 }
284
Popular Tags