1 package com.quadcap.sql.types; 2 3 40 41 import java.io.Externalizable ; 42 import java.io.IOException ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 46 import com.quadcap.sql.io.ExternalizeProxy; 47 48 import com.quadcap.util.Debug; 49 50 55 public class ValueNull extends Value implements Externalizable , 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 toString() { 221 return collatesLast ? "lastnull" : "null"; 222 } 223 224 public void readExternal(ObjectInput in) throws IOException { 225 collatesLast = in.read() == 1; 226 } 227 228 public void writeExternal(ObjectOutput out) 229 throws IOException 230 { 231 out.write(collatesLast ? 1 : 0); 232 } 233 234 public Object readObject(ObjectInput in) 235 throws IOException , ClassNotFoundException 236 { 237 int cl = in.readByte(); 238 ValueNull v = new ValueNull(cl == 1); 239 return v; 240 } 241 242 public void writeObject(ObjectOutput out, Object object) 243 throws IOException 244 { 245 ValueNull v = (ValueNull)object; 246 out.write(v.collatesLast ? 1 : 0); 247 } 248 249 public Object asJavaObject() { 250 return null; 251 } 252 253 public void fromJavaObject(Object obj) throws ValueException { 254 if (obj != null) throw new ValueException("bad type: " + obj); 255 } 256 257 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 { 281 out.writeNull(collatesLast); 282 } 283 } 284 | Popular Tags |