1. /*
  2. * @(#)RowSetMetaDataImpl.java 1.7 04/05/29
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.sql.rowset;
  8. import java.sql.*;
  9. import javax.sql.*;
  10. import java.io.*;
  11. import java.lang.reflect.*;
  12. /**
  13. * Provides implementations for the methods that set and get
  14. * metadata information about a <code>RowSet</code> object's columns.
  15. * A <code>RowSetMetaDataImpl</code> object keeps track of the
  16. * number of columns in the rowset and maintains an internal array
  17. * of column attributes for each column.
  18. * <P>
  19. * A <code>RowSet</code> object creates a <code>RowSetMetaDataImpl</code>
  20. * object internally in order to set and retrieve information about
  21. * its columns.
  22. * <P>
  23. * NOTE: All metadata in a <code>RowSetMetaDataImpl</code> object
  24. * should be considered as unavailable until the <code>RowSet</code> object
  25. * that it describes is populated.
  26. * Therefore, any <code>RowSetMetaDataImpl</code> method that retrieves information
  27. * is defined as having unspecified behavior when it is called
  28. * before the <code>RowSet</code> object contains data.
  29. */
  30. public class RowSetMetaDataImpl implements RowSetMetaData, Serializable {
  31. /**
  32. * The number of columns in the <code>RowSet</code> object that created
  33. * this <code>RowSetMetaDataImpl</code> object.
  34. * @serial
  35. */
  36. private int colCount;
  37. /**
  38. * An array of <code>ColInfo</code> objects used to store information
  39. * about each column in the <code>RowSet</code> object for which
  40. * this <code>RowSetMetaDataImpl</code> object was created. The first
  41. * <code>ColInfo</code> object in this array contains information about
  42. * the first column in the <code>RowSet</code> object, the second element
  43. * contains information about the second column, and so on.
  44. * @serial
  45. */
  46. private ColInfo[] colInfo;
  47. /**
  48. * Checks to see that the designated column is a valid column number for
  49. * the <code>RowSet</code> object for which this <code>RowSetMetaDataImpl</code>
  50. * was created. To be valid, a column number must be greater than
  51. * <code>0</code> and less than or equal to the number of columns in a row.
  52. * @throws <code>SQLException</code> with the message "Invalid column index"
  53. * if the given column number is out of the range of valid column
  54. * numbers for the <code>RowSet</code> object
  55. */
  56. private void checkColRange(int col) throws SQLException {
  57. if (col <= 0 || col > colCount) {
  58. throw new SQLException("Invalid column index :"+col);
  59. }
  60. }
  61. /**
  62. * Checks to see that the given SQL type is a valid column type and throws an
  63. * <code>SQLException</code> object if it is not.
  64. * To be valid, a SQL type must be one of the constant values
  65. * in the <code><a href="../../sql/Types.html">java.sql.Types</a></code>
  66. * class.
  67. *
  68. * @param SQLType an <code>int</code> defined in the class <code>java.sql.Types</code>
  69. * @throws SQLException if the given <code>int</code> is not a constant defined in the
  70. * class <code>java.sql.Types</code>
  71. */
  72. private void checkColType(int SQLType) throws SQLException {
  73. try {
  74. Class c = java.sql.Types.class;
  75. Field[] publicFields = c.getFields();
  76. int fieldValue = 0;
  77. for (int i = 0; i < publicFields.length; i++) {
  78. fieldValue = publicFields[i].getInt(c);
  79. if (fieldValue == SQLType) {
  80. return;
  81. }
  82. }
  83. } catch (Exception e) {
  84. throw new SQLException(e.getMessage());
  85. }
  86. throw new SQLException("Invalid SQL type for column");
  87. }
  88. /**
  89. * Sets to the given number the number of columns in the <code>RowSet</code>
  90. * object for which this <code>RowSetMetaDataImpl</code> object was created.
  91. *
  92. * @param columnCount an <code>int</code> giving the number of columns in the
  93. * <code>RowSet</code> object
  94. * @throws SQLException if the given number is equal to or less than zero
  95. */
  96. public void setColumnCount(int columnCount) throws SQLException {
  97. if (columnCount <= 0) {
  98. throw new SQLException("Invalid column count. Cannot be less " +
  99. "or equal to zero");
  100. }
  101. colCount = columnCount;
  102. // If the colCount is Integer.MAX_VALUE,
  103. // we do not initialize the colInfo object.
  104. // even if we try to initialize the colCount with
  105. // colCount = Integer.MAx_VALUE-1, the colInfo
  106. // initialization fails throwing an ERROR
  107. // OutOfMemory Exception. So we do not initialize
  108. // colInfo at Integer.MAX_VALUE. This is to pass TCK.
  109. if(!(colCount == Integer.MAX_VALUE)) {
  110. colInfo = new ColInfo[colCount + 1];
  111. for (int i=1; i <= colCount; i++) {
  112. colInfo[i] = new ColInfo();
  113. }
  114. }
  115. }
  116. /**
  117. * Sets whether the designated column is automatically
  118. * numbered, thus read-only, to the given <code>boolean</code>
  119. * value.
  120. *
  121. * @param columnIndex the first column is 1, the second is 2, and so on;
  122. * must be between <code>1</code> and the number of columns
  123. * in the rowset, inclusive
  124. * @param property <code>true</code> if the given column is
  125. * automatically incremented; <code>false</code>
  126. * otherwise
  127. * @throws <code>SQLException</code> if a database access error occurs or
  128. * the given index is out of bounds
  129. */
  130. public void setAutoIncrement(int columnIndex, boolean property) throws SQLException {
  131. checkColRange(columnIndex);
  132. colInfo[columnIndex].autoIncrement = property;
  133. }
  134. /**
  135. * Sets whether the name of the designated column is case sensitive to
  136. * the given <code>boolean</code>.
  137. *
  138. * @param columnIndex the first column is 1, the second is 2, and so on;
  139. * must be between <code>1</code> and the number of columns
  140. * in the rowset, inclusive
  141. * @param property <code>true</code> to indicate that the column
  142. * name is case sensitive; <code>false</code> otherwise
  143. * @throws SQLException if a database access error occurs or
  144. * the given column number is out of bounds
  145. */
  146. public void setCaseSensitive(int columnIndex, boolean property) throws SQLException {
  147. checkColRange(columnIndex);
  148. colInfo[columnIndex].caseSensitive = property;
  149. }
  150. /**
  151. * Sets whether a value stored in the designated column can be used
  152. * in a <code>WHERE</code> clause to the given <code>boolean</code> value.
  153. *
  154. * @param columnIndex the first column is 1, the second is 2, and so on;
  155. * must be between <code>1</code> and the number
  156. * of columns in the rowset, inclusive
  157. * @param property <code>true</code> to indicate that a column
  158. * value can be used in a <code>WHERE</code> clause;
  159. * <code>false</code> otherwise
  160. *
  161. * @throws <code>SQLException</code> if a database access error occurs or
  162. * the given column number is out of bounds
  163. */
  164. public void setSearchable(int columnIndex, boolean property)
  165. throws SQLException {
  166. checkColRange(columnIndex);
  167. colInfo[columnIndex].searchable = property;
  168. }
  169. /**
  170. * Sets whether a value stored in the designated column is a cash
  171. * value to the given <code>boolean</code>.
  172. *
  173. * @param columnIndex the first column is 1, the second is 2, and so on;
  174. * must be between <code>1</code> and the number of columns,
  175. * inclusive between <code>1</code> and the number of columns, inclusive
  176. * @param property true if the value is a cash value; false otherwise.
  177. * @throws <code>SQLException</code> if a database access error occurs
  178. * or the given column number is out of bounds
  179. */
  180. public void setCurrency(int columnIndex, boolean property)
  181. throws SQLException {
  182. checkColRange(columnIndex);
  183. colInfo[columnIndex].currency = property;
  184. }
  185. /**
  186. * Sets whether a value stored in the designated column can be set
  187. * to <code>NULL</code> to the given constant from the interface
  188. * <code>ResultSetMetaData</code>.
  189. *
  190. * @param columnIndex the first column is 1, the second is 2, and so on;
  191. * must be between <code>1</code> and the number of columns, inclusive
  192. * @param property one of the following <code>ResultSetMetaData</code> constants:
  193. * <code>columnNoNulls</code>,
  194. * <code>columnNullable</code>, or
  195. * <code>columnNullableUnknown</code>
  196. *
  197. * @throws <code>SQLException</code> if a database access error occurs,
  198. * the given column number is out of bounds, or the value supplied
  199. * for the <i>property</i> parameter is not one of the following
  200. * constants:
  201. * <code>ResultSetMetaData.columnNoNulls</code>,
  202. * <code>ResultSetMetaData.columnNullable</code>, or
  203. * <code>ResultSetMetaData.columnNullableUnknown</code>
  204. */
  205. public void setNullable(int columnIndex, int property) throws SQLException {
  206. if ((property < ResultSetMetaData.columnNoNulls) ||
  207. property > ResultSetMetaData.columnNullableUnknown) {
  208. throw new SQLException("Invalid nullable constant set. Must be " +
  209. "either columnNoNulls, columnNullable or columnNullableUnknown");
  210. }
  211. checkColRange(columnIndex);
  212. colInfo[columnIndex].nullable = property;
  213. }
  214. /**
  215. * Sets whether a value stored in the designated column is a signed
  216. * number to the given <code>boolean</code>.
  217. *
  218. * @param columnIndex the first column is 1, the second is 2, and so on;
  219. * must be between <code>1</code> and the number of columns, inclusive
  220. * @param property <code>true</code> to indicate that a column
  221. * value is a signed number;
  222. * <code>false</code> to indicate that it is not
  223. * @throws SQLException if a database access error occurs
  224. * or the given column number is out of bounds
  225. */
  226. public void setSigned(int columnIndex, boolean property) throws SQLException {
  227. checkColRange(columnIndex);
  228. colInfo[columnIndex].signed = property;
  229. }
  230. /**
  231. * Sets the normal maximum number of chars in the designated column
  232. * to the given number.
  233. *
  234. * @param columnIndex the first column is 1, the second is 2, and so on;
  235. * must be between <code>1</code> and the number of columns, inclusive
  236. * @param size the maximum size of the column in chars; must be
  237. * <code>0</code> or more
  238. * @throws SQLException if a database access error occurs,
  239. * the given column number is out of bounds, or <i>size</i> is
  240. * less than <code>0</code>
  241. */
  242. public void setColumnDisplaySize(int columnIndex, int size) throws SQLException {
  243. if (size < 0) {
  244. throw new SQLException("Invalid column display size. Cannot be less " +
  245. "than zero");
  246. }
  247. checkColRange(columnIndex);
  248. colInfo[columnIndex].columnDisplaySize = size;
  249. }
  250. /**
  251. * Sets the suggested column label for use in printouts and
  252. * displays, if any, to <i>label</i>. If <i>label</i> is
  253. * <code>null</code>, the column label is set to an empty string
  254. * ("").
  255. *
  256. * @param columnIndex the first column is 1, the second is 2, and so on;
  257. * must be between <code>1</code> and the number of columns, inclusive
  258. * @param label the column label to be used in printouts and displays; if the
  259. * column label is <code>null</code>, an empty <code>String</code> is
  260. * set
  261. * @throws SQLException if a database access error occurs
  262. * or the given column index is out of bounds
  263. */
  264. public void setColumnLabel(int columnIndex, String label) throws SQLException {
  265. checkColRange(columnIndex);
  266. if (label != null) {
  267. colInfo[columnIndex].columnLabel = new String(label);
  268. } else {
  269. colInfo[columnIndex].columnLabel = new String("");
  270. }
  271. }
  272. /**
  273. * Sets the column name of the designated column to the given name.
  274. *
  275. * @param columnIndex the first column is 1, the second is 2, and so on;
  276. * must be between <code>1</code> and the number of columns, inclusive
  277. * @param columnName a <code>String</code> object indicating the column name;
  278. * if the given name is <code>null</code>, an empty <code>String</code>
  279. * is set
  280. * @throws SQLException if a database access error occurs or the given column
  281. * index is out of bounds
  282. */
  283. public void setColumnName(int columnIndex, String columnName) throws SQLException {
  284. checkColRange(columnIndex);
  285. if (columnName != null) {
  286. colInfo[columnIndex].columnName = new String(columnName);
  287. } else {
  288. colInfo[columnIndex].columnName = new String("");
  289. }
  290. }
  291. /**
  292. * Sets the designated column's table's schema name, if any, to
  293. * <i>schemaName</i>. If <i>schemaName</i> is <code>null</code>,
  294. * the schema name is set to an empty string ("").
  295. *
  296. * @param columnIndex the first column is 1, the second is 2, and so on;
  297. * must be between <code>1</code> and the number of columns, inclusive
  298. * @param schemaName the schema name for the table from which a value in the
  299. * designated column was derived; may be an empty <code>String</code>
  300. * or <code>null</code>
  301. * @throws SQLException if a database access error occurs
  302. * or the given column number is out of bounds
  303. */
  304. public void setSchemaName(int columnIndex, String schemaName) throws SQLException {
  305. checkColRange(columnIndex);
  306. if (schemaName != null ) {
  307. colInfo[columnIndex].schemaName = new String(schemaName);
  308. } else {
  309. colInfo[columnIndex].schemaName = new String("");
  310. }
  311. }
  312. /**
  313. * Sets the total number of decimal digits in a value stored in the
  314. * designated column to the given number.
  315. *
  316. * @param columnIndex the first column is 1, the second is 2, and so on;
  317. * must be between <code>1</code> and the number of columns, inclusive
  318. * @param precision the total number of decimal digits; must be <code>0</code>
  319. * or more
  320. * @throws SQLException if a database access error occurs,
  321. * <i>columnIndex</i> is out of bounds, or <i>precision</i>
  322. * is less than <code>0</code>
  323. */
  324. public void setPrecision(int columnIndex, int precision) throws SQLException {
  325. if (precision < 0) {
  326. throw new SQLException("Invalid precision value. Cannot be less " +
  327. "than zero");
  328. }
  329. checkColRange(columnIndex);
  330. colInfo[columnIndex].colPrecision = precision;
  331. }
  332. /**
  333. * Sets the number of digits to the right of the decimal point in a value
  334. * stored in the designated column to the given number.
  335. *
  336. * @param columnIndex the first column is 1, the second is 2, and so on;
  337. * must be between <code>1</code> and the number of columns, inclusive
  338. * @param scale the number of digits to the right of the decimal point; must be
  339. * zero or greater
  340. * @throws SQLException if a database access error occurs,
  341. * <i>columnIndex</i> is out of bounds, or <i>scale</i>
  342. * is less than <code>0</code>
  343. */
  344. public void setScale(int columnIndex, int scale) throws SQLException {
  345. if (scale < 0) {
  346. throw new SQLException("Invalid scale size. Cannot be less " +
  347. "than zero");
  348. }
  349. checkColRange(columnIndex);
  350. colInfo[columnIndex].colScale = scale;
  351. }
  352. /**
  353. * Sets the name of the table from which the designated column
  354. * was derived to the given table name.
  355. *
  356. * @param columnIndex the first column is 1, the second is 2, and so on;
  357. * must be between <code>1</code> and the number of columns, inclusive
  358. * @param tableName the column's table name; may be <code>null</code> or an
  359. * empty string
  360. * @throws SQLException if a database access error occurs
  361. * or the given column number is out of bounds
  362. */
  363. public void setTableName(int columnIndex, String tableName) throws SQLException {
  364. checkColRange(columnIndex);
  365. if (tableName != null) {
  366. colInfo[columnIndex].tableName = new String(tableName);
  367. } else {
  368. colInfo[columnIndex].tableName = new String("");
  369. }
  370. }
  371. /**
  372. * Sets the catalog name of the table from which the designated
  373. * column was derived to <i>catalogName</i>. If <i>catalogName</i>
  374. * is <code>null</code>, the catalog name is set to an empty string.
  375. *
  376. * @param columnIndex the first column is 1, the second is 2, and so on;
  377. * must be between <code>1</code> and the number of columns, inclusive
  378. * @param catalogName the column's table's catalog name; if the catalogName
  379. * is <code>null</code>, an empty <code>String</code> is set
  380. * @throws SQLException if a database access error occurs
  381. * or the given column number is out of bounds
  382. */
  383. public void setCatalogName(int columnIndex, String catalogName) throws SQLException {
  384. checkColRange(columnIndex);
  385. if (catalogName != null)
  386. colInfo[columnIndex].catName = new String(catalogName);
  387. else
  388. colInfo[columnIndex].catName = new String("");
  389. }
  390. /**
  391. * Sets the SQL type code for values stored in the designated column
  392. * to the given type code from the class <code>java.sql.Types</code>.
  393. *
  394. * @param columnIndex the first column is 1, the second is 2, and so on;
  395. * must be between <code>1</code> and the number of columns, inclusive
  396. * @param SQLType the designated column's SQL type, which must be one of the
  397. * constants in the class <code>java.sql.Types</code>
  398. * @throws SQLException if a database access error occurs,
  399. * the given column number is out of bounds, or the column type
  400. * specified is not one of the constants in
  401. * <code>java.sql.Types</code>
  402. * @see java.sql.Types
  403. */
  404. public void setColumnType(int columnIndex, int SQLType) throws SQLException {
  405. // examine java.sql.Type reflectively, loop on the fields and check
  406. // this. Separate out into a private method
  407. checkColType(SQLType);
  408. checkColRange(columnIndex);
  409. colInfo[columnIndex].colType = SQLType;
  410. }
  411. /**
  412. * Sets the type name used by the data source for values stored in the
  413. * designated column to the given type name.
  414. *
  415. * @param columnIndex the first column is 1, the second is 2, and so on;
  416. * must be between <code>1</code> and the number of columns, inclusive
  417. * @param typeName the data source-specific type name; if <i>typeName</i> is
  418. * <code>null</code>, an empty <code>String</code> is set
  419. * @throws SQLException if a database access error occurs
  420. * or the given column number is out of bounds
  421. */
  422. public void setColumnTypeName(int columnIndex, String typeName)
  423. throws SQLException {
  424. checkColRange(columnIndex);
  425. if (typeName != null) {
  426. colInfo[columnIndex].colTypeName = new String(typeName);
  427. } else {
  428. colInfo[columnIndex].colTypeName = new String("");
  429. }
  430. }
  431. /**
  432. * Retrieves the number of columns in the <code>RowSet</code> object
  433. * for which this <code>RowSetMetaDataImpl</code> object was created.
  434. *
  435. * @return the number of columns
  436. * @throws SQLException if an error occurs determining the column count
  437. */
  438. public int getColumnCount() throws SQLException {
  439. return colCount;
  440. }
  441. /**
  442. * Retrieves whether a value stored in the designated column is
  443. * automatically numbered, and thus readonly.
  444. *
  445. * @param columnIndex the first column is 1, the second is 2, and so on;
  446. * must be between <code>1</code> and the number of columns, inclusive
  447. * @return <code>true</code> if the column is automatically numbered;
  448. * <code>false</code> otherwise
  449. * @throws SQLException if a database access error occurs
  450. * or the given column number is out of bounds
  451. */
  452. public boolean isAutoIncrement(int columnIndex) throws SQLException {
  453. checkColRange(columnIndex);
  454. return colInfo[columnIndex].autoIncrement;
  455. }
  456. /**
  457. * Indicates whether the case of the designated column's name
  458. * matters.
  459. *
  460. * @param columnIndex the first column is 1, the second is 2, and so on;
  461. * must be between <code>1</code> and the number of columns, inclusive
  462. * @return <code>true</code> if the column name is case sensitive;
  463. * <code>false</code> otherwise
  464. * @throws SQLException if a database access error occurs
  465. * or the given column number is out of bounds
  466. */
  467. public boolean isCaseSensitive(int columnIndex) throws SQLException {
  468. checkColRange(columnIndex);
  469. return colInfo[columnIndex].caseSensitive;
  470. }
  471. /**
  472. * Indicates whether a value stored in the designated column
  473. * can be used in a <code>WHERE</code> clause.
  474. *
  475. * @param columnIndex the first column is 1, the second is 2, and so on;
  476. * must be between <code>1</code> and the number of columns, inclusive
  477. * @return <code>true</code> if a value in the designated column can be used in a
  478. * <code>WHERE</code> clause; <code>false</code> otherwise
  479. * @throws SQLException if a database access error occurs
  480. * or the given column number is out of bounds
  481. */
  482. public boolean isSearchable(int columnIndex) throws SQLException {
  483. checkColRange(columnIndex);
  484. return colInfo[columnIndex].searchable;
  485. }
  486. /**
  487. * Indicates whether a value stored in the designated column
  488. * is a cash value.
  489. *
  490. * @param columnIndex the first column is 1, the second is 2, and so on;
  491. * must be between <code>1</code> and the number of columns, inclusive
  492. * @return <code>true</code> if a value in the designated column is a cash value;
  493. * <code>false</code> otherwise
  494. * @throws SQLException if a database access error occurs
  495. * or the given column number is out of bounds
  496. */
  497. public boolean isCurrency(int columnIndex) throws SQLException {
  498. checkColRange(columnIndex);
  499. return colInfo[columnIndex].currency;
  500. }
  501. /**
  502. * Retrieves a constant indicating whether it is possible
  503. * to store a <code>NULL</code> value in the designated column.
  504. *
  505. * @param columnIndex the first column is 1, the second is 2, and so on;
  506. * must be between <code>1</code> and the number of columns, inclusive
  507. * @return a constant from the <code>ResultSetMetaData</code> interface;
  508. * either <code>columnNoNulls</code>,
  509. * <code>columnNullable</code>, or
  510. * <code>columnNullableUnknown</code>
  511. * @throws SQLException if a database access error occurs
  512. * or the given column number is out of bounds
  513. */
  514. public int isNullable(int columnIndex) throws SQLException {
  515. checkColRange(columnIndex);
  516. return colInfo[columnIndex].nullable;
  517. }
  518. /**
  519. * Indicates whether a value stored in the designated column is
  520. * a signed number.
  521. *
  522. * @param columnIndex the first column is 1, the second is 2, and so on;
  523. * must be between <code>1</code> and the number of columns, inclusive
  524. * @return <code>true</code> if if a value in the designated column is a signed
  525. * number; <code>false</code> otherwise
  526. * @throws SQLException if a database access error occurs
  527. * or the given column number is out of bounds
  528. */
  529. public boolean isSigned(int columnIndex) throws SQLException {
  530. checkColRange(columnIndex);
  531. return colInfo[columnIndex].signed;
  532. }
  533. /**
  534. * Retrieves the normal maximum width in chars of the designated column.
  535. *
  536. * @param columnIndex the first column is 1, the second is 2, and so on;
  537. * must be between <code>1</code> and the number of columns, inclusive
  538. * @return the maximum number of chars that can be displayed in the designated
  539. * column
  540. * @throws SQLException if a database access error occurs
  541. * or the given column number is out of bounds
  542. */
  543. public int getColumnDisplaySize(int columnIndex) throws SQLException {
  544. checkColRange(columnIndex);
  545. return colInfo[columnIndex].columnDisplaySize;
  546. }
  547. /**
  548. * Retrieves the the suggested column title for the designated
  549. * column for use in printouts and displays.
  550. *
  551. * @param columnIndex the first column is 1, the second is 2, and so on;
  552. * must be between <code>1</code> and the number of columns, inclusive
  553. * @return the suggested column name to use in printouts and displays
  554. * @throws SQLException if a database access error occurs
  555. * or the given column number is out of bounds
  556. */
  557. public String getColumnLabel(int columnIndex) throws SQLException {
  558. checkColRange(columnIndex);
  559. return colInfo[columnIndex].columnLabel;
  560. }
  561. /**
  562. * Retrieves the name of the designated column.
  563. *
  564. * @param columnIndex the first column is 1, the second is 2, and so on;
  565. * must be between <code>1</code> and the number of columns, inclusive
  566. * @return the column name of the designated column
  567. * @throws SQLException if a database access error occurs
  568. * or the given column number is out of bounds
  569. */
  570. public String getColumnName(int columnIndex) throws SQLException {
  571. checkColRange(columnIndex);
  572. return colInfo[columnIndex].columnName;
  573. }
  574. /**
  575. * Retrieves the schema name of the table from which the value
  576. * in the designated column was derived.
  577. *
  578. * @param columnIndex the first column is 1, the second is 2, and so on;
  579. * must be between <code>1</code> and the number of columns,
  580. * inclusive
  581. * @return the schema name or an empty <code>String</code> if no schema
  582. * name is available
  583. * @throws SQLException if a database access error occurs
  584. * or the given column number is out of bounds
  585. */
  586. public String getSchemaName(int columnIndex) throws SQLException {
  587. checkColRange(columnIndex);
  588. String str ="";
  589. if(colInfo[columnIndex].schemaName == null){
  590. } else {
  591. str = colInfo[columnIndex].schemaName;
  592. }
  593. return str;
  594. }
  595. /**
  596. * Retrieves the total number of digits for values stored in
  597. * the designated column.
  598. *
  599. * @param columnIndex the first column is 1, the second is 2, and so on;
  600. * must be between <code>1</code> and the number of columns, inclusive
  601. * @return the precision for values stored in the designated column
  602. * @throws SQLException if a database access error occurs
  603. * or the given column number is out of bounds
  604. */
  605. public int getPrecision(int columnIndex) throws SQLException {
  606. checkColRange(columnIndex);
  607. return colInfo[columnIndex].colPrecision;
  608. }
  609. /**
  610. * Retrieves the number of digits to the right of the decimal point
  611. * for values stored in the designated column.
  612. *
  613. * @param columnIndex the first column is 1, the second is 2, and so on;
  614. * must be between <code>1</code> and the number of columns, inclusive
  615. * @return the scale for values stored in the designated column
  616. * @throws SQLException if a database access error occurs
  617. * or the given column number is out of bounds
  618. */
  619. public int getScale(int columnIndex) throws SQLException {
  620. checkColRange(columnIndex);
  621. return colInfo[columnIndex].colScale;
  622. }
  623. /**
  624. * Retrieves the name of the table from which the value
  625. * in the designated column was derived.
  626. *
  627. * @param columnIndex the first column is 1, the second is 2, and so on;
  628. * must be between <code>1</code> and the number of columns, inclusive
  629. * @return the table name or an empty <code>String</code> if no table name
  630. * is available
  631. * @throws SQLException if a database access error occurs
  632. * or the given column number is out of bounds
  633. */
  634. public String getTableName(int columnIndex) throws SQLException {
  635. checkColRange(columnIndex);
  636. return colInfo[columnIndex].tableName;
  637. }
  638. /**
  639. * Retrieves the catalog name of the table from which the value
  640. * in the designated column was derived.
  641. *
  642. * @param columnIndex the first column is 1, the second is 2, and so on;
  643. * must be between <code>1</code> and the number of columns, inclusive
  644. * @return the catalog name of the column's table or an empty
  645. * <code>String</code> if no catalog name is available
  646. * @throws SQLException if a database access error occurs
  647. * or the given column number is out of bounds
  648. */
  649. public String getCatalogName(int columnIndex) throws SQLException {
  650. checkColRange(columnIndex);
  651. String str ="";
  652. if(colInfo[columnIndex].catName == null){
  653. } else {
  654. str = colInfo[columnIndex].catName;
  655. }
  656. return str;
  657. }
  658. /**
  659. * Retrieves the type code (one of the <code>java.sql.Types</code>
  660. * constants) for the SQL type of the value stored in the
  661. * designated column.
  662. *
  663. * @param columnIndex the first column is 1, the second is 2, and so on;
  664. * must be between <code>1</code> and the number of columns, inclusive
  665. * @return an <code>int</code> representing the SQL type of values
  666. * stored in the designated column
  667. * @throws SQLException if a database access error occurs
  668. * or the given column number is out of bounds
  669. * @see java.sql.Types
  670. */
  671. public int getColumnType(int columnIndex) throws SQLException {
  672. checkColRange(columnIndex);
  673. return colInfo[columnIndex].colType;
  674. }
  675. /**
  676. * Retrieves the DBMS-specific type name for values stored in the
  677. * designated column.
  678. *
  679. * @param columnIndex the first column is 1, the second is 2, and so on;
  680. * must be between <code>1</code> and the number of columns, inclusive
  681. * @return the type name used by the data source
  682. * @throws SQLException if a database access error occurs
  683. * or the given column number is out of bounds
  684. */
  685. public String getColumnTypeName(int columnIndex) throws SQLException {
  686. checkColRange(columnIndex);
  687. return colInfo[columnIndex].colTypeName;
  688. }
  689. /**
  690. * Indicates whether the designated column is definitely
  691. * not writable, thus readonly.
  692. *
  693. * @param columnIndex the first column is 1, the second is 2, and so on;
  694. * must be between <code>1</code> and the number of columns, inclusive
  695. * @return <code>true</code> if this <code>RowSet</code> object is read-Only
  696. * and thus not updatable; <code>false</code> otherwise
  697. * @throws SQLException if a database access error occurs
  698. * or the given column number is out of bounds
  699. */
  700. public boolean isReadOnly(int columnIndex) throws SQLException {
  701. checkColRange(columnIndex);
  702. return colInfo[columnIndex].readOnly;
  703. }
  704. /**
  705. * Indicates whether it is possible for a write operation on
  706. * the designated column to succeed. A return value of
  707. * <code>true</code> means that a write operation may or may
  708. * not succeed.
  709. *
  710. * @param columnIndex the first column is 1, the second is 2, and so on;
  711. * must be between <code>1</code> and the number of columns, inclusive
  712. * @return <code>true</code> if a write operation on the designated column may
  713. * will succeed; <code>false</code> otherwise
  714. * @throws SQLException if a database access error occurs
  715. * or the given column number is out of bounds
  716. */
  717. public boolean isWritable(int columnIndex) throws SQLException {
  718. checkColRange(columnIndex);
  719. return colInfo[columnIndex].writable;
  720. }
  721. /**
  722. * Indicates whether a write operation on the designated column
  723. * will definitely succeed.
  724. *
  725. * @param columnIndex the first column is 1, the second is 2, and so on;
  726. * must be between <code>1</code> and the number of columns, inclusive
  727. * @return <code>true</code> if a write operation on the designated column will
  728. * definitely succeed; <code>false</code> otherwise
  729. * @throws SQLException if a database access error occurs
  730. * or the given column number is out of bounds
  731. */
  732. public boolean isDefinitelyWritable(int columnIndex)
  733. throws SQLException { return true;}
  734. /**
  735. * Retrieves the fully-qualified name of the class in the Java
  736. * programming language to which a value in the designated column
  737. * will be mapped. For example, if the value is an <code>int</code>,
  738. * the class name returned by this method will be
  739. * <code>java.lang.Integer</code>.
  740. * <P>
  741. * If the value in the designated column has a custom mapping,
  742. * this method returns the name of the class that implements
  743. * <code>SQLData</code>. When the method <code>ResultSet.getObject</code>
  744. * is called to retrieve a value from the designated column, it will
  745. * create an instance of this class or one of its subclasses.
  746. *
  747. * @param columnIndex the first column is 1, the second is 2, and so on;
  748. * must be between <code>1</code> and the number of columns, inclusive
  749. * @return the fully-qualified name of the class in the Java programming
  750. * language that would be used by the method <code>RowSet.getObject</code> to
  751. * retrieve the value in the specified column. This is the class
  752. * name used for custom mapping when there is a custom mapping.
  753. * @throws SQLException if a database access error occurs
  754. * or the given column number is out of bounds
  755. */
  756. public String getColumnClassName(int columnIndex) throws SQLException {
  757. String className = (new String()).getClass().getName();
  758. int sqlType = getColumnType(columnIndex);
  759. switch (sqlType) {
  760. case Types.NUMERIC:
  761. case Types.DECIMAL:
  762. className = (new java.math.BigDecimal(0)).getClass().getName ();
  763. break;
  764. case Types.BIT:
  765. className = (new Boolean(false)).getClass().getName ();
  766. break;
  767. case Types.TINYINT:
  768. className = (new Byte("0")).getClass().getName ();
  769. break;
  770. case Types.SMALLINT:
  771. className = (new Short("0")).getClass().getName ();
  772. break;
  773. case Types.INTEGER:
  774. className = (new Integer(0)).getClass().getName ();
  775. break;
  776. case Types.BIGINT:
  777. className = (new Long(0)).getClass().getName ();
  778. break;
  779. case Types.REAL:
  780. className = (new Float(0)).getClass().getName ();
  781. break;
  782. case Types.FLOAT:
  783. case Types.DOUBLE:
  784. className = (new Double(0)).getClass().getName();
  785. break;
  786. case Types.BINARY:
  787. case Types.VARBINARY:
  788. case Types.LONGVARBINARY:
  789. byte[] b = {};
  790. className = (b.getClass()).getName();
  791. break;
  792. case Types.DATE:
  793. className = (new java.sql.Date(123456)).getClass().getName ();
  794. break;
  795. case Types.TIME:
  796. className = (new java.sql.Time(123456)).getClass().getName ();
  797. break;
  798. case Types.TIMESTAMP:
  799. className = (new java.sql.Timestamp(123456)).getClass().getName ();
  800. break;
  801. case Types.BLOB:
  802. byte[] blob = {};
  803. className = (blob.getClass()).getName();
  804. break;
  805. case Types.CLOB:
  806. char[] c = {};
  807. className = (c.getClass()).getName();
  808. break;
  809. }
  810. return className;
  811. }
  812. static final long serialVersionUID = 6893806403181801867L;
  813. private class ColInfo implements Serializable {
  814. /**
  815. * The field that indicates whether the value in this column is a number
  816. * that is incremented automatically, which makes the value read-only.
  817. * <code>true</code> means that the value in this column
  818. * is automatically numbered; <code>false</code> means that it is not.
  819. *
  820. * @serial
  821. */
  822. public boolean autoIncrement;
  823. /**
  824. * The field that indicates whether the value in this column is case sensitive.
  825. * <code>true</code> means that it is; <code>false</code> that it is not.
  826. *
  827. * @serial
  828. */
  829. public boolean caseSensitive;
  830. /**
  831. * The field that indicates whether the value in this column is a cash value
  832. * <code>true</code> means that it is; <code>false</code> that it is not.
  833. *
  834. * @serial
  835. */
  836. public boolean currency;
  837. /**
  838. * The field that indicates whether the value in this column is nullable.
  839. * The possible values are the <code>ResultSet</code> constants
  840. * <code>columnNoNulls</code>, <code>columnNullable</code>, and
  841. * <code>columnNullableUnknown</code>.
  842. *
  843. * @serial
  844. */
  845. public int nullable;
  846. /**
  847. * The field that indicates whether the value in this column is a signed number.
  848. * <code>true</code> means that it is; <code>false</code> that it is not.
  849. *
  850. * @serial
  851. */
  852. public boolean signed;
  853. /**
  854. * The field that indicates whether the value in this column can be used in
  855. * a <code>WHERE</code> clause.
  856. * <code>true</code> means that it can; <code>false</code> that it cannot.
  857. *
  858. * @serial
  859. */
  860. public boolean searchable;
  861. /**
  862. * The field that indicates the normal maximum width in characters for
  863. * this column.
  864. *
  865. * @serial
  866. */
  867. public int columnDisplaySize;
  868. /**
  869. * The field that holds the suggested column title for this column, to be
  870. * used in printing and displays.
  871. *
  872. * @serial
  873. */
  874. public String columnLabel;
  875. /**
  876. * The field that holds the name of this column.
  877. *
  878. * @serial
  879. */
  880. public String columnName;
  881. /**
  882. * The field that holds the schema name for the table from which this column
  883. * was derived.
  884. *
  885. * @serial
  886. */
  887. public String schemaName;
  888. /**
  889. * The field that holds the precision of the value in this column. For number
  890. * types, the precision is the total number of decimal digits; for character types,
  891. * it is the maximum number of characters; for binary types, it is the maximum
  892. * length in bytes.
  893. *
  894. * @serial
  895. */
  896. public int colPrecision;
  897. /**
  898. * The field that holds the scale (number of digits to the right of the decimal
  899. * point) of the value in this column.
  900. *
  901. * @serial
  902. */
  903. public int colScale;
  904. /**
  905. * The field that holds the name of the table from which this column
  906. * was derived. This value may be the empty string if there is no
  907. * table name, such as when this column is produced by a join.
  908. *
  909. * @serial
  910. */
  911. public String tableName ="";
  912. /**
  913. * The field that holds the catalog name for the table from which this column
  914. * was derived. If the DBMS does not support catalogs, the value may be the
  915. * empty string.
  916. *
  917. * @serial
  918. */
  919. public String catName;
  920. /**
  921. * The field that holds the type code from the class <code>java.sql.Types</code>
  922. * indicating the type of the value in this column.
  923. *
  924. * @serial
  925. */
  926. public int colType;
  927. /**
  928. * The field that holds the the type name used by this particular data source
  929. * for the value stored in this column.
  930. *
  931. * @serial
  932. */
  933. public String colTypeName;
  934. /**
  935. * The field that holds the updatablity boolean per column of a RowSet
  936. *
  937. * @serial
  938. */
  939. public boolean readOnly = false;
  940. /**
  941. * The field that hold the writable boolean per column of a RowSet
  942. *
  943. *@serial
  944. */
  945. public boolean writable = true;
  946. }
  947. }