1 33 package smallsql.database; 34 35 36 abstract class Expression implements Cloneable { 37 38 static final Expression NULL = new ExpressionValue( null, SQLTokenizer.NULL ); 39 40 final private int type; 41 private String name; private String alias; 43 44 51 private Expression[] params; 52 53 Expression(int type){ 54 this.type = type; 55 } 56 57 protected Object clone() throws CloneNotSupportedException { 58 return super.clone(); 59 } 60 61 final String getName(){ 62 return name; 63 } 64 65 final void setName(String name){ 66 this.alias = this.name = name; 67 } 68 69 final String getAlias(){ 70 return alias; 71 } 72 73 final void setAlias(String alias){ 74 this.alias = alias; 75 } 76 77 void setParams( Expression[] params ){ 78 this.params = params; 79 } 80 81 85 void setParamAt( Expression param, int idx){ 86 params[idx] = param; 87 } 88 89 final Expression[] getParams(){ return params; } 90 91 94 public boolean equals(Object expr){ 95 if(!(expr instanceof Expression)) return false; 96 if( ((Expression)expr).type == type){ 97 98 Expression[] p1 = ((Expression)expr).params; 99 Expression[] p2 = params; 100 if(p1 != null && p2 != null){ 101 if(p1 == null) return false; 102 for(int i=0; i<p1.length; i++){ 103 if(!p2[i].equals(p1[i])) return false; 104 } 105 } 106 String name1 = ((Expression)expr).name; 107 String name2 = name; 108 if(name1 == name2) return true; 109 if(name1 == null) return false; 110 if(name1.equalsIgnoreCase(name2)) return true; 111 } 112 return false; 113 } 114 115 116 abstract boolean isNull() throws Exception ; 117 118 abstract boolean getBoolean() throws Exception ; 119 120 abstract int getInt() throws Exception ; 121 122 abstract long getLong() throws Exception ; 123 124 abstract float getFloat() throws Exception ; 125 126 abstract double getDouble() throws Exception ; 127 128 abstract long getMoney() throws Exception ; 129 130 abstract MutableNumeric getNumeric() throws Exception ; 131 132 abstract Object getObject() throws Exception ; 133 134 final Object getApiObject() throws Exception { 135 Object obj = getObject(); 136 if(obj instanceof Mutable){ 137 return ((Mutable)obj).getImmutableObject(); 138 } 139 return obj; 140 } 141 142 abstract String getString() throws Exception ; 143 144 abstract byte[] getBytes() throws Exception ; 145 146 abstract int getDataType(); 147 148 final int getType(){return type;} 149 150 155 156 String getTableName(){ 157 return null; 158 } 159 160 161 int getPrecision(){ 162 return SSResultSetMetaData.getDataTypePrecision( getDataType(), -1 ); 163 } 164 165 166 167 int getScale(){ 168 return getScale(getDataType()); 169 } 170 171 172 final static int getScale(int dataType){ 173 switch(dataType){ 174 case SQLTokenizer.MONEY: 175 case SQLTokenizer.SMALLMONEY: 176 return 4; 177 case SQLTokenizer.TIMESTAMP: 178 return 9; case SQLTokenizer.NUMERIC: 180 case SQLTokenizer.DECIMAL: 181 return 38; 182 default: return 0; 183 } 184 } 185 186 187 int getDisplaySize(){ 188 return SSResultSetMetaData.getDisplaySize(getDataType(), getPrecision(), getScale()); 189 } 190 191 boolean isDefinitelyWritable(){ 192 return false; 193 } 194 195 boolean isAutoIncrement(){ 196 return false; 197 } 198 199 boolean isCaseSensitive(){ 200 return false; } 202 203 boolean isNullable(){ 204 return true; } 206 207 208 static final int VALUE = 1; 209 static final int NAME = 2; 210 static final int FUNCTION = 3; 211 static final int GROUP_BY = 11; 212 static final int COUNT = 12; 213 static final int SUM = 13; 214 static final int FIRST = 14; 215 static final int LAST = 15; 216 static final int MIN = 16; 217 static final int MAX = 17; 218 static final int GROUP_BEGIN= GROUP_BY; 219 220 } | Popular Tags |