1. /*
  2. * @(#)SQLOutput.java 1.11 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. * The output stream for writing the attributes of a user-defined
  11. * type back to the database. This interface, used
  12. * only for custom mapping, is used by the driver, and its
  13. * methods are never directly invoked by a programmer.
  14. * <p>When an object of a class implementing interface
  15. * <code>SQLData</code> is passed as an argument to an SQL statement, the
  16. * JDBC driver calls <code>SQLData.getSQLType</code> to
  17. * determine the kind of SQL
  18. * datum being passed to the database.
  19. * The driver then creates an instance of <code>SQLOutput</code> and
  20. * passes it to the method <code>SQLData.writeSQL</code>.
  21. * The method <code>writeSQL</code> in turn calls the
  22. * appropriate <code>SQLOutput.writeXXX</code> methods
  23. * to write data from the <code>SQLData</code> object to
  24. * the <code>SQLOutput</code> output stream as the
  25. * representation of an SQL user-defined type.
  26. */
  27. public interface SQLOutput {
  28. //================================================================
  29. // Methods for writing attributes to the stream of SQL data.
  30. // These methods correspond to the column-accessor methods of
  31. // java.sql.ResultSet.
  32. //================================================================
  33. /**
  34. * Writes the next attribute to the stream as a Java String.
  35. *
  36. * @param x the value to pass to the database.
  37. * @exception SQLException if a database access error occurs
  38. */
  39. void writeString(String x) throws SQLException;
  40. /**
  41. * Writes the next attribute to the stream as a Java boolean.
  42. *
  43. * @param x the value to pass to the database.
  44. * @exception SQLException if a database access error occurs
  45. */
  46. void writeBoolean(boolean x) throws SQLException;
  47. /**
  48. * Writes the next attribute to the stream as a Java byte.
  49. *
  50. * @param x the value to pass to the database.
  51. * @exception SQLException if a database access error occurs
  52. */
  53. void writeByte(byte x) throws SQLException;
  54. /**
  55. * Writes the next attribute to the stream as a Java short.
  56. *
  57. * @param x the value to pass to the database.
  58. * @exception SQLException if a database access error occurs
  59. */
  60. void writeShort(short x) throws SQLException;
  61. /**
  62. * Writes the next attribute to the stream as a Java int.
  63. *
  64. * @param x the value to pass to the database.
  65. * @exception SQLException if a database access error occurs
  66. */
  67. void writeInt(int x) throws SQLException;
  68. /**
  69. * Writes the next attribute to the stream as a Java long.
  70. *
  71. * @param x the value to pass to the database.
  72. * @exception SQLException if a database access error occurs
  73. */
  74. void writeLong(long x) throws SQLException;
  75. /**
  76. * Writes the next attribute to the stream as a Java float.
  77. *
  78. * @param x the value to pass to the database.
  79. * @exception SQLException if a database access error occurs
  80. */
  81. void writeFloat(float x) throws SQLException;
  82. /**
  83. * Writes the next attribute to the stream as a Java double.
  84. *
  85. * @param x the value to pass to the database.
  86. * @exception SQLException if a database access error occurs
  87. */
  88. void writeDouble(double x) throws SQLException;
  89. /**
  90. * Writes the next attribute to the stream as a java.math.BigDecimal object.
  91. *
  92. * @param x the value to pass to the database.
  93. * @exception SQLException if a database access error occurs
  94. */
  95. void writeBigDecimal(java.math.BigDecimal x) throws SQLException;
  96. /**
  97. * Writes the next attribute to the stream as an array of bytes.
  98. *
  99. * @param x the value to pass to the database.
  100. * @exception SQLException if a database access error occurs
  101. */
  102. void writeBytes(byte[] x) throws SQLException;
  103. /**
  104. * Writes the next attribute to the stream as a java.sql.Date object.
  105. *
  106. * @param x the value to pass to the database.
  107. * @exception SQLException if a database access error occurs
  108. */
  109. void writeDate(java.sql.Date x) throws SQLException;
  110. /**
  111. * Writes the next attribute to the stream as a java.sql.Time object.
  112. *
  113. * @param x the value to pass to the database.
  114. * @exception SQLException if a database access error occurs
  115. */
  116. void writeTime(java.sql.Time x) throws SQLException;
  117. /**
  118. * Writes the next attribute to the stream as a java.sql.Timestamp object.
  119. *
  120. * @param x the value to pass to the database.
  121. * @exception SQLException if a database access error occurs
  122. */
  123. void writeTimestamp(java.sql.Timestamp x) throws SQLException;
  124. /**
  125. * Returns the next attribute to the stream as a stream of Unicode characters.
  126. *
  127. * @param x the value to pass to the database.
  128. * @exception SQLException if a database access error occurs
  129. */
  130. void writeCharacterStream(java.io.Reader x) throws SQLException;
  131. /**
  132. * Returns the next attribute to the stream as a stream of ASCII characters.
  133. *
  134. * @param x the value to pass to the database.
  135. * @exception SQLException if a database access error occurs
  136. */
  137. void writeAsciiStream(java.io.InputStream x) throws SQLException;
  138. /**
  139. * Returns the next attribute to the stream as a stream of uninterpreted
  140. * bytes.
  141. *
  142. * @param x the value to pass to the database.
  143. * @exception SQLException if a database access error occurs
  144. */
  145. void writeBinaryStream(java.io.InputStream x) throws SQLException;
  146. //================================================================
  147. // Methods for writing items of SQL user-defined types to the stream.
  148. // These methods pass objects to the database as values of SQL
  149. // Structured Types, Distinct Types, Constructed Types, and Locator
  150. // Types. They decompose the Java object(s) and write leaf data
  151. // items using the methods above.
  152. //================================================================
  153. /**
  154. * Writes to the stream the data contained in the given
  155. * <code>SQLData</code> object.
  156. * When the <code>SQLData</code> object is null, this
  157. * method writes an SQL NULL to the stream.
  158. * Otherwise, it calls the <code>SQLData.writeSQL</code>
  159. * method of the given object, which
  160. * writes the object's attributes to the stream.
  161. * The implementation of the method <code>SQLData.writeSQ</code>
  162. * calls the appropriate <code>SQLOutput.writeXXX</code> method(s)
  163. * for writing each of the object's attributes in order.
  164. * The attributes must be read from an <code>SQLInput</code>
  165. * input stream and written to an <code>SQLOutput</code>
  166. * output stream in the same order in which they were
  167. * listed in the SQL definition of the user-defined type.
  168. *
  169. * @param x the object representing data of an SQL structured or
  170. * distinct type
  171. * @exception SQLException if a database access error occurs
  172. */
  173. void writeObject(SQLData x) throws SQLException;
  174. /**
  175. * Writes a REF(<structured-type>) to the stream.
  176. *
  177. * @param x an object representing data of an SQL REF Type
  178. * @exception SQLException if a database access error occurs
  179. */
  180. void writeRef(Ref x) throws SQLException;
  181. /**
  182. * Writes a BLOB to the stream.
  183. *
  184. * @param x an object representing a BLOB
  185. * @exception SQLException if a database access error occurs
  186. */
  187. void writeBlob(Blob x) throws SQLException;
  188. /**
  189. * Writes a CLOB to the stream.
  190. *
  191. * @param x an object representing a CLOB
  192. * @exception SQLException if a database access error occurs
  193. */
  194. void writeClob(Clob x) throws SQLException;
  195. /**
  196. * Writes a structured-type to the stream.
  197. *
  198. * @param x an object representing data of a Structured Type
  199. * @exception SQLException if a database access error occurs
  200. */
  201. void writeStruct(Struct x) throws SQLException;
  202. /**
  203. * Writes an array to the stream.
  204. *
  205. * @param x an object representing an SQL array
  206. * @exception SQLException if a database access error occurs
  207. */
  208. void writeArray(Array x) throws SQLException;
  209. }