1 30 31 32 package org.hsqldb.rowio; 33 34 import java.io.IOException ; 35 import java.math.BigDecimal ; 36 import java.sql.Date ; 37 import java.sql.Time ; 38 import java.sql.Timestamp ; 39 40 import org.hsqldb.Column; 41 import org.hsqldb.HsqlDateTime; 42 import org.hsqldb.HsqlException; 43 import org.hsqldb.Token; 44 import org.hsqldb.Tokenizer; 45 import org.hsqldb.Types; 46 import org.hsqldb.scriptio.ScriptReaderBase; 47 import org.hsqldb.store.ValuePool; 48 import org.hsqldb.types.Binary; 49 import org.hsqldb.types.JavaObject; 50 import org.hsqldb.lib.java.JavaSystem; 51 52 59 public class RowInputTextLog extends RowInputBase 60 implements RowInputInterface { 61 62 Tokenizer tokenizer; 63 String tableName = null; 64 String schemaName = null; 65 int statementType; 66 67 public RowInputTextLog() { 68 69 super(new byte[0]); 70 71 tokenizer = new Tokenizer(); 72 } 73 74 public void setSource(String text) throws HsqlException { 75 76 tokenizer.reset(text); 77 78 statementType = ScriptReaderBase.ANY_STATEMENT; 79 80 String s = tokenizer.getString(); 81 82 if (s.equals(Token.T_INSERT)) { 83 statementType = ScriptReaderBase.INSERT_STATEMENT; 84 85 tokenizer.getString(); 86 87 tableName = tokenizer.getString(); 88 89 tokenizer.getString(); 90 } else if (s.equals(Token.T_DELETE)) { 91 statementType = ScriptReaderBase.DELETE_STATEMENT; 92 93 tokenizer.getString(); 94 95 tableName = tokenizer.getString(); 96 } else if (s.equals(Token.T_COMMIT)) { 97 statementType = ScriptReaderBase.COMMIT_STATEMENT; 98 } else if (s.equals(Token.T_SET)) { 99 if (tokenizer.isGetThis(Token.T_SCHEMA)) { 100 schemaName = tokenizer.getSimpleName(); 101 statementType = ScriptReaderBase.SCHEMA_STATEMENT; 102 } 103 } 104 } 105 106 public int getStatementType() { 107 return statementType; 108 } 109 110 public String getTableName() { 111 return tableName; 112 } 113 114 public String getSchemaName() { 115 return schemaName; 116 } 117 118 protected String readField() throws IOException { 119 120 try { 121 tokenizer.getString(); 122 123 if (statementType == ScriptReaderBase.DELETE_STATEMENT) { 124 tokenizer.getString(); 125 tokenizer.getString(); 126 } 127 128 String s = tokenizer.getString(); 129 130 if (tokenizer.getType() == Types.NULL) { 131 s = null; 132 } 133 134 return s; 135 } catch (HsqlException e) { 136 throw new IOException (e.getMessage()); 137 } 138 } 139 140 protected String readNumberField() throws IOException { 141 142 try { 143 tokenizer.getString(); 144 145 if (statementType == ScriptReaderBase.DELETE_STATEMENT) { 146 tokenizer.getString(); 147 tokenizer.getString(); 148 } 149 150 String s = tokenizer.getString(); 151 152 if ("-".equals(s)) { 153 s = s + tokenizer.getString(); 154 } else if (tokenizer.getType() == Types.NULL) { 155 s = null; 156 } 157 158 return s; 159 } catch (HsqlException e) { 160 throw new IOException (e.getMessage()); 161 } 162 } 163 164 public String readString() throws IOException { 165 166 String s = readField(); 167 168 return ValuePool.getString(s); 169 } 170 171 public short readShortData() throws IOException { 172 173 String s = readNumberField(); 174 175 if (s == null) { 176 return 0; 177 } 178 179 return Short.parseShort(s); 180 } 181 182 public int readIntData() throws IOException { 183 184 String s = readNumberField(); 185 186 if (s == null) { 187 return 0; 188 } 189 190 return Integer.parseInt(s); 191 } 192 193 public long readLongData() throws IOException { 194 195 String s = readNumberField(); 196 197 if (s == null) { 198 return 0; 199 } 200 201 return Long.parseLong(s); 202 } 203 204 public int readType() throws IOException { 205 return 0; 206 } 207 208 protected boolean checkNull() { 209 210 return false; 212 } 213 214 protected String readChar(int type) throws IOException { 215 return readString(); 216 } 217 218 protected Integer readSmallint() throws IOException , HsqlException { 219 220 String s = readNumberField(); 221 222 if (s == null) { 223 return null; 224 } 225 226 int i = Integer.parseInt(s); 227 228 return ValuePool.getInt(i); 229 } 230 231 protected Integer readInteger() throws IOException , HsqlException { 232 233 String s = readNumberField(); 234 235 if (s == null) { 236 return null; 237 } 238 239 int i = Integer.parseInt(s); 240 241 return ValuePool.getInt(i); 242 } 243 244 protected Long readBigint() throws IOException , HsqlException { 245 246 String s = readNumberField(); 247 248 if (s == null) { 249 return null; 250 } 251 252 long i = Long.parseLong(s); 253 254 return ValuePool.getLong(i); 255 } 256 257 protected Double readReal(int type) throws IOException , HsqlException { 258 259 String s = readNumberField(); 260 261 if (s == null) { 262 return null; 263 } 264 265 double i = JavaSystem.parseDouble(s); 266 267 if (tokenizer.isGetThis(Token.T_DIVIDE)) { 268 s = tokenizer.getString(); 269 270 double ii = JavaSystem.parseDouble(s); 272 273 if (i == 0E0) { 274 i = Double.NaN; 275 } else if (i == -1E0) { 276 i = Double.NEGATIVE_INFINITY; 277 } else if (i == 1E0) { 278 i = Double.POSITIVE_INFINITY; 279 } 280 } 281 282 return ValuePool.getDouble(Double.doubleToLongBits(i)); 283 } 284 285 protected BigDecimal readDecimal() throws IOException , HsqlException { 286 287 String s = readNumberField(); 288 289 if (s == null) { 290 return null; 291 } 292 293 BigDecimal i = new BigDecimal (s); 294 295 return ValuePool.getBigDecimal(i); 296 } 297 298 protected Time readTime() throws IOException , HsqlException { 299 300 String s = readField(); 301 302 if (s == null) { 303 return null; 304 } 305 306 return HsqlDateTime.timeValue(s); 307 } 308 309 protected Date readDate() throws IOException , HsqlException { 310 311 String s = readField(); 312 313 if (s == null) { 314 return null; 315 } 316 317 return HsqlDateTime.dateValue(s); 318 } 319 320 protected Timestamp readTimestamp() throws IOException , HsqlException { 321 322 String s = readField(); 323 324 if (s == null) { 325 return null; 326 } 327 328 return HsqlDateTime.timestampValue(s); 329 } 330 331 protected Boolean readBit() throws IOException , HsqlException { 332 333 String s = readField(); 334 335 if (s == null) { 336 return null; 337 } 338 339 return s.equalsIgnoreCase("TRUE") ? Boolean.TRUE 340 : Boolean.FALSE; 341 } 342 343 protected Object readOther() throws IOException , HsqlException { 344 345 byte[] data; 346 String s = readField(); 347 348 if (s == null) { 349 return null; 350 } 351 352 data = Column.hexToByteArray(s); 353 354 return new JavaObject(data); 355 } 356 357 protected Binary readBinary(int type) throws IOException , HsqlException { 358 359 String s = readField(); 360 361 if (s == null) { 362 return null; 363 } 364 365 return new Binary(Column.hexToByteArray(s), false); 366 } 367 } 368 | Popular Tags |