1 30 31 32 package org.hsqldb.rowio; 33 34 import java.math.BigDecimal ; 35 import java.sql.Date ; 36 import java.sql.Time ; 37 import java.sql.Timestamp ; 38 39 import org.hsqldb.Column; 40 import org.hsqldb.Table; 41 import org.hsqldb.Trace; 42 import org.hsqldb.Types; 43 import org.hsqldb.lib.HashMappedList; 44 import org.hsqldb.lib.HsqlByteArrayOutputStream; 45 import org.hsqldb.types.Binary; 46 import org.hsqldb.types.JavaObject; 47 48 58 public abstract class RowOutputBase extends HsqlByteArrayOutputStream 59 implements RowOutputInterface { 60 61 public static final int CACHED_ROW_160 = 0; 62 public static final int CACHED_ROW_170 = 1; 63 64 protected boolean skipSystemId = false; 66 67 72 public RowOutputBase() { 73 super(); 74 } 75 76 81 public RowOutputBase(int initialSize) { 82 super(initialSize); 83 } 84 85 90 public RowOutputBase(byte[] buffer) { 91 super(buffer); 92 } 93 94 public abstract void writeEnd(); 96 97 public abstract void writeSize(int size); 98 99 public abstract void writeType(int type); 100 101 public abstract void writeShortData(short i); 102 103 public abstract void writeIntData(int i); 104 105 public abstract void writeIntData(int i, int position); 106 107 public abstract void writeString(String s); 108 109 protected void writeFieldPrefix() {} 111 112 protected abstract void writeFieldType(int type); 113 114 protected abstract void writeNull(int type); 115 116 protected abstract void writeChar(String s, int t); 117 118 protected abstract void writeSmallint(Number o); 119 120 protected abstract void writeInteger(Number o); 121 122 protected abstract void writeBigint(Number o); 123 124 protected abstract void writeReal(Double o, int type); 125 126 protected abstract void writeDecimal(BigDecimal o); 127 128 protected abstract void writeBit(Boolean o); 129 130 protected abstract void writeDate(Date o); 131 132 protected abstract void writeTime(Time o); 133 134 protected abstract void writeTimestamp(Timestamp o); 135 136 protected abstract void writeOther(JavaObject o); 137 138 protected abstract void writeBinary(Binary o, int t); 139 140 public void writeRow(Object [] data, Table t) { 141 142 writeSize(0); 143 writeData(data, t); 144 writeIntData(size(), 0); 145 } 146 147 154 public void writeData(Object [] data, Table t) { 155 156 int[] types = t.getColumnTypes(); 157 int l = t.getColumnCount(); 158 159 writeData(l, types, data, null, null); 160 } 161 162 172 public void writeData(int l, int[] types, Object [] data, 173 HashMappedList cols, int[] primaryKeys) { 174 175 boolean hasPK = primaryKeys != null && primaryKeys.length != 0; 176 int limit = hasPK ? primaryKeys.length 177 : l; 178 179 for (int i = 0; i < limit; i++) { 180 int j = hasPK ? primaryKeys[i] 181 : i; 182 Object o = data[j]; 183 int t = types[j]; 184 185 if (cols != null) { 186 Column col = (Column) cols.get(j); 187 188 writeFieldPrefix(); 189 writeString(col.columnName.statementName); 190 } 191 192 if (o == null) { 193 writeNull(t); 194 195 continue; 196 } 197 198 writeFieldType(t); 199 200 switch (t) { 201 202 case Types.NULL : 203 case Types.CHAR : 204 case Types.VARCHAR : 205 case Types.VARCHAR_IGNORECASE : 206 case Types.LONGVARCHAR : 207 writeChar((String ) o, t); 208 break; 209 210 case Types.TINYINT : 211 case Types.SMALLINT : 212 writeSmallint((Number ) o); 213 break; 214 215 case Types.INTEGER : 216 writeInteger((Number ) o); 217 break; 218 219 case Types.BIGINT : 220 writeBigint((Number ) o); 221 break; 222 223 case Types.REAL : 224 case Types.FLOAT : 225 case Types.DOUBLE : 226 writeReal((Double ) o, t); 227 break; 228 229 case Types.NUMERIC : 230 case Types.DECIMAL : 231 writeDecimal((BigDecimal ) o); 232 break; 233 234 case Types.BOOLEAN : 235 writeBit((Boolean ) o); 236 break; 237 238 case Types.DATE : 239 writeDate((Date ) o); 240 break; 241 242 case Types.TIME : 243 writeTime((Time ) o); 244 break; 245 246 case Types.TIMESTAMP : 247 writeTimestamp((Timestamp ) o); 248 break; 249 250 case Types.OTHER : 251 writeOther((JavaObject) o); 252 break; 253 254 case Types.BINARY : 255 case Types.VARBINARY : 256 case Types.LONGVARBINARY : 257 writeBinary((Binary) o, t); 258 break; 259 260 default : 261 throw Trace.runtimeError(Trace.FUNCTION_NOT_SUPPORTED, 262 Types.getTypeString(t)); 263 } 264 } 265 } 266 267 public HsqlByteArrayOutputStream getOutputStream() { 269 return this; 270 } 271 } 272 | Popular Tags |