1 5 package org.h2.jdbc; 6 7 import java.sql.ResultSetMetaData ; 8 import java.sql.SQLException ; 9 10 import org.h2.message.*; 11 import org.h2.message.TraceObject; 12 import org.h2.result.ResultInterface; 13 import org.h2.util.MathUtils; 14 import org.h2.value.DataType; 15 16 19 public class JdbcResultSetMetaData extends TraceObject implements ResultSetMetaData { 20 21 private JdbcResultSet rs; 22 private ResultInterface result; 23 24 30 public int getColumnCount() throws SQLException { 31 try { 32 debugCodeCall("getColumnCount"); 33 checkClosed(); 34 return result.getVisibleColumnCount(); 35 } catch(Throwable e) { 36 throw logAndConvert(e); 37 } 38 } 39 40 47 public String getColumnLabel(int column) throws SQLException { 48 try { 49 debugCodeCall("getColumnLabel", column); 50 rs.checkColumnIndex(column); 51 return result.getAlias(--column); 52 } catch(Throwable e) { 53 throw logAndConvert(e); 54 } 55 } 56 57 64 public String getColumnName(int column) throws SQLException { 65 try { 66 debugCodeCall("getColumnName", column); 67 rs.checkColumnIndex(column); 68 return result.getColumnName(--column); 69 } catch(Throwable e) { 70 throw logAndConvert(e); 71 } 72 } 73 74 81 public int getColumnType(int column) throws SQLException { 82 try { 83 debugCodeCall("getColumnType", column); 84 rs.checkColumnIndex(column); 85 int type = result.getColumnType(--column); 86 return DataType.convertTypeToSQLType(type); 87 } catch(Throwable e) { 88 throw logAndConvert(e); 89 } 90 } 91 92 99 public String getColumnTypeName(int column) throws SQLException { 100 try { 101 debugCodeCall("getColumnTypeName", column); 102 rs.checkColumnIndex(column); 103 int type = result.getColumnType(--column); 104 return DataType.getDataType(type).name; 105 } catch(Throwable e) { 106 throw logAndConvert(e); 107 } 108 } 109 110 117 public String getSchemaName(int column) throws SQLException { 118 try { 119 debugCodeCall("getSchemaName", column); 120 rs.checkColumnIndex(column); 121 return result.getSchemaName(--column); 122 } catch(Throwable e) { 123 throw logAndConvert(e); 124 } 125 } 126 127 134 public String getTableName(int column) throws SQLException { 135 try { 136 debugCodeCall("getTableName", column); 137 rs.checkColumnIndex(column); 138 return result.getTableName(--column); 139 } catch(Throwable e) { 140 throw logAndConvert(e); 141 } 142 } 143 144 151 public String getCatalogName(int column) throws SQLException { 152 try { 153 debugCodeCall("getCatalogName", column); 154 rs.checkColumnIndex(column); 155 return rs.getConnection().getCatalog(); 156 } catch(Throwable e) { 157 throw logAndConvert(e); 158 } 159 } 160 161 169 public boolean isAutoIncrement(int column) throws SQLException { 170 try { 171 debugCodeCall("isAutoIncrement", column); 172 rs.checkColumnIndex(column); 173 return result.isAutoIncrement(--column); 174 } catch(Throwable e) { 175 throw logAndConvert(e); 176 } 177 } 178 179 187 public boolean isCaseSensitive(int column) throws SQLException { 188 try { 189 debugCodeCall("isCaseSensitive", column); 190 rs.checkColumnIndex(column); 191 return true; 192 } catch(Throwable e) { 193 throw logAndConvert(e); 194 } 195 } 196 197 205 public boolean isSearchable(int column) throws SQLException { 206 try { 207 debugCodeCall("isSearchable", column); 208 rs.checkColumnIndex(column); 209 return true; 210 } catch(Throwable e) { 211 throw logAndConvert(e); 212 } 213 } 214 215 223 public boolean isCurrency(int column) throws SQLException { 224 try { 225 debugCodeCall("isCurrency", column); 226 rs.checkColumnIndex(column); 227 return false; 228 } catch(Throwable e) { 229 throw logAndConvert(e); 230 } 231 } 232 233 243 public int isNullable(int column) throws SQLException { 244 try { 245 debugCodeCall("isNullable", column); 246 rs.checkColumnIndex(column); 247 return result.getNullable(--column); 248 } catch(Throwable e) { 249 throw logAndConvert(e); 250 } 251 } 252 253 261 public boolean isSigned(int column) throws SQLException { 262 try { 263 debugCodeCall("isSigned", column); 264 rs.checkColumnIndex(column); 265 return true; 266 } catch(Throwable e) { 267 throw logAndConvert(e); 268 } 269 } 270 271 279 public boolean isReadOnly(int column) throws SQLException { 280 try { 281 debugCodeCall("isReadOnly", column); 282 rs.checkColumnIndex(column); 283 return false; 284 } catch(Throwable e) { 285 throw logAndConvert(e); 286 } 287 } 288 289 297 public boolean isWritable(int column) throws SQLException { 298 try { 299 debugCodeCall("isWritable", column); 300 rs.checkColumnIndex(column); 301 return true; 302 } catch(Throwable e) { 303 throw logAndConvert(e); 304 } 305 } 306 307 315 public boolean isDefinitelyWritable(int column) throws SQLException { 316 try { 317 debugCodeCall("isDefinitelyWritable", column); 318 rs.checkColumnIndex(column); 319 return false; 320 } catch(Throwable e) { 321 throw logAndConvert(e); 322 } 323 } 324 325 333 public String getColumnClassName(int column) throws SQLException { 334 try { 335 debugCodeCall("getColumnClassName", column); 336 rs.checkColumnIndex(column); 337 int type = result.getColumnType(--column); 338 return DataType.getTypeClassName(type); 339 } catch(Throwable e) { 340 throw logAndConvert(e); 341 } 342 } 343 344 352 public int getPrecision(int column) throws SQLException { 353 try { 354 debugCodeCall("getPrecision", column); 355 rs.checkColumnIndex(column); 356 long prec = result.getColumnPrecision(--column); 357 return MathUtils.convertLongToInt(prec); 358 } catch(Throwable e) { 359 throw logAndConvert(e); 360 } 361 } 362 363 371 public int getScale(int column) throws SQLException { 372 try { 373 debugCodeCall("getScale", column); 374 rs.checkColumnIndex(column); 375 return result.getColumnScale(--column); 376 } catch(Throwable e) { 377 throw logAndConvert(e); 378 } 379 } 380 381 388 public int getColumnDisplaySize(int column) throws SQLException { 389 try { 390 debugCodeCall("getColumnDisplaySize", column); 391 rs.checkColumnIndex(column); 392 return result.getDisplaySize(--column); 393 } catch(Throwable e) { 394 throw logAndConvert(e); 395 } 396 } 397 398 JdbcResultSetMetaData(JdbcResultSet rs, ResultInterface result, Trace trace, int id) { 399 setTrace(trace, TraceObject.RESULT_SET_META_DATA, id); 400 this.rs = rs; 401 this.result = result; 402 } 403 404 void checkClosed() throws SQLException { 405 rs.checkClosed(); 406 } 407 408 412 419 421 425 432 434 } 435 | Popular Tags |