1 28 29 package com.caucho.amber.query; 30 31 import com.caucho.amber.type.*; 32 33 36 public class QueryArgs { 37 private Type []_argTypes; 38 private Object []_argValues; 39 40 public QueryArgs(int length) 41 { 42 _argTypes = new Type[length]; 43 _argValues = new Object [length]; 44 } 45 46 49 Type []getArgTypes() 50 { 51 return _argTypes; 52 } 53 54 57 Object []getArgValues() 58 { 59 return _argValues; 60 } 61 62 65 public void setString(int index, String v) 66 { 67 _argTypes[index - 1] = StringType.create(); 68 _argValues[index - 1] = v; 69 } 70 71 74 public void setByte(int index, byte v) 75 { 76 _argTypes[index - 1] = ByteType.create(); 77 _argValues[index - 1] = new Integer (v); 78 } 79 80 83 public void setShort(int index, short v) 84 { 85 _argTypes[index - 1] = ShortType.create(); 86 _argValues[index - 1] = new Integer (v); 87 } 88 89 92 public void setInt(int index, int v) 93 { 94 _argTypes[index - 1] = IntegerType.create(); 95 _argValues[index - 1] = new Integer (v); 96 } 97 98 101 public void setLong(int index, long v) 102 { 103 _argTypes[index - 1] = LongType.create(); 104 _argValues[index - 1] = new Long (v); 105 } 106 107 110 public void setDouble(int index, double v) 111 { 112 _argTypes[index - 1] = DoubleType.create(); 113 _argValues[index - 1] = new Double (v); 114 } 115 116 119 public void setTimestamp(int index, java.sql.Timestamp v) 120 { 121 _argTypes[index - 1] = SqlTimestampType.create(); 122 _argValues[index - 1] = v; 123 } 124 125 128 public void setDate(int index, java.sql.Date v) 129 { 130 _argTypes[index - 1] = SqlDateType.create(); 131 _argValues[index - 1] = v; 132 } 133 134 137 public void setNull(int index, int v) 138 { 139 _argTypes[index - 1] = StringType.create(); 140 _argValues[index - 1] = null; 141 } 142 143 146 public int hashCode() 147 { 148 int hash = 37; 149 150 for (int i = _argValues.length - 1; i >= 0; i--) { 151 Object v = _argValues[i]; 152 153 if (v != null) 154 hash = 31 * hash + v.hashCode(); 155 else 156 hash = 31 * hash + 17; 157 } 158 159 return hash; 160 } 161 162 165 public boolean equals(Object o) 166 { 167 if (! (o instanceof QueryArgs)) 168 return false; 169 170 QueryArgs args = (QueryArgs) o; 171 172 if (_argValues.length != args._argValues.length) 173 return false; 174 175 for (int i = _argValues.length - 1; i >= 0; i--) { 176 Object a = args._argValues[i]; 177 Object b = _argValues[i]; 178 179 if (a != b && (a == null || ! a.equals(b))) 180 return false; 181 } 182 183 return true; 184 } 185 186 public String toString() 187 { 188 return "QueryArgs[]"; 189 } 190 } 191 | Popular Tags |