1. /*
  2. * @(#)SQLInput.java 1.12 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * JDBC 2.0
  10. *
  11. * A input stream that contains a stream of values representing an
  12. * instance of an SQL structured or distinct type.
  13. * This interface, used only for custom mapping, is used by the driver
  14. * behind the scenes, and a programmer never directly invokes
  15. * <code>SQLInput</code> methods.
  16. * <P>When the method <code>getObject</code> is called with an
  17. * object of a class implementing the interface <code>SQLData</code>,
  18. * the JDBC driver calls the method <code>SQLData.getSQLType</code>
  19. * to determine the SQL type of the user-defined type (UDT)
  20. * being custom mapped. The driver
  21. * creates an instance of <code>SQLInput</code>, populating it with the
  22. * attributes of the UDT. The driver then passes the input
  23. * stream to the method <code>SQLData.readSQL</code>, which in turn
  24. * calls the <code>SQLInput.readXXX</code> methods
  25. * in its implementation for reading the
  26. * attributes from the input stream.
  27. */
  28. public interface SQLInput {
  29. //================================================================
  30. // Methods for reading attributes from the stream of SQL data.
  31. // These methods correspond to the column-accessor methods of
  32. // java.sql.ResultSet.
  33. //================================================================
  34. /**
  35. * Reads the next attribute in the stream as a Java String.
  36. *
  37. * @return the attribute; if the value is SQL NULL, return null.
  38. * @exception SQLException if a database access error occurs
  39. */
  40. String readString() throws SQLException;
  41. /**
  42. * Reads the next attribute in the stream as a Java boolean.
  43. *
  44. * @return the attribute; if the value is SQL NULL, return null.
  45. * @exception SQLException if a database access error occurs
  46. */
  47. boolean readBoolean() throws SQLException;
  48. /**
  49. * Reads the next attribute in the stream as a Java byte.
  50. *
  51. * @return the attribute; if the value is SQL NULL, return null.
  52. * @exception SQLException if a database access error occurs
  53. */
  54. byte readByte() throws SQLException;
  55. /**
  56. * Reads the next attribute in the stream as a Java short.
  57. *
  58. * @return the attribute; if the value is SQL NULL, return null.
  59. * @exception SQLException if a database access error occurs
  60. */
  61. short readShort() throws SQLException;
  62. /**
  63. * Reads the next attribute in the stream as a Java int.
  64. *
  65. * @return the attribute; if the value is SQL NULL, return null.
  66. * @exception SQLException if a database access error occurs
  67. */
  68. int readInt() throws SQLException;
  69. /**
  70. * Reads the next attribute in the stream as a Java long.
  71. *
  72. * @return the attribute; if the value is SQL NULL, return null.
  73. * @exception SQLException if a database access error occurs
  74. */
  75. long readLong() throws SQLException;
  76. /**
  77. * Reads the next attribute in the stream as a Java float.
  78. *
  79. * @return the attribute; if the value is SQL NULL, return null.
  80. * @exception SQLException if a database access error occurs
  81. */
  82. float readFloat() throws SQLException;
  83. /**
  84. * Reads the next attribute in the stream as a Java double.
  85. *
  86. * @return the attribute; if the value is SQL NULL, return null.
  87. * @exception SQLException if a database access error occurs
  88. */
  89. double readDouble() throws SQLException;
  90. /**
  91. * Reads the next attribute in the stream as a java.math.BigDecimal object.
  92. *
  93. * @return the attribute; if the value is SQL NULL, return null.
  94. * @exception SQLException if a database access error occurs
  95. */
  96. java.math.BigDecimal readBigDecimal() throws SQLException;
  97. /**
  98. * Reads the next attribute in the stream as an array of bytes.
  99. *
  100. * @return the attribute; if the value is SQL NULL, return null.
  101. * @exception SQLException if a database access error occurs
  102. */
  103. byte[] readBytes() throws SQLException;
  104. /**
  105. * Reads the next attribute in the stream as a java.sql.Date object.
  106. *
  107. * @return the attribute; if the value is SQL NULL, return null.
  108. * @exception SQLException if a database access error occurs
  109. */
  110. java.sql.Date readDate() throws SQLException;
  111. /**
  112. * Reads the next attribute in the stream as a java.sql.Time object.
  113. *
  114. * @return the attribute; if the value is SQL NULL, return null.
  115. * @exception SQLException if a database access error occurs
  116. */
  117. java.sql.Time readTime() throws SQLException;
  118. /**
  119. * Reads the next attribute in the stream as a java.sql.Timestamp object.
  120. *
  121. * @return the attribute; if the value is SQL NULL, return null.
  122. * @exception SQLException if a database access error occurs
  123. */
  124. java.sql.Timestamp readTimestamp() throws SQLException;
  125. /**
  126. * Returns the next attribute in the stream as a stream of Unicode characters.
  127. *
  128. * @return the attribute; if the value is SQL NULL, return null.
  129. * @exception SQLException if a database access error occurs
  130. */
  131. java.io.Reader readCharacterStream() throws SQLException;
  132. /**
  133. * Returns the next attribute in the stream as a stream of ASCII characters.
  134. *
  135. * @return the attribute; if the value is SQL NULL, return null.
  136. * @exception SQLException if a database access error occurs
  137. */
  138. java.io.InputStream readAsciiStream() throws SQLException;
  139. /**
  140. * Returns the next attribute in the stream as a stream of uninterpreted
  141. * bytes.
  142. *
  143. * @return the attribute; if the value is SQL NULL, return null.
  144. * @exception SQLException if a database access error occurs
  145. */
  146. java.io.InputStream readBinaryStream() throws SQLException;
  147. //================================================================
  148. // Methods for reading items of SQL user-defined types from the stream.
  149. //================================================================
  150. /**
  151. * Returns the datum at the head of the stream as a Java object. The
  152. * actual type of the object returned is determined by the default type
  153. * mapping, and any customizations present in this stream's type map.
  154. *
  155. * A type map is registered with the stream by the JDBC driver before the
  156. * stream is passed to the application.
  157. *
  158. * When the datum at the head of the stream is an SQL NULL,
  159. * the method returns null. If the datum is an SQL structured or distinct
  160. * type, it determines the SQL type of the datum at the head of the stream,
  161. * constructs an object of the appropriate class, and calls the method
  162. * <code>SQLData.readSQL</code> on that object, which reads additional data from the
  163. * stream, using the protocol described for that method.
  164. *
  165. * @return the datum at the head of the stream as a Java object; null if
  166. * the datum is SQL NULL
  167. * @exception SQLException if a database access error occurs
  168. */
  169. Object readObject() throws SQLException;
  170. /**
  171. * Reads a REF(<structured-type>) from the stream.
  172. *
  173. * @return an object representing data of the SQL REF at the head of the stream
  174. * @exception SQLException if a database access error occurs
  175. */
  176. Ref readRef() throws SQLException;
  177. /**
  178. * Reads a BLOB from the stream.
  179. *
  180. * @return an object representing the SQL BLOB at the head of the stream
  181. * @exception SQLException if a database access error occurs
  182. */
  183. Blob readBlob() throws SQLException;
  184. /**
  185. * Reads a CLOB from the stream.
  186. *
  187. * @return an object representing the SQL CLOB at the head of the stream
  188. * @exception SQLException if a database access error occurs
  189. */
  190. Clob readClob() throws SQLException;
  191. /**
  192. * Reads an array from the stream.
  193. *
  194. * @return an object representing the SQL array at the head of the stream
  195. * @exception SQLException if a database access error occurs
  196. */
  197. Array readArray() throws SQLException;
  198. /**
  199. * Determines whether the last value read was null.
  200. *
  201. * @return true if the most recently gotten SQL value was null;
  202. * otherwise, false
  203. * @exception SQLException if a database access error occurs
  204. *
  205. */
  206. boolean wasNull() throws SQLException;
  207. }