1 23 24 package org.continuent.sequoia.common.protocol; 25 26 import java.io.IOException ; 27 import java.io.Serializable ; 28 29 import org.continuent.sequoia.common.stream.DriverBufferedInputStream; 30 import org.continuent.sequoia.common.stream.DriverBufferedOutputStream; 31 import org.continuent.sequoia.driver.ResultSetMetaData; 32 33 46 public class Field implements Serializable 47 { 48 61 private static final long serialVersionUID = 1050843622547803111L; 62 63 private String tableName; 64 private String fieldName; 65 private String fieldLabel; 66 private int columnDisplaySize; 67 private int sqlType; 68 private String typeName; 69 private String columnClassName; 70 private boolean isAutoIncrement; 71 private boolean isCaseSensitive; 72 private boolean isCurrency; 73 private int isNullable; 74 private boolean isReadOnly; 75 private boolean isWritable; 76 private boolean isDefinitelyWritable; 77 private boolean isSearchable; 78 private boolean isSigned; 79 private int precision; 80 private int scale; 81 private String encoding; 82 83 93 public Field(String table, String columnName, int columnDisplaySize, 94 int sqlType, String typeName, String columnClassName) 95 { 96 this(table, columnName, columnName, columnDisplaySize, sqlType, typeName, 97 columnClassName, false, true, false, ResultSetMetaData.columnNullable, 98 true, false, false, false, false, 0, 0, null); 99 } 100 101 125 public Field(String table, String columnName, String columnLabel, 126 int columnDisplaySize, int sqlType, String typeName, 127 String columnClassName, boolean isAutoIncrement, boolean isCaseSensitive, 128 boolean isCurrency, int isNullable, boolean isReadOnly, 129 boolean isWritable, boolean isDefinitelyWritable, boolean isSearchable, 130 boolean isSigned, int precision, int scale, String encoding) 131 { 132 this.tableName = table; 133 this.fieldName = columnName; 134 this.fieldLabel = columnLabel; 135 this.columnDisplaySize = columnDisplaySize; 136 this.sqlType = sqlType; 137 this.typeName = typeName; 138 this.columnClassName = columnClassName; 139 this.isAutoIncrement = isAutoIncrement; 140 this.isCaseSensitive = isCaseSensitive; 141 this.isCurrency = isCurrency; 142 this.isNullable = isNullable; 143 this.isReadOnly = isReadOnly; 144 this.isWritable = isWritable; 145 this.isDefinitelyWritable = isDefinitelyWritable; 146 this.isSearchable = isSearchable; 147 this.isSigned = isSigned; 148 this.precision = precision; 149 this.scale = scale; 150 this.encoding = encoding; 151 } 152 153 160 public Field(DriverBufferedInputStream in) throws IOException 161 { 162 if (in.readBoolean()) 163 this.tableName = in.readLongUTF(); 164 else 165 this.tableName = null; 166 167 this.fieldName = in.readLongUTF(); 168 this.fieldLabel = in.readLongUTF(); 169 this.columnDisplaySize = in.readInt(); 170 this.sqlType = in.readInt(); 171 this.typeName = in.readLongUTF(); 172 this.columnClassName = in.readLongUTF(); 173 this.isAutoIncrement = in.readBoolean(); 174 this.isCaseSensitive = in.readBoolean(); 175 this.isCurrency = in.readBoolean(); 176 this.isNullable = in.readInt(); 177 this.isReadOnly = in.readBoolean(); 178 this.isWritable = in.readBoolean(); 179 this.isDefinitelyWritable = in.readBoolean(); 180 this.isSearchable = in.readBoolean(); 181 this.isSigned = in.readBoolean(); 182 this.precision = in.readInt(); 183 this.scale = in.readInt(); 184 this.encoding = in.readLongUTF(); 185 } 186 187 195 public void sendToStream(DriverBufferedOutputStream out) throws IOException 196 { 197 if (null == this.tableName) 198 out.writeBoolean(false); 199 else 200 { 201 out.writeBoolean(true); 202 out.writeLongUTF(this.tableName); 203 } 204 205 out.writeLongUTF(this.fieldName); 206 out.writeLongUTF(this.fieldLabel); 207 out.writeInt(this.columnDisplaySize); 208 out.writeInt(this.sqlType); 209 out.writeLongUTF(this.typeName); 210 out.writeLongUTF(this.columnClassName); 211 out.writeBoolean(this.isAutoIncrement); 212 out.writeBoolean(this.isCaseSensitive); 213 out.writeBoolean(this.isCurrency); 214 out.writeInt(this.isNullable); 215 out.writeBoolean(this.isReadOnly); 216 out.writeBoolean(this.isWritable); 217 out.writeBoolean(this.isDefinitelyWritable); 218 out.writeBoolean(this.isSearchable); 219 out.writeBoolean(this.isSigned); 220 out.writeInt(this.precision); 221 out.writeInt(this.scale); 222 out.writeLongUTF(this.encoding); 223 224 } 225 226 231 public final String getFieldLabel() 232 { 233 return fieldLabel; 234 } 235 236 241 public String getFieldName() 242 { 243 return fieldName; 244 } 245 246 251 public String getFullName() 252 { 253 return tableName + "." + fieldName; 254 } 255 256 259 public int getPrecision() 260 { 261 return precision; 262 } 263 264 267 public int getScale() 268 { 269 return scale; 270 } 271 272 278 public int getSqlType() 279 { 280 return sqlType; 281 } 282 283 288 public String getTableName() 289 { 290 return tableName; 291 } 292 293 299 public String getTypeName() 300 { 301 return typeName; 302 } 303 304 309 public String getColumnClassName() 310 { 311 return columnClassName; 312 } 313 314 317 public int getColumnDisplaySize() 318 { 319 return columnDisplaySize; 320 } 321 322 325 public String getEncoding() 326 { 327 return encoding; 328 } 329 330 333 public boolean isAutoIncrement() 334 { 335 return isAutoIncrement; 336 } 337 338 341 public boolean isCaseSensitive() 342 { 343 return isCaseSensitive; 344 } 345 346 349 public boolean isCurrency() 350 { 351 return isCurrency; 352 } 353 354 357 public boolean isDefinitelyWritable() 358 { 359 return isDefinitelyWritable; 360 } 361 362 365 public int isNullable() 366 { 367 return isNullable; 368 } 369 370 373 public boolean isReadOnly() 374 { 375 return isReadOnly; 376 } 377 378 381 public boolean isSearchable() 382 { 383 return isSearchable; 384 } 385 386 389 public boolean isSigned() 390 { 391 return isSigned; 392 } 393 394 397 public boolean isWritable() 398 { 399 return isWritable; 400 } 401 402 408 public String toString() 409 { 410 return getFullName(); 411 } 412 413 } | Popular Tags |