1 21 22 package org.apache.derby.impl.jdbc; 23 24 import org.apache.derby.iapi.sql.ResultDescription; 25 import org.apache.derby.iapi.sql.ResultColumnDescriptor; 26 import org.apache.derby.iapi.types.DataTypeDescriptor; 27 import org.apache.derby.iapi.types.DataTypeUtilities; 28 import org.apache.derby.iapi.types.TypeId; 29 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 32 import org.apache.derby.iapi.reference.SQLState; 33 34 import java.sql.ResultSetMetaData ; 35 import java.sql.SQLException ; 36 import java.sql.Types ; 37 import java.sql.ResultSet ; 38 39 53 public class EmbedResultSetMetaData 54 implements ResultSetMetaData { 55 56 private final ResultColumnDescriptor[] columnInfo; 57 58 public EmbedResultSetMetaData(ResultColumnDescriptor[] columnInfo) { 62 this.columnInfo = columnInfo; 63 } 64 65 69 74 public int getColumnCount() { 75 return columnInfo == null ? 0 : columnInfo.length; 76 } 77 78 86 public boolean isAutoIncrement(int column) throws SQLException { 87 88 ResultColumnDescriptor rcd = columnInfo[column - 1]; 89 return rcd.isAutoincrement(); 90 } 91 92 99 public boolean isCaseSensitive(int column) throws SQLException { 100 return DataTypeUtilities.isCaseSensitive(getColumnTypeDescriptor(column)); 101 } 102 103 104 111 public boolean isSearchable(int column) throws SQLException { 112 validColumnNumber(column); 113 114 return true; 117 } 118 119 126 public boolean isCurrency(int column) throws SQLException { 127 128 return DataTypeUtilities.isCurrency(getColumnTypeDescriptor(column)); 129 } 130 131 138 public int isNullable(int column) throws SQLException { 139 return DataTypeUtilities.isNullable(getColumnTypeDescriptor(column)); 140 } 141 142 149 public boolean isSigned(int column) throws SQLException { 150 return DataTypeUtilities.isSigned(getColumnTypeDescriptor(column)); 151 } 152 153 154 161 public int getColumnDisplaySize(int column) throws SQLException { 162 return DataTypeUtilities.getColumnDisplaySize(getColumnTypeDescriptor(column)); 163 } 164 165 173 public String getColumnLabel(int column) throws SQLException { 174 ResultColumnDescriptor cd = columnInfo[column - 1]; 175 String s = cd.getName(); 176 177 return (s==null? "Column"+Integer.toString(column) : s); 179 } 180 181 182 189 public String getColumnName(int column) throws SQLException { 190 ResultColumnDescriptor cd = columnInfo[column - 1]; 191 String s = cd.getName(); 192 return (s==null? "" : s); 194 195 } 196 197 198 205 public String getSchemaName(int column) throws SQLException { 206 ResultColumnDescriptor cd = columnInfo[column - 1]; 207 208 String s = cd.getSourceSchemaName(); 209 return (s==null? "" : s); 211 } 212 213 220 public int getPrecision(int column) throws SQLException { 221 return DataTypeUtilities.getDigitPrecision(getColumnTypeDescriptor(column)); 222 } 223 224 225 232 public int getScale(int column) throws SQLException { 233 DataTypeDescriptor dtd = getColumnTypeDescriptor(column); 234 return dtd.getScale(); 236 } 237 238 244 public String getTableName(int column) throws SQLException { 245 ResultColumnDescriptor cd = columnInfo[column - 1]; 246 String s = cd.getSourceTableName(); 247 248 return (s==null? "" : s); 250 } 251 252 259 public String getCatalogName(int column) throws SQLException { 260 validColumnNumber(column); 261 return ""; 262 } 263 264 272 public int getColumnType(int column) throws SQLException { 273 DataTypeDescriptor dtd = getColumnTypeDescriptor(column); 274 return dtd.getTypeId().getJDBCTypeId(); 275 } 276 277 284 public String getColumnTypeName(int column) throws SQLException { 285 DataTypeDescriptor dtd = getColumnTypeDescriptor(column); 286 return dtd.getTypeId().getSQLTypeName(); 287 } 288 289 296 public boolean isReadOnly(int column) throws SQLException { 297 validColumnNumber(column); 298 299 return false; 301 } 302 303 310 public boolean isWritable(int column) throws SQLException { 311 validColumnNumber(column); 312 return columnInfo[column - 1].updatableByCursor(); 313 } 314 315 322 public boolean isDefinitelyWritable(int column) throws SQLException { 323 validColumnNumber(column); 324 325 return false; 327 } 328 329 332 333 private void validColumnNumber(int column) throws SQLException { 334 if (column < 1 || 335 column > getColumnCount() ) 336 throw Util.generateCsSQLException( 337 SQLState.COLUMN_NOT_FOUND, new Integer (column)); 338 } 339 340 public DataTypeDescriptor getColumnTypeDescriptor(int column) throws SQLException 341 { 342 validColumnNumber(column); 343 344 ResultColumnDescriptor cd = columnInfo[column - 1]; 345 346 return cd.getType(); 347 } 348 349 355 365 public String getColumnClassName(int column) throws SQLException { 366 367 return getColumnTypeDescriptor(column).getTypeId().getResultSetMetaDataTypeName(); 368 } 369 370 371 public static ResultColumnDescriptor getResultColumnDescriptor(String name, int jdcbTypeId, boolean nullable) { 372 373 return new org.apache.derby.impl.sql.GenericColumnDescriptor( 374 name, DataTypeDescriptor.getBuiltInDataTypeDescriptor(jdcbTypeId, nullable)); 375 } 376 public static ResultColumnDescriptor getResultColumnDescriptor(String name, int jdcbTypeId, boolean nullable, int length) { 377 378 return new org.apache.derby.impl.sql.GenericColumnDescriptor( 379 name, DataTypeDescriptor.getBuiltInDataTypeDescriptor(jdcbTypeId, nullable, length)); 380 } 381 public static ResultColumnDescriptor getResultColumnDescriptor(String name, DataTypeDescriptor dtd) { 382 return new org.apache.derby.impl.sql.GenericColumnDescriptor(name, dtd); 383 } 384 } 385 | Popular Tags |