1 28 29 package com.caucho.db.table; 30 31 import com.caucho.db.index.BTree; 32 import com.caucho.db.sql.Expr; 33 import com.caucho.db.sql.QueryContext; 34 import com.caucho.db.sql.SelectResult; 35 import com.caucho.db.store.Transaction; 36 37 import java.sql.SQLException ; 38 39 42 class LongColumn extends Column { 43 49 LongColumn(Row row, String name) 50 { 51 super(row, name); 52 } 53 54 57 public int getTypeCode() 58 { 59 return LONG; 60 } 61 62 65 public Class getJavaType() 66 { 67 return long.class; 68 } 69 70 73 public int getDeclarationSize() 74 { 75 return 8; 76 } 77 78 81 public int getLength() 82 { 83 return 8; 84 } 85 86 93 void setString(Transaction xa, byte []block, int rowOffset, String str) 94 { 95 if (str == null) 96 setNull(block, rowOffset); 97 else 98 setLong(xa, block, rowOffset, Long.parseLong(str)); 99 } 100 101 107 public String getString(byte []block, int rowOffset) 108 { 109 if (isNull(block, rowOffset)) 110 return null; 111 else 112 return String.valueOf(getLong(block, rowOffset)); 113 } 114 115 122 void setInteger(Transaction xa, byte []block, int rowOffset, int value) 123 { 124 setLong(xa, block, rowOffset, value); 125 } 126 127 133 public int getInteger(byte []block, int rowOffset) 134 { 135 return (int) getLong(block, rowOffset); 136 } 137 138 145 void setLong(Transaction xa, byte []block, int rowOffset, long value) 146 { 147 int offset = rowOffset + _columnOffset; 148 149 block[offset++] = (byte) (value >> 56); 150 block[offset++] = (byte) (value >> 48); 151 block[offset++] = (byte) (value >> 40); 152 block[offset++] = (byte) (value >> 32); 153 block[offset++] = (byte) (value >> 24); 154 block[offset++] = (byte) (value >> 16); 155 block[offset++] = (byte) (value >> 8); 156 block[offset++] = (byte) (value); 157 158 setNonNull(block, rowOffset); 159 } 160 161 167 public long getLong(byte []block, int rowOffset) 168 { 169 if (isNull(block, rowOffset)) 170 return 0; 171 172 int offset = rowOffset + _columnOffset; 173 long value = 0; 174 175 value = (block[offset++] & 0xffL) << 56; 176 value |= (block[offset++] & 0xffL) << 48; 177 value |= (block[offset++] & 0xffL) << 40; 178 value |= (block[offset++] & 0xffL) << 32; 179 value |= (block[offset++] & 0xffL) << 24; 180 value |= (block[offset++] & 0xffL) << 16; 181 value |= (block[offset++] & 0xffL) << 8; 182 value |= (block[offset++] & 0xffL); 183 184 return value; 185 } 186 187 194 void setExpr(Transaction xa, 195 byte []block, int rowOffset, 196 Expr expr, QueryContext context) 197 throws SQLException 198 { 199 if (expr.isNull(null)) 200 setNull(block, rowOffset); 201 else 202 setLong(xa, block, rowOffset, expr.evalLong(context)); 203 } 204 205 208 public void evalToResult(byte []block, int rowOffset, SelectResult result) 209 { 210 if (isNull(block, rowOffset)) { 211 result.writeNull(); 212 return; 213 } 214 215 result.writeLong(getLong(block, rowOffset)); 216 } 217 218 228 int evalToBuffer(byte []block, int rowOffset, 229 byte []buffer, int bufferOffset) 230 throws SQLException 231 { 232 if (isNull(block, rowOffset)) 233 return 0; 234 235 int startOffset = rowOffset + _columnOffset; 236 int len = 8; 237 238 System.arraycopy(block, startOffset, buffer, bufferOffset, len); 239 240 return len; 241 } 242 243 246 public boolean isEqual(byte []block1, int rowOffset1, 247 byte []block2, int rowOffset2) 248 { 249 if (isNull(block1, rowOffset1) != isNull(block2, rowOffset2)) 250 return false; 251 252 int startOffset1 = rowOffset1 + _columnOffset; 253 int startOffset2 = rowOffset2 + _columnOffset; 254 255 return (block1[startOffset1 + 0] == block2[startOffset2 + 0] && 256 block1[startOffset1 + 1] == block2[startOffset2 + 1] && 257 block1[startOffset1 + 2] == block2[startOffset2 + 2] && 258 block1[startOffset1 + 3] == block2[startOffset2 + 3] && 259 block1[startOffset1 + 4] == block2[startOffset2 + 4] && 260 block1[startOffset1 + 5] == block2[startOffset2 + 5] && 261 block1[startOffset1 + 6] == block2[startOffset2 + 6] && 262 block1[startOffset1 + 7] == block2[startOffset2 + 7]); 263 } 264 265 272 void setIndex(Transaction xa, 273 byte []block, int rowOffset, 274 long rowAddr, QueryContext context) 275 throws SQLException 276 { 277 BTree index = getIndex(); 278 279 if (index == null) 280 return; 281 282 index.insert(block, rowOffset + _columnOffset, 8, rowAddr, xa, false); 283 } 284 285 288 public void set(TableIterator iter, Expr expr, QueryContext context) 289 throws SQLException 290 { 291 iter.setDirty(); 292 setLong(iter.getTransaction(), 293 iter.getBuffer(), iter.getRowOffset(), expr.evalLong(context)); 294 } 295 296 303 void delete(Transaction xa, byte []block, int rowOffset) 304 throws SQLException 305 { 306 BTree index = getIndex(); 307 308 if (index != null) 309 index.remove(block, rowOffset + _columnOffset, 8, xa); 310 } 311 } 312 | Popular Tags |