001 /*
002 * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.sql.rowset;
027
028 import java.sql.SQLException;
029
030 /**
031 * <h3>1.0 Background</h3>
032 * The <code>Joinable</code> interface provides the methods for getting and
033 * setting a match column, which is the basis for forming the SQL <code>JOIN</code>
034 * formed by adding <code>RowSet</code> objects to a <code>JoinRowSet</code>
035 * object.
036 * <P>
037 * Any standard <code>RowSet</code> implementation <b>may</b> implement
038 * the <code>Joinable</code> interface in order to be
039 * added to a <code>JoinRowSet</code> object. Implementing this interface gives
040 * a <code>RowSet</code> object the ability to use <code>Joinable</code> methods,
041 * which set, retrieve, and get information about match columns. An
042 * application may add a
043 * <code>RowSet</code> object that has not implemented the <code>Joinable</code>
044 * interface to a <code>JoinRowSet</code> object, but to do so it must use one
045 * of the <code>JoinRowSet.addRowSet</code> methods that takes both a
046 * <code>RowSet</code> object and a match column or an array of <code>RowSet</code>
047 * objects and an array of match columns.
048 * <P>
049 * To get access to the methods in the <code>Joinable</code> interface, a
050 * <code>RowSet</code> object implements at least one of the
051 * five standard <code>RowSet</code> interfaces and also implements the
052 * <code>Joinable</code> interface. In addition, most <code>RowSet</code>
053 * objects extend the <code>BaseRowSet</code> class. For example:
054 * <pre>
055 * class MyRowSetImpl extends BaseRowSet implements CachedRowSet, Joinable {
056 * :
057 * :
058 * }
059 * </pre>
060 * <P>
061 * <h3>2.0 Usage Guidelines</h3>
062 * <P>
063 * The methods in the <code>Joinable</code> interface allow a <code>RowSet</code> object
064 * to set a match column, retrieve a match column, or unset a match column, which is
065 * the column upon which an SQL <code>JOIN</code> can be based.
066 * An instance of a class that implements these methods can be added to a
067 * <code>JoinRowSet</code> object to allow an SQL <code>JOIN</code> relationship to
068 * be established.
069 * <p>
070 * <pre>
071 * CachedRowSet crs = new MyRowSetImpl();
072 * crs.populate((ResultSet)rs);
073 * (Joinable)crs.setMatchColumnIndex(1);
074 *
075 * JoinRowSet jrs = new JoinRowSetImpl();
076 * jrs.addRowSet(crs);
077 * </pre>
078 * In the previous example, <i>crs</i> is a <code>CachedRowSet</code> object that
079 * has emplemented the <code>Joinable</code> interface. In the following example,
080 * <i>crs2</i> has not, so it must supply the match column as an argument to the
081 * <code>addRowSet</code> method. This example assumes that column 1 is the match
082 * column.
083 * <PRE>
084 * CachedRowSet crs2 = new MyRowSetImpl();
085 * crs2.populate((ResultSet)rs);
086 *
087 * JoinRowSet jrs2 = new JoinRowSetImpl();
088 * jrs2.addRowSet(crs2, 1);
089 * </PRE>
090 * <p>
091 * The <code>JoinRowSet</code> interface makes it possible to get data from one or
092 * more <code>RowSet</code> objects consolidated into one table without having to incur
093 * the expense of creating a connection to a database. It is therefore ideally suited
094 * for use by disconnected <code>RowSet</code> objects. Nevertheless, any
095 * <code>RowSet</code> object <b>may</b> implement this interface
096 * regardless of whether it is connected or disconnected. Note that a
097 * <code>JdbcRowSet</code> object, being always connected to its data source, can
098 * become part of an SQL <code>JOIN</code> directly without having to become part
099 * of a <code>JoinRowSet</code> object.
100 * <P>
101 * <h3>3.0 Managing Multiple Match Columns</h3>
102 * The index array passed into the <code>setMatchColumn</code> methods indicates
103 * how many match columns are being set (the length of the array) in addition to
104 * which columns will be used for the match. For example:
105 * <pre>
106 * int[] i = {1, 2, 4, 7}; // indicates four match columns, with column
107 * // indexes 1, 2, 4, 7 participating in the JOIN.
108 * Joinable.setMatchColumn(i);
109 * </pre>
110 * Subsequent match columns may be added as follows to a different <code>Joinable</code>
111 * object (a <code>RowSet</code> object that has implemented the <code>Joinable</code>
112 * interface).
113 * <pre>
114 * int[] w = {3, 2, 5, 3};
115 * Joinable2.setMatchColumn(w);
116 * </pre>
117 * When an application adds two or more <code>RowSet</code> objects to a
118 * <code>JoinRowSet</code> object, the order of the indexes in the array is
119 * particularly important. Each index of
120 * the array maps directly to the corresponding index of the previously added
121 * <code>RowSet</code> object. If overlap or underlap occurs, the match column
122 * data is maintained in the event an additional <code>Joinable</code> RowSet is
123 * added and needs to relate to the match column data. Therefore, applications
124 * can set multiple match columns in any order, but
125 * this order has a direct effect on the outcome of the <code>SQL</code> JOIN.
126 * <p>
127 * This assertion applies in exactly the same manner when column names are used
128 * rather than column indexes to indicate match columns.
129 *
130 * @see JoinRowSet
131 * @author Jonathan Bruce
132 */
133 public interface Joinable {
134
135 /**
136 * Sets the designated column as the match column for this <code>RowSet</code>
137 * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
138 * object based on the match column.
139 * <p>
140 * Sub-interfaces such as the <code>CachedRowSet</code><sup><font size=-2>TM</font></sup>
141 * interface define the method <code>CachedRowSet.setKeyColumns</code>, which allows
142 * primary key semantics to be enforced on specific columns.
143 * Implementations of the <code>setMatchColumn(int columnIdx)</code> method
144 * should ensure that the constraints on the key columns are maintained when
145 * a <code>CachedRowSet</code> object sets a primary key column as a match column.
146 *
147 * @param columnIdx an <code>int</code> identifying the index of the column to be
148 * set as the match column
149 * @throws SQLException if an invalid column index is set
150 * @see #setMatchColumn(int[])
151 * @see #unsetMatchColumn(int)
152 *
153 */
154 public void setMatchColumn(int columnIdx) throws SQLException;
155
156 /**
157 * Sets the designated columns as the match column for this <code>RowSet</code>
158 * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
159 * object based on the match column.
160 *
161 * @param columnIdxes an array of <code>int</code> identifying the indexes of the
162 * columns to be set as the match columns
163 * @throws SQLException if an invalid column index is set
164 * @see #setMatchColumn(int[])
165 * @see #unsetMatchColumn(int[])
166 */
167 public void setMatchColumn(int[] columnIdxes) throws SQLException;
168
169 /**
170 * Sets the designated column as the match column for this <code>RowSet</code>
171 * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
172 * object based on the match column.
173 * <p>
174 * Subinterfaces such as the <code>CachedRowSet</code> interface define
175 * the method <code>CachedRowSet.setKeyColumns</code>, which allows
176 * primary key semantics to be enforced on specific columns.
177 * Implementations of the <code>setMatchColumn(String columnIdx)</code> method
178 * should ensure that the constraints on the key columns are maintained when
179 * a <code>CachedRowSet</code> object sets a primary key column as a match column.
180 *
181 * @param columnName a <code>String</code> object giving the name of the column
182 * to be set as the match column
183 * @throws SQLException if an invalid column name is set, the column name
184 * is a null, or the column name is an empty string
185 * @see #unsetMatchColumn
186 * @see #setMatchColumn(int[])
187 */
188 public void setMatchColumn(String columnName) throws SQLException;
189
190 /**
191 * Sets the designated columns as the match column for this <code>RowSet</code>
192 * object. A <code>JoinRowSet</code> object can now add this <code>RowSet</code>
193 * object based on the match column.
194 *
195 * @param columnNames an array of <code>String</code> objects giving the names
196 * of the column to be set as the match columns
197 * @throws SQLException if an invalid column name is set, the column name
198 * is a null, or the column name is an empty string
199 * @see #unsetMatchColumn
200 * @see #setMatchColumn(int[])
201 */
202 public void setMatchColumn(String[] columnNames)
203 throws SQLException;
204
205 /**
206 * Retrieves the indexes of the match columns that were set for this
207 * <code>RowSet</code> object with the method
208 * <code>setMatchColumn(int[] columnIdxes)</code>.
209 *
210 * @return an <code>int</code> array identifying the indexes of the columns
211 * that were set as the match columns for this <code>RowSet</code> object
212 * @throws SQLException if no match column has been set
213 * @see #setMatchColumn
214 * @see #unsetMatchColumn
215 */
216 public int[] getMatchColumnIndexes() throws SQLException;
217
218 /**
219 * Retrieves the names of the match columns that were set for this
220 * <code>RowSet</code> object with the method
221 * <code>setMatchColumn(String [] columnNames)</code>.
222 *
223 * @return an array of <code>String</code> objects giving the names of the columns
224 * set as the match columns for this <code>RowSet</code> object
225 * @throws SQLException if no match column has been set
226 * @see #setMatchColumn
227 * @see #unsetMatchColumn
228 *
229 */
230 public String[] getMatchColumnNames() throws SQLException;
231
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 columnIdx an <code>int</code> that identifies the index of the column
242 * that is to be unset as a match column
243 * @throws SQLException if an invalid column index is designated or if
244 * the designated column was not previously set as a match
245 * column
246 * @see #setMatchColumn
247 */
248 public void unsetMatchColumn(int columnIdx) throws SQLException;
249
250 /**
251 * Unsets the designated columns as the match column for this <code>RowSet</code>
252 * object.
253 *
254 * @param columnIdxes an arrary of <code>int</code> that identifies the indexes
255 * of the columns that are to be unset as match columns
256 * @throws SQLException if an invalid column index is designated or if
257 * the designated column was not previously set as a match
258 * column
259 * @see #setMatchColumn
260 */
261 public void unsetMatchColumn(int[] columnIdxes) throws SQLException;
262
263 /**
264 * Unsets the designated column as the match column for this <code>RowSet</code>
265 * object.
266 * <P>
267 * <code>RowSet</code> objects that implement the <code>Joinable</code> interface
268 * must ensure that a key-like constraint continues to be enforced until the
269 * method <code>CachedRowSet.unsetKeyColumns</code> has been called on the
270 * designated column.
271 *
272 * @param columnName a <code>String</code> object giving the name of the column
273 * that is to be unset as a match column
274 * @throws SQLException if an invalid column name is designated or
275 * the designated column was not previously set as a match
276 * column
277 * @see #setMatchColumn
278 */
279 public void unsetMatchColumn(String columnName) throws SQLException;
280
281 /**
282 * Unsets the designated columns as the match columns for this <code>RowSet</code>
283 * object.
284 *
285 * @param columnName an array of <code>String</code> objects giving the names of
286 * the columns that are to be unset as the match columns
287 * @throws SQLException if an invalid column name is designated or the
288 * designated column was not previously set as a match column
289 * @see #setMatchColumn
290 */
291 public void unsetMatchColumn(String[] columnName)
292 throws SQLException;
293 }
|