1. /*
  2. * @(#)Joinable.java 1.5 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.SQLException;
  9. /**
  10. * <h3>1.0 Background</h3>
  11. * The <code>Joinable</code> interface provides the methods for getting and
  12. * setting a match column, which is the basis for forming the SQL <code>JOIN</code>
  13. * formed by adding <code>RowSet</code> objects to a <code>JoinRowSet</code>
  14. * object.
  15. * <P>
  16. * Any standard <code>RowSet</code> implementation <b>may</b> implement
  17. * the <code>Joinable</code> interface in order to be
  18. * added to a <code>JoinRowSet</code> object. Implementing this interface gives
  19. * a <code>RowSet</code> object the ability to use <code>Joinable</code> methods,
  20. * which set, retrieve, and get information about match columns. An
  21. * application may add a
  22. * <code>RowSet</code> object that has not implemented the <code>Joinable</code>
  23. * interface to a <code>JoinRowSet</code> object, but to do so it must use one
  24. * of the <code>JoinRowSet.addRowSet</code> methods that takes both a
  25. * <code>RowSet</code> object and a match column or an array of <code>RowSet</code>
  26. * objects and an array of match columns.
  27. * <P>
  28. * To get access to the methods in the <code>Joinable</code> interface, a
  29. * <code>RowSet</code> object implements at least one of the
  30. * five standard <code>RowSet</code> interfaces and also implements the
  31. * <code>Joinable</code> interface. In addition, most <code>RowSet</code>
  32. * objects extend the <code>BaseRowSet</code> class. For example:
  33. * <pre>
  34. * class MyRowSetImpl extends BaseRowSet implements CachedRowSet, Joinable {
  35. * :
  36. * :
  37. * }
  38. * </pre>
  39. * <P>
  40. * <h3>2.0 Usage Guidelines</h3>
  41. * <P>
  42. * The methods in the <code>Joinable</code> interface allow a <code>RowSet</code> object
  43. * to set a match column, retrieve a match column, or unset a match column, which is
  44. * the column upon which an SQL <code>JOIN</code> can be based.
  45. * An instance of a class that implements these methods can be added to a
  46. * <code>JoinRowSet</code> object to allow an SQL <code>JOIN</code> relationship to
  47. * be established.
  48. * <p>
  49. * <pre>
  50. * CachedRowSet crs = new MyRowSetImpl();
  51. * crs.populate((ResultSet)rs);
  52. * (Joinable)crs.setMatchColumnIndex(1);
  53. *
  54. * JoinRowSet jrs = new JoinRowSetImpl();
  55. * jrs.addRowSet(crs);
  56. * </pre>
  57. * In the previous example, <i>crs</i> is a <code>CachedRowSet</code> object that
  58. * has emplemented the <code>Joinable</code> interface. In the following example,
  59. * <i>crs2</i> has not, so it must supply the match column as an argument to the
  60. * <code>addRowSet</code> method. This example assumes that column 1 is the match
  61. * column.
  62. * <PRE>
  63. * CachedRowSet crs2 = new MyRowSetImpl();
  64. * crs2.populate((ResultSet)rs);
  65. *
  66. * JoinRowSet jrs2 = new JoinRowSetImpl();
  67. * jrs2.addRowSet(crs2, 1);
  68. * </PRE>
  69. * <p>
  70. * The <code>JoinRowSet</code> interface makes it possible to get data from one or
  71. * more <code>RowSet</code> objects consolidated into one table without having to incur
  72. * the expense of creating a connection to a database. It is therefore ideally suited
  73. * for use by disconnected <code>RowSet</code> objects. Nevertheless, any
  74. * <code>RowSet</code> object <b>may</b> implement this interface
  75. * regardless of whether it is connected or disconnected. Note that a
  76. * <code>JdbcRowSet</code> object, being always connected to its data source, can
  77. * become part of an SQL <code>JOIN</code> directly without having to become part
  78. * of a <code>JoinRowSet</code> object.
  79. * <P>
  80. * <h3>3.0 Managing Multiple Match Columns</h3>
  81. * The index array passed into the <code>setMatchColumn</code> methods indicates
  82. * how many match columns are being set (the length of the array) in addition to
  83. * which columns will be used for the match. For example:
  84. * <pre>
  85. * int[] i = {1, 2, 4, 7}; // indicates four match columns, with column
  86. * // indexes 1, 2, 4, 7 participating in the JOIN.
  87. * Joinable.setMatchColumn(i);
  88. * </pre>
  89. * Subsequent match columns may be added as follows to a different <code>Joinable</code>
  90. * object (a <code>RowSet</code> object that has implemented the <code>Joinable</code>
  91. * interface).
  92. * <pre>
  93. * int[] w = {3, 2, 5, 3};
  94. * Joinable2.setMatchColumn(w);
  95. * </pre>
  96. * When an application adds two or more <code>RowSet</code> objects to a
  97. * <code>JoinRowSet</code> object, the order of the indexes in the array is
  98. * particularly important. Each index of
  99. * the array maps directly to the corresponding index of the previously added
  100. * <code>RowSet</code> object. If overlap or underlap occurs, the match column
  101. * data is maintained in the event an additional <code>Joinable</code> RowSet is
  102. * added and needs to relate to the match column data. Therefore, applications
  103. * can set multiple match columns in any order, but
  104. * this order has a direct effect on the outcome of the <code>SQL</code> JOIN.
  105. * <p>
  106. * This assertion applies in exactly the same manner when column names are used
  107. * rather than column indexes to indicate match columns.
  108. *
  109. * @see JoinRowSet
  110. * @author Jonathan Bruce
  111. */
  112. public interface Joinable {
  113. /**
  114. * Sets the designated column as the match column for this <code>RowSet</code>
  115. * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
  116. * object based on the match column.
  117. * <p>
  118. * Sub-interfaces such as the <code>CachedRowSet</code><sup><font size=-2>TM</font></sup>
  119. * interface define the method <code>CachedRowSet.setKeyColumns</code>, which allows
  120. * primary key semantics to be enforced on specific columns.
  121. * Implementations of the <code>setMatchColumn(int columnIdx)</code> method
  122. * should ensure that the constraints on the key columns are maintained when
  123. * a <code>CachedRowSet</code> object sets a primary key column as a match column.
  124. *
  125. * @param columnIdx an <code>int</code> identifying the index of the column to be
  126. * set as the match column
  127. * @throws SQLException if an invalid column index is set
  128. * @see #setMatchColumn(int[])
  129. * @see #unsetMatchColumn(int)
  130. *
  131. */
  132. public void setMatchColumn(int columnIdx) throws SQLException;
  133. /**
  134. * Sets the designated columns as the match column for this <code>RowSet</code>
  135. * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
  136. * object based on the match column.
  137. *
  138. * @param columnIdxes an array of <code>int</code> identifying the indexes of the
  139. * columns to be set as the match columns
  140. * @throws SQLException if an invalid column index is set
  141. * @see #setMatchColumn(int[])
  142. * @see #unsetMatchColumn(int[])
  143. */
  144. public void setMatchColumn(int[] columnIdxes) throws SQLException;
  145. /**
  146. * Sets the designated column as the match column for this <code>RowSet</code>
  147. * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
  148. * object based on the match column.
  149. * <p>
  150. * Subinterfaces such as the <code>CachedRowSet</code> interface define
  151. * the method <code>CachedRowSet.setKeyColumns</code>, which allows
  152. * primary key semantics to be enforced on specific columns.
  153. * Implementations of the <code>setMatchColumn(String columnIdx)</code> method
  154. * should ensure that the constraints on the key columns are maintained when
  155. * a <code>CachedRowSet</code> object sets a primary key column as a match column.
  156. *
  157. * @param columnName a <code>String</code> object giving the name of the column
  158. * to be set as the match column
  159. * @throws SQLException if an invalid column name is set, the column name
  160. * is a null, or the column name is an empty string
  161. * @see #unsetMatchColumn
  162. * @see #setMatchColumn(int[])
  163. */
  164. public void setMatchColumn(String columnName) throws SQLException;
  165. /**
  166. * Sets the designated columns as the match column for this <code>RowSet</code>
  167. * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
  168. * object based on the match column.
  169. *
  170. * @param columnNames an array of <code>String</code> objects giving the names
  171. * of the column to be set as the match columns
  172. * @throws SQLException if an invalid column name is set, the column name
  173. * is a null, or the column name is an empty string
  174. * @see #unsetMatchColumn
  175. * @see #setMatchColumn(int[])
  176. */
  177. public void setMatchColumn(String[] columnNames) throws SQLException;
  178. /**
  179. * Retrieves the indexes of the match columns that were set for this
  180. * <code>RowSet</code> object with the method
  181. * <code>setMatchColumn(int[] columnIdxes)</code>.
  182. *
  183. * @return an <code>int</code> array identifying the indexes of the columns
  184. * that were set as the match columns for this <code>RowSet</code> object
  185. * @throws SQLException if no match column has been set
  186. * @see #setMatchColumn
  187. * @see #unsetMatchColumn
  188. */
  189. public int[] getMatchColumnIndexes() throws SQLException;
  190. /**
  191. * Retrieves the names of the match columns that were set for this
  192. * <code>RowSet</code> object with the method
  193. * <code>setMatchColumn(String [] columnNames)</code>.
  194. *
  195. * @return an array of <code>String</code> objects giving the names of the columns
  196. * set as the match columns for this <code>RowSet</code> object
  197. * @throws SQLException if no match column has been set
  198. * @see #setMatchColumn
  199. * @see #unsetMatchColumn
  200. *
  201. */
  202. public String[] getMatchColumnNames() throws SQLException;
  203. /**
  204. * Unsets the designated column as the match column for this <code>RowSet</code>
  205. * object.
  206. * <P>
  207. * <code>RowSet</code> objects that implement the <code>Joinable</code> interface
  208. * must ensure that a key-like constraint continues to be enforced until the
  209. * method <code>CachedRowSet.unsetKeyColumns</code> has been called on the
  210. * designated column.
  211. *
  212. * @param columnIdx an <code>int</code> that identifies the index of the column
  213. * that is to be unset as a match column
  214. * @throws SQLException if an invalid column index is designated or if
  215. * the designated column was not previously set as a match
  216. * column
  217. * @see #setMatchColumn
  218. */
  219. public void unsetMatchColumn(int columnIdx) throws SQLException;
  220. /**
  221. * Unsets the designated columns as the match column for this <code>RowSet</code>
  222. * object.
  223. *
  224. * @param columnIdxes an arrary of <code>int</code> that identifies the indexes
  225. * of the columns that are to be unset as match columns
  226. * @throws SQLException if an invalid column index is designated or if
  227. * the designated column was not previously set as a match
  228. * column
  229. * @see #setMatchColumn
  230. */
  231. public void unsetMatchColumn(int[] columnIdxes) throws SQLException;
  232. /**
  233. * Unsets the designated column as the match column for this <code>RowSet</code>
  234. * object.
  235. * <P>
  236. * <code>RowSet</code> objects that implement the <code>Joinable</code> interface
  237. * must ensure that a key-like constraint continues to be enforced until the
  238. * method <code>CachedRowSet.unsetKeyColumns</code> has been called on the
  239. * designated column.
  240. *
  241. * @param columnName a <code>String</code> object giving the name of the column
  242. * that is to be unset as a match column
  243. * @throws SQLException if an invalid column name is designated or
  244. * the designated column was not previously set as a match
  245. * column
  246. * @see #setMatchColumn
  247. */
  248. public void unsetMatchColumn(String columnName) throws SQLException;
  249. /**
  250. * Unsets the designated columns as the match columns for this <code>RowSet</code>
  251. * object.
  252. *
  253. * @param columnName an array of <code>String</code> objects giving the names of
  254. * the columns that are to be unset as the match columns
  255. * @throws SQLException if an invalid column name is designated or the
  256. * designated column was not previously set as a match column
  257. * @see #setMatchColumn
  258. */
  259. public void unsetMatchColumn(String[] columnName) throws SQLException;
  260. }