1 package in.co.daffodil.db.jdbc; 2 3 import java.sql.*; 4 import com.daffodilwoods.database.resource.*; 5 import java.io.BufferedWriter ; 6 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype; 8 import in.co.daffodil.db.general.*; 9 import com.daffodilwoods.database.utility.*; 10 11 27 28 public class DaffodilDBResultSetMetaData 29 implements ResultSetMetaData { 30 31 static final int intType = 0; 32 static final int stringType = 1; 33 static final int imageType = 2; 34 static final int memoType = 3; 35 static final int realType = 4; 36 37 private _ColumnCharacteristics columnCharacteristics; 38 private DaffodilDBConnection connection; 39 40 DaffodilDBResultSetMetaData(DaffodilDBConnection con) { 41 connection = con; 42 } 43 44 45 void setColumnCharacteristics(_ColumnCharacteristics columnChar) { 46 columnCharacteristics = columnChar; 47 } 48 49 public int getColumnIndex(String name) throws SQLException { 50 try { 51 return columnCharacteristics.getColumnIndex(name) + 52 DaffodilDBDriver.COLUMN_OFFSET; 53 } 54 catch (DException e) { 55 throw e.getSqlException(connection.getLocale()); 56 } 57 } 58 59 65 public int getColumnCount() throws SQLException { 66 try { 67 return columnCharacteristics.getColumnCount(); 68 } 69 catch (DException e) { 70 throw e.getSqlException(connection.getLocale()); 71 } 72 } 73 74 81 public boolean isAutoIncrement(int index) throws SQLException { 82 checkValidColumn(index); 83 try { 84 return columnCharacteristics.isAutoIncrement(index - 85 DaffodilDBDriver.COLUMN_OFFSET); 86 } 87 catch (DException e) { 88 throw e.getSqlException(connection.getLocale()); 89 } 90 } 91 92 99 public boolean isCaseSensitive(int index) throws SQLException { 100 checkValidColumn(index); 101 return false; 102 } 103 104 111 public boolean isSearchable(int index) throws SQLException { 112 checkValidColumn(index); 113 try { 114 int type = columnCharacteristics.getColumnType(index - 115 DaffodilDBDriver.COLUMN_OFFSET); 116 int dataType = getDataType(type); 117 return! (dataType == memoType || dataType == imageType); 118 } 119 catch (DException e) { 120 throw e.getSqlException(connection.getLocale()); 121 } 122 } 123 124 131 public boolean isCurrency(int index) throws SQLException { 132 checkValidColumn(index); 133 return false; 134 } 135 136 144 public int isNullable(int index) throws SQLException { 145 checkValidColumn(index); 146 try { 147 int nullableValue = columnCharacteristics.isNullable(index - 148 DaffodilDBDriver.COLUMN_OFFSET); 149 return nullableValue == -1 ? columnNullableUnknown : nullableValue; 150 } 151 catch (DException e) { 152 throw e.getSqlException(connection.getLocale()); 153 } 154 } 155 156 178 179 public boolean isSigned(int index) throws SQLException { 180 checkValidColumn(index); 181 try { 182 int type = columnCharacteristics.getColumnType(index - 183 DaffodilDBDriver.COLUMN_OFFSET); 184 int dataType = getDataType(type); 185 return dataType == realType || dataType == intType; 186 } 187 catch (DException e) { 188 throw e.getSqlException(connection.getLocale()); 189 } 190 } 191 192 200 public int getColumnDisplaySize(int index) throws SQLException { 201 checkValidColumn(index); 202 try { 203 int size = columnCharacteristics.getSize(index - 204 DaffodilDBDriver.COLUMN_OFFSET); 205 int precision = columnCharacteristics.getPrecision(index - 206 DaffodilDBDriver.COLUMN_OFFSET); 207 return Utilities.getDispalySize(getColumnType(index), precision, size); 208 } 209 catch (DException e) { 210 throw e.getSqlException(connection.getLocale()); 211 } 212 } 213 214 222 public String getColumnLabel(int index) throws SQLException { 223 checkValidColumn(index); 224 try { 225 return columnCharacteristics.getColumnLabel(index - 226 DaffodilDBDriver.COLUMN_OFFSET); 227 } 228 catch (DException e) { 229 throw e.getSqlException(connection.getLocale()); 230 } 231 } 232 233 240 public String getColumnName(int index) throws SQLException { 241 checkValidColumn(index); 242 try { 243 return columnCharacteristics.getColumnName(index - 244 DaffodilDBDriver.COLUMN_OFFSET); 245 } 246 catch (DException e) { 247 throw e.getSqlException(connection.getLocale()); 248 } 249 } 250 251 258 public String getSchemaName(int index) throws SQLException { 259 checkValidColumn(index); 260 try { 261 return columnCharacteristics.getSchemaName(index - 262 DaffodilDBDriver.COLUMN_OFFSET); 263 } 264 catch (DException e) { 265 throw e.getSqlException(connection.getLocale()); 266 } 267 } 268 269 276 public int getPrecision(int index) throws SQLException { 277 checkValidColumn(index); 278 try { 279 return columnCharacteristics.getPrecision(index - 280 DaffodilDBDriver.COLUMN_OFFSET); 281 } 282 catch (DException e) { 283 throw e.getSqlException(connection.getLocale()); 284 } 285 } 286 287 294 public int getScale(int index) throws SQLException { 295 checkValidColumn(index); 296 try { 297 return columnCharacteristics.getScale(index - 298 DaffodilDBDriver.COLUMN_OFFSET); 299 } 300 catch (DException e) { 301 throw e.getSqlException(connection.getLocale()); 302 } 303 } 304 305 312 public String getTableName(int index) throws SQLException { 313 checkValidColumn(index); 314 try { 315 return columnCharacteristics.getTableName(index - 316 DaffodilDBDriver.COLUMN_OFFSET); 317 } 318 catch (DException e) { 319 throw e.getSqlException(connection.getLocale()); 320 } 321 } 322 323 331 public String getCatalogName(int index) throws SQLException { 332 checkValidColumn(index); 333 try { 334 return columnCharacteristics.getCatalogName(index - 335 DaffodilDBDriver. 336 COLUMN_OFFSET); 337 } 338 catch (DException e) { 339 throw e.getSqlException(connection.getLocale()); 340 } 341 } 342 343 351 public int getColumnType(int index) throws SQLException { 352 checkValidColumn(index); 353 try { 354 int dataType = columnCharacteristics.getColumnType(index - 355 DaffodilDBDriver.COLUMN_OFFSET); 356 int type = Utilities.getCorrespondingSqlTypeOfDatabaseType(dataType); 357 return type; 358 } 359 catch (DException e) { 360 throw e.getSqlException(connection.getLocale()); 361 } 362 } 363 364 372 public String getColumnTypeName(int index) throws SQLException { 373 checkValidColumn(index); 374 try { 375 int type = columnCharacteristics.getColumnType(index - 376 DaffodilDBDriver.COLUMN_OFFSET); 377 return Utilities.getDataBaseTypeName(type); 378 } 379 catch (DException e) { 380 throw e.getSqlException(connection.getLocale()); 381 } 382 } 383 384 391 public boolean isReadOnly(int index) throws SQLException { 392 checkValidColumn(index); 393 return false; 394 } 395 396 403 public boolean isWritable(int index) throws SQLException { 404 checkValidColumn(index); 405 return true; 406 } 407 408 415 public boolean isDefinitelyWritable(int index) throws SQLException { 416 checkValidColumn(index); 417 return true; 418 } 419 420 424 425 440 441 public String getColumnClassName(int index) throws SQLException { 442 checkValidColumn(index); 443 int sqlType = getColumnType(index); 444 return Utilities.getCorrespondingJavaClassesOfSqlTypes(sqlType); 445 } 446 447 451 452 private int getDataType(int databaseType) { 453 switch (databaseType) { 454 case Datatype.TIME: 455 case Datatype.TIMESTAMP: 456 case Datatype.DATE: 457 case Datatype.BOOLEAN: 458 case Datatype.CHARACTER: 459 return stringType; 460 461 case Datatype.BYTE: 462 case Datatype.INTEGER: 463 case Datatype.MODULE: 464 case Datatype.RECORD: 465 case Datatype.LONG: 466 case Datatype.SHORT: 467 return intType; 468 469 case Datatype.BIGDECIMAL: 470 case Datatype.FLOAT: 471 case Datatype.SUM: 472 case Datatype.DOUBLE: 473 return realType; 474 475 case Datatype.BLOB: 476 return imageType; 477 478 case Datatype.ARRAY: 479 case Datatype.REF: 480 case Datatype.STRUCT: 481 case Datatype.CLOB: 482 return memoType; 483 } 484 return memoType; 485 } 486 487 private void checkValidColumn(int columnIndex) throws SQLException { 488 if (columnIndex < 1 || columnIndex > getColumnCount()) { 489 DException dex = new DException("DSE505", 490 new Object [] {new Integer (columnIndex)}); 491 throw dex.getSqlException(connection.getLocale()); 492 } 493 } 494 } 495 | Popular Tags |