1. /*
  2. * @(#)JdbcRowSet.java 1.4 04/02/27
  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 javax.naming.*;
  11. import java.io.*;
  12. import java.math.*;
  13. import java.io.*;
  14. /**
  15. * The standard interface that all standard implementations of
  16. * <code>JdbcRowSet</code> must implement.
  17. *
  18. * <h3>1.0 Overview</h3>
  19. * A wrapper around a <code>ResultSet</code> object that makes it possible
  20. * to use the result set as a JavaBeans<sup><font size=-2>TM</font></sup>
  21. * component. Thus, a <code>JdbcRowSet</code> object can be one of the Beans that
  22. * a tool makes available for composing an application. Because
  23. * a <code>JdbcRowSet</code> is a connected rowset, that is, it continually
  24. * maintains its connection to a database using a JDBC technology-enabled
  25. * driver, it also effectively makes the driver a JavaBeans component.
  26. * <P>
  27. * Because it is always connected to its database, an instance of
  28. * <code>JdbcRowSet</code>
  29. * can simply take calls invoked on it and in turn call them on its
  30. * <code>ResultSet</code> object. As a consequence, a result set can, for
  31. * example, be a component in a Swing application.
  32. * <P>
  33. * Another advantage of a <code>JdbcRowSet</code> object is that it can be
  34. * used to make a <code>ResultSet</code> object scrollable and updatable. All
  35. * <code>RowSet</code> objects are by default scrollable and updatable. If
  36. * the driver and database being used do not support scrolling and/or updating
  37. * of result sets, an application can populate a <code>JdbcRowSet</code> object
  38. * with the data of a <code>ResultSet</code> object and then operate on the
  39. * <code>JdbcRowSet</code> object as if it were the <code>ResultSet</code>
  40. * object.
  41. * <P>
  42. * <h3>2.0 Creating a <code>JdbcRowSet</code> Object</h3>
  43. * The reference implementation of the <code>JdbcRowSet</code> interface,
  44. * <code>JdbcRowSetImpl</code>, provides an implementation of
  45. * the default constructor. A new instance is initialized with
  46. * default values, which can be set with new values as needed. A
  47. * new instance is not really functional until its <code>execute</code>
  48. * method is called. In general, this method does the following:
  49. * <UL>
  50. * <LI> establishes a connection with a database
  51. * <LI> creates a <code>PreparedStatement</code> object and sets any of its
  52. * placeholder parameters
  53. * <LI> executes the statement to create a <code>ResultSet</code> object
  54. * </UL>
  55. * If the <code>execute</code> method is successful, it will set the
  56. * appropriate private <code>JdbcRowSet</code> fields with the following:
  57. * <UL>
  58. * <LI> a <code>Connection</code> object -- the connection between the rowset
  59. * and the database
  60. * <LI> a <code>PreparedStatement</code> object -- the query that produces
  61. * the result set
  62. * <LI> a <code>ResultSet</code> object -- the result set that the rowset's
  63. * command produced and that is being made, in effect, a JavaBeans
  64. * component
  65. * </UL>
  66. * If these fields have not been set, meaning that the <code>execute</code>
  67. * method has not executed successfully, no methods other than
  68. * <code>execute</code> and <code>close</code> may be called on the
  69. * rowset. All other public methods will throw an exception.
  70. * <P>
  71. * Before calling the <code>execute</code> method, however, the command
  72. * and properties needed for establishing a connection must be set.
  73. * The following code fragment creates a <code>JdbcRowSetImpl</code> object,
  74. * sets the command and connection properties, sets the placeholder parameter,
  75. * and then invokes the method <code>execute</code>.
  76. * <PRE>
  77. * JdbcRowSetImpl jrs = new JdbcRowSetImpl();
  78. * jrs.setCommand("SELECT * FROM TITLES WHERE TYPE = ?");
  79. * jrs.setURL("jdbc:myDriver:myAttribute");
  80. * jrs.setUsername("cervantes");
  81. * jrs.setPassword("sancho");
  82. * jrs.setString(1, "BIOGRAPHY");
  83. * jrs.execute();
  84. * </PRE>
  85. * The variable <code>jrs</code> now represents an instance of
  86. * <code>JdbcRowSetImpl</code> that is a thin wrapper around the
  87. * <code>ResultSet</code> object containing all the rows in the
  88. * table <code>TITLES</code> where the type of book is biography.
  89. * At this point, operations called on <code>jrs</code> will
  90. * affect the rows in the result set, which is effectively a JavaBeans
  91. * component.
  92. * <P>
  93. * The implementation of the <code>RowSet</code> method <code>execute</code> in the
  94. * <code>JdbcRowSet</code> reference implementation differs from that in the
  95. * <code>CachedRowSet</code><sup><font size=-2>TM</font></sup>
  96. * reference implementation to account for the different
  97. * requirements of connected and disconnected <code>RowSet</code> objects.
  98. * <p>
  99. *
  100. * @author Jonathan Bruce
  101. */
  102. public interface JdbcRowSet extends RowSet, Joinable {
  103. /**
  104. * Retrieves a <code>boolean</code> indicating whether rows marked
  105. * for deletion appear in the set of current rows. If <code>true</code> is
  106. * returned, deleted rows are visible with the current rows. If
  107. * <code>false</code> is returned, rows are not visible with the set of
  108. * current rows. The default value is <code>false</code>.
  109. * <P>
  110. * Standard rowset implementations may choose to restrict this behavior
  111. * for security considerations or for certain deployment
  112. * scenarios. The visibility of deleted rows is implementation-defined
  113. * and does not represent standard behavior.
  114. * <P>
  115. * Note: Allowing deleted rows to remain visible complicates the behavior
  116. * of some standard JDBC <code>RowSet</code> implementations methods.
  117. * However, most rowset users can simply ignore this extra detail because
  118. * only very specialized applications will likely want to take advantage of
  119. * this feature.
  120. *
  121. * @return <code>true</code> if deleted rows are visible;
  122. * <code>false</code> otherwise
  123. * @exception SQLException if a rowset implementation is unable to
  124. * to determine whether rows marked for deletion remain visible
  125. * @see #setShowDeleted
  126. */
  127. public boolean getShowDeleted() throws SQLException;
  128. /**
  129. * Sets the property <code>showDeleted</code> to the given
  130. * <code>boolean</code> value. This property determines whether
  131. * rows marked for deletion continue to appear in the set of current rows.
  132. * If the value is set to <code>true</code>, deleted rows are immediately
  133. * visible with the set of current rows. If the value is set to
  134. * <code>false</code>, the deleted rows are set as invisible with the
  135. * current set of rows.
  136. * <P>
  137. * Standard rowset implementations may choose to restrict this behavior
  138. * for security considerations or for certain deployment
  139. * scenarios. This is left as implementation-defined and does not
  140. * represent standard behavior.
  141. *
  142. * @param b <code>true</code> if deleted rows should be shown;
  143. * <code>false</code> otherwise
  144. * @exception SQLException if a rowset implementation is unable to
  145. * to reset whether deleted rows should be visible
  146. * @see #getShowDeleted
  147. */
  148. public void setShowDeleted(boolean b) throws SQLException;
  149. /**
  150. * Retrieves the first warning reported by calls on this <code>JdbcRowSet</code>
  151. * object.
  152. * If a second warning was reported on this <code>JdbcRowSet</code> object,
  153. * it will be chained to the first warning and can be retrieved by
  154. * calling the method <code>RowSetWarning.getNextWarning</code> on the
  155. * first warning. Subsequent warnings on this <code>JdbcRowSet</code>
  156. * object will be chained to the <code>RowSetWarning</code> objects
  157. * returned by the method <code>RowSetWarning.getNextWarning</code>.
  158. *
  159. * The warning chain is automatically cleared each time a new row is read.
  160. * This method may not be called on a <code>RowSet</code> object
  161. * that has been closed;
  162. * doing so will cause an <code>SQLException</code> to be thrown.
  163. * <P>
  164. * Because it is always connected to its data source, a <code>JdbcRowSet</code>
  165. * object can rely on the presence of active
  166. * <code>Statement</code>, <code>Connection</code>, and <code>ResultSet</code>
  167. * instances. This means that applications can obtain additional
  168. * <code>SQLWarning</code>
  169. * notifications by calling the <code>getNextWarning</code> methods that
  170. * they provide.
  171. * Disconnected <code>Rowset</code> objects, such as a
  172. * <code>CachedRowSet</code> object, do not have access to
  173. * these <code>getNextWarning</code> methods.
  174. *
  175. * @return the first <code>RowSetWarning</code>
  176. * object reported on this <code>JdbcRowSet</code> object
  177. * or <code>null</code> if there are none
  178. * @throws SQLException if this method is called on a closed
  179. * <code>JdbcRowSet</code> object
  180. * @see RowSetWarning
  181. */
  182. public RowSetWarning getRowSetWarnings() throws SQLException;
  183. /**
  184. * Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from
  185. * the <code>ResultSet</code> or JDBC properties passed to it's constructors.
  186. * This method wraps the <code>Connection</code> commit method to allow flexible
  187. * auto commit or non auto commit transactional control support.
  188. * <p>
  189. * Makes all changes made since the previous commit/rollback permanent
  190. * and releases any database locks currently held by this Connection
  191. * object. This method should be used only when auto-commit mode has
  192. * been disabled.
  193. *
  194. * @throws SQLException if a database access error occurs or this
  195. * Connection object within this <code>JdbcRowSet</code> is in auto-commit mode
  196. * @see java.sql.Connection#setAutoCommit
  197. */
  198. public void commit() throws SQLException;
  199. /**
  200. * Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from
  201. * the original <code>ResultSet</code> or JDBC properties passed to it. This
  202. * method wraps the <code>Connection</code>'s <code>getAutoCommit</code> method
  203. * to allow an application to determine the <code>JdbcRowSet</code> transaction
  204. * behavior.
  205. * <p>
  206. * Sets this connection's auto-commit mode to the given state. If a
  207. * connection is in auto-commit mode, then all its SQL statements will
  208. * be executed and committed as individual transactions. Otherwise, its
  209. * SQL statements are grouped into transactions that are terminated by a
  210. * call to either the method commit or the method rollback. By default,
  211. * new connections are in auto-commit mode.
  212. *
  213. * @throws SQLException if a database access error occurs
  214. * @see java.sql.Connection#getAutoCommit()
  215. */
  216. public boolean getAutoCommit() throws SQLException;
  217. /**
  218. * Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from
  219. * the original <code>ResultSet</code> or JDBC properties passed to it. This
  220. * method wraps the <code>Connection</code>'s <code>getAutoCommit</code> method
  221. * to allow an application to set the <code>JdbcRowSet</code> transaction behavior.
  222. * <p>
  223. * Sets the current auto-commit mode for this <code>Connection</code> object.
  224. *
  225. * @return the current state of this internal <code>Connection</code> object's
  226. * auto-commit mode
  227. * @throws SQLException if a database access error occurs
  228. * @see java.sql.Connection#setAutoCommit(boolean)
  229. */
  230. public void setAutoCommit(boolean autoCommit) throws SQLException;
  231. /**
  232. * Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from
  233. * the original <code>ResultSet</code> or JDBC properties passed to it.
  234. * Undoes all changes made in the current transaction and releases any
  235. * database locks currently held by this <code>Connection</code> object. This method
  236. * should be used only when auto-commit mode has been disabled.
  237. *
  238. * @throws SQLException if a database access error occurs or this <code>Connection</code>
  239. * object within this <code>JdbcRowSet</code> is in auto-commit mode.
  240. * @see #rollback(Savepoint)
  241. */
  242. public void rollback() throws SQLException;
  243. /**
  244. * Each <code>JdbcRowSet</code> contains a <code>Connection</code> object from
  245. * the original <code>ResultSet</code> or JDBC properties passed to it.
  246. * Undoes all changes made in the current transaction to the last set savepoint
  247. * and releases any database locks currently held by this <code>Connection</code>
  248. * object. This method should be used only when auto-commit mode has been disabled.
  249. *
  250. * @throws SQLException if a database access error occurs or this <code>Connection</code>
  251. * object within this <code>JdbcRowSet</code> is in auto-commit mode.
  252. * @see #rollback
  253. */
  254. public void rollback(Savepoint s) throws SQLException;
  255. }