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.HsqlException; 41 import org.hsqldb.Trace; 42 import org.hsqldb.Types; 43 import org.hsqldb.lib.HsqlByteArrayInputStream; 44 import org.hsqldb.types.Binary; 45 46 56 public abstract class RowInputBase extends HsqlByteArrayInputStream { 57 58 static final int NO_POS = -1; 59 60 protected int filePos = NO_POS; 62 protected int size; 63 64 public RowInputBase() { 65 this(new byte[4]); 66 } 67 68 71 public RowInputBase(byte[] buf) { 72 73 super(buf); 74 75 size = buf.length; 76 } 77 78 public int getPos() { 79 80 if (filePos == NO_POS) { 81 82 } 84 85 return (filePos); 86 } 87 88 public int getSize() { 89 return size; 90 } 91 92 public abstract int readIntData() throws IOException ; 94 95 public abstract long readLongData() throws IOException ; 96 97 public abstract int readType() throws IOException ; 98 99 public abstract String readString() throws IOException ; 100 101 protected abstract boolean checkNull() throws IOException ; 103 104 protected abstract String readChar(int type) 105 throws IOException , HsqlException; 106 107 protected abstract Integer readSmallint() 108 throws IOException , HsqlException; 109 110 protected abstract Integer readInteger() 111 throws IOException , HsqlException; 112 113 protected abstract Long readBigint() throws IOException , HsqlException; 114 115 protected abstract Double readReal(int type) 116 throws IOException , HsqlException; 117 118 protected abstract BigDecimal readDecimal() 119 throws IOException , HsqlException; 120 121 protected abstract Boolean readBit() throws IOException , HsqlException; 122 123 protected abstract Time readTime() throws IOException , HsqlException; 124 125 protected abstract Date readDate() throws IOException , HsqlException; 126 127 protected abstract Timestamp readTimestamp() 128 throws IOException , HsqlException; 129 130 protected abstract Object readOther() throws IOException , HsqlException; 131 132 protected abstract Binary readBinary(int type) 133 throws IOException , HsqlException; 134 135 143 public Object [] readData(int[] colTypes) 144 throws IOException , HsqlException { 145 146 int l = colTypes.length; 147 Object [] data = new Object [l]; 148 Object o; 149 int type; 150 151 for (int i = 0; i < l; i++) { 152 if (checkNull()) { 153 continue; 154 } 155 156 o = null; 157 type = colTypes[i]; 158 159 switch (type) { 160 161 case Types.NULL : 162 case Types.CHAR : 163 case Types.VARCHAR : 164 case Types.VARCHAR_IGNORECASE : 165 case Types.LONGVARCHAR : 166 o = readChar(type); 167 break; 168 169 case Types.TINYINT : 170 case Types.SMALLINT : 171 o = readSmallint(); 172 break; 173 174 case Types.INTEGER : 175 o = readInteger(); 176 break; 177 178 case Types.BIGINT : 179 o = readBigint(); 180 break; 181 182 case Types.REAL : 185 case Types.FLOAT : 186 case Types.DOUBLE : 187 o = readReal(type); 188 break; 189 190 case Types.NUMERIC : 191 case Types.DECIMAL : 192 o = readDecimal(); 193 break; 194 195 case Types.DATE : 196 o = readDate(); 197 break; 198 199 case Types.TIME : 200 o = readTime(); 201 break; 202 203 case Types.TIMESTAMP : 204 o = readTimestamp(); 205 break; 206 207 case Types.BOOLEAN : 208 o = readBit(); 209 break; 210 211 case Types.OTHER : 212 o = readOther(); 213 break; 214 215 case Types.BINARY : 216 case Types.VARBINARY : 217 case Types.LONGVARBINARY : 218 o = readBinary(type); 219 break; 220 221 default : 222 throw Trace.runtimeError( 223 Trace.UNSUPPORTED_INTERNAL_OPERATION, 224 "RowInputBase " + Types.getTypeString(type)); 225 } 226 227 data[i] = o; 228 } 229 230 return data; 231 } 232 233 238 public void resetRow(int filepos, int rowsize) throws IOException { 239 240 mark = 0; 241 242 reset(); 243 244 if (buf.length < rowsize) { 245 buf = new byte[rowsize]; 246 } 247 248 filePos = filepos; 249 size = count = rowsize; 250 pos = 4; 251 buf[0] = (byte) ((rowsize >>> 24) & 0xFF); 252 buf[1] = (byte) ((rowsize >>> 16) & 0xFF); 253 buf[2] = (byte) ((rowsize >>> 8) & 0xFF); 254 buf[3] = (byte) ((rowsize >>> 0) & 0xFF); 255 } 256 257 public byte[] getBuffer() { 258 return buf; 259 } 260 261 public int skipBytes(int n) throws IOException { 262 throw Trace.runtimeError(Trace.UNSUPPORTED_INTERNAL_OPERATION, 263 "RowInputBase"); 264 } 265 266 public String readLine() throws IOException { 267 throw Trace.runtimeError(Trace.UNSUPPORTED_INTERNAL_OPERATION, 268 "RowInputBase"); 269 } 270 } 271 | Popular Tags |