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 java.util.Calendar ; 47 import java.util.Date ; 48 49 54 public abstract class ValueDateTime extends Value implements Externalizable { 55 long val; 56 57 public ValueDateTime() {} 58 59 public ValueDateTime(long val) { 60 this.val = val; 61 } 62 63 Calendar getCal() { 64 Calendar c = Calendar.getInstance(); 65 c.setTime(new Date (val)); 66 return c; 67 } 68 69 public long getTime() { return val; } 70 71 public String toString() { return Long.toString(val); } 72 73 public Value unop(int op) throws ValueException { 74 switch (op) { 75 case Op.NULL: 76 return ValueBoolean.falseBoolean; 77 default: 78 throw new ValueException("Unary op: " + Op.toString(op) + 79 " not implemented for this type"); 80 } 81 } 82 83 public abstract Value binop(int op, Value l) throws ValueException; 84 85 public Value binop(int op, ValueNull r) throws ValueException { 86 switch (op) { 87 case Op.EQ: 88 case Op.NE: 89 case Op.LT: 90 case Op.LE: 91 case Op.GT: 92 case Op.GE: 93 return ValueUnknown.valueUnknown; 94 case Op.COMPARE: 95 return r.valCmpNull(); 96 default: 97 throw badBinop(op, r); 98 } 99 } 100 101 public Value binop(int op, ValueDate r) throws ValueException { 102 return ValueDateTime.binop(op, this, (ValueDateTime)r); 103 } 104 105 public Value binop(int op, ValueTime r) throws ValueException { 106 return ValueDateTime.binop(op, this, (ValueDateTime)r); 107 } 108 109 public Value binop(int op, ValueTimestamp r) throws ValueException { 110 return ValueDateTime.binop(op, this, (ValueDateTime)r); 111 } 112 113 public static final Value binop(int op, ValueDateTime e, ValueDateTime f) 114 throws ValueException 115 { 116 switch (op) { 117 case Op.EQ: 118 return new ValueBoolean(e.val == f.val); 119 case Op.GE: 120 return new ValueBoolean(e.val >= f.val); 121 case Op.GT: 122 return new ValueBoolean(e.val > f.val); 123 case Op.LE: 124 return new ValueBoolean(e.val <= f.val); 125 case Op.LT: 126 return new ValueBoolean(e.val < f.val); 127 case Op.NE: 128 return new ValueBoolean(e.val != f.val); 129 case Op.COMPARE: 130 if (e.val < f.val) return ValueInteger.MINUS_ONE; 131 if (e.val > f.val) return ValueInteger.PLUS_ONE; 132 return ValueInteger.ZERO; 133 default: 134 throw badBinop(op, e, f); 135 } 136 } 137 138 public void readExternal(ObjectInput in) 139 throws IOException , ClassNotFoundException 140 { 141 val = in.readLong(); 142 } 143 144 public void writeExternal(ObjectOutput out) 145 throws IOException 146 { 147 out.writeLong(val); 148 } 149 150 public Object asJavaObject() { 151 return null; 152 } 153 154 abstract public Type getType(); 155 156 157 public void serializeKey(KeyStream out) throws IOException { 158 out.writeLong(val); 159 } 160 } 161 | Popular Tags |