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