Path: blob/master/src/java.sql.rowset/share/classes/javax/sql/rowset/Joinable.java
40948 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sql.rowset;2627import java.sql.SQLException;2829/**30* <h2>1.0 Background</h2>31* The <code>Joinable</code> interface provides the methods for getting and32* setting a match column, which is the basis for forming the SQL <code>JOIN</code>33* formed by adding <code>RowSet</code> objects to a <code>JoinRowSet</code>34* object.35* <P>36* Any standard <code>RowSet</code> implementation <b>may</b> implement37* the <code>Joinable</code> interface in order to be38* added to a <code>JoinRowSet</code> object. Implementing this interface gives39* a <code>RowSet</code> object the ability to use <code>Joinable</code> methods,40* which set, retrieve, and get information about match columns. An41* application may add a42* <code>RowSet</code> object that has not implemented the <code>Joinable</code>43* interface to a <code>JoinRowSet</code> object, but to do so it must use one44* of the <code>JoinRowSet.addRowSet</code> methods that takes both a45* <code>RowSet</code> object and a match column or an array of <code>RowSet</code>46* objects and an array of match columns.47* <P>48* To get access to the methods in the <code>Joinable</code> interface, a49* <code>RowSet</code> object implements at least one of the50* five standard <code>RowSet</code> interfaces and also implements the51* <code>Joinable</code> interface. In addition, most <code>RowSet</code>52* objects extend the <code>BaseRowSet</code> class. For example:53* <pre>54* class MyRowSetImpl extends BaseRowSet implements CachedRowSet, Joinable {55* :56* :57* }58* </pre>59*60* <h2>2.0 Usage Guidelines</h2>61* <P>62* The methods in the <code>Joinable</code> interface allow a <code>RowSet</code> object63* to set a match column, retrieve a match column, or unset a match column, which is64* the column upon which an SQL <code>JOIN</code> can be based.65* An instance of a class that implements these methods can be added to a66* <code>JoinRowSet</code> object to allow an SQL <code>JOIN</code> relationship to67* be established.68*69* <pre>70* CachedRowSet crs = new MyRowSetImpl();71* crs.populate((ResultSet)rs);72* (Joinable)crs.setMatchColumnIndex(1);73*74* JoinRowSet jrs = new JoinRowSetImpl();75* jrs.addRowSet(crs);76* </pre>77* In the previous example, <i>crs</i> is a <code>CachedRowSet</code> object that78* has implemented the <code>Joinable</code> interface. In the following example,79* <i>crs2</i> has not, so it must supply the match column as an argument to the80* <code>addRowSet</code> method. This example assumes that column 1 is the match81* column.82* <PRE>83* CachedRowSet crs2 = new MyRowSetImpl();84* crs2.populate((ResultSet)rs);85*86* JoinRowSet jrs2 = new JoinRowSetImpl();87* jrs2.addRowSet(crs2, 1);88* </PRE>89* <p>90* The <code>JoinRowSet</code> interface makes it possible to get data from one or91* more <code>RowSet</code> objects consolidated into one table without having to incur92* the expense of creating a connection to a database. It is therefore ideally suited93* for use by disconnected <code>RowSet</code> objects. Nevertheless, any94* <code>RowSet</code> object <b>may</b> implement this interface95* regardless of whether it is connected or disconnected. Note that a96* <code>JdbcRowSet</code> object, being always connected to its data source, can97* become part of an SQL <code>JOIN</code> directly without having to become part98* of a <code>JoinRowSet</code> object.99*100* <h2>3.0 Managing Multiple Match Columns</h2>101* The index array passed into the <code>setMatchColumn</code> methods indicates102* how many match columns are being set (the length of the array) in addition to103* which columns will be used for the match. For example:104* <pre>105* int[] i = {1, 2, 4, 7}; // indicates four match columns, with column106* // indexes 1, 2, 4, 7 participating in the JOIN.107* Joinable.setMatchColumn(i);108* </pre>109* Subsequent match columns may be added as follows to a different <code>Joinable</code>110* object (a <code>RowSet</code> object that has implemented the <code>Joinable</code>111* interface).112* <pre>113* int[] w = {3, 2, 5, 3};114* Joinable2.setMatchColumn(w);115* </pre>116* When an application adds two or more <code>RowSet</code> objects to a117* <code>JoinRowSet</code> object, the order of the indexes in the array is118* particularly important. Each index of119* the array maps directly to the corresponding index of the previously added120* <code>RowSet</code> object. If overlap or underlap occurs, the match column121* data is maintained in the event an additional <code>Joinable</code> RowSet is122* added and needs to relate to the match column data. Therefore, applications123* can set multiple match columns in any order, but124* this order has a direct effect on the outcome of the <code>SQL</code> JOIN.125* <p>126* This assertion applies in exactly the same manner when column names are used127* rather than column indexes to indicate match columns.128*129* @see JoinRowSet130* @author Jonathan Bruce131* @since 1.5132*/133public interface Joinable {134135/**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>141* interface define the method <code>CachedRowSet.setKeyColumns</code>, which allows142* primary key semantics to be enforced on specific columns.143* Implementations of the <code>setMatchColumn(int columnIdx)</code> method144* should ensure that the constraints on the key columns are maintained when145* 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 be148* set as the match column149* @throws SQLException if an invalid column index is set150* @see #setMatchColumn(int[])151* @see #unsetMatchColumn(int)152*153*/154public void setMatchColumn(int columnIdx) throws SQLException;155156/**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 the162* columns to be set as the match columns163* @throws SQLException if an invalid column index is set164* @see #setMatchColumn(int[])165* @see #unsetMatchColumn(int[])166*/167public void setMatchColumn(int[] columnIdxes) throws SQLException;168169/**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 define175* the method <code>CachedRowSet.setKeyColumns</code>, which allows176* primary key semantics to be enforced on specific columns.177* Implementations of the <code>setMatchColumn(String columnIdx)</code> method178* should ensure that the constraints on the key columns are maintained when179* 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 column182* to be set as the match column183* @throws SQLException if an invalid column name is set, the column name184* is a null, or the column name is an empty string185* @see #unsetMatchColumn186* @see #setMatchColumn(int[])187*/188public void setMatchColumn(String columnName) throws SQLException;189190/**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 names196* of the column to be set as the match columns197* @throws SQLException if an invalid column name is set, the column name198* is a null, or the column name is an empty string199* @see #unsetMatchColumn200* @see #setMatchColumn(int[])201*/202public void setMatchColumn(String[] columnNames) throws SQLException;203204/**205* Retrieves the indexes of the match columns that were set for this206* <code>RowSet</code> object with the method207* <code>setMatchColumn(int[] columnIdxes)</code>.208*209* @return an <code>int</code> array identifying the indexes of the columns210* that were set as the match columns for this <code>RowSet</code> object211* @throws SQLException if no match column has been set212* @see #setMatchColumn213* @see #unsetMatchColumn214*/215public int[] getMatchColumnIndexes() throws SQLException;216217/**218* Retrieves the names of the match columns that were set for this219* <code>RowSet</code> object with the method220* <code>setMatchColumn(String [] columnNames)</code>.221*222* @return an array of <code>String</code> objects giving the names of the columns223* set as the match columns for this <code>RowSet</code> object224* @throws SQLException if no match column has been set225* @see #setMatchColumn226* @see #unsetMatchColumn227*228*/229public String[] getMatchColumnNames() throws SQLException;230231/**232* Unsets the designated column as the match column for this <code>RowSet</code>233* object.234* <P>235* <code>RowSet</code> objects that implement the <code>Joinable</code> interface236* must ensure that a key-like constraint continues to be enforced until the237* method <code>CachedRowSet.unsetKeyColumns</code> has been called on the238* designated column.239*240* @param columnIdx an <code>int</code> that identifies the index of the column241* that is to be unset as a match column242* @throws SQLException if an invalid column index is designated or if243* the designated column was not previously set as a match244* column245* @see #setMatchColumn246*/247public void unsetMatchColumn(int columnIdx) throws SQLException;248249/**250* Unsets the designated columns as the match column for this <code>RowSet</code>251* object.252*253* @param columnIdxes an array of <code>int</code> that identifies the indexes254* of the columns that are to be unset as match columns255* @throws SQLException if an invalid column index is designated or if256* the designated column was not previously set as a match257* column258* @see #setMatchColumn259*/260public void unsetMatchColumn(int[] columnIdxes) throws SQLException;261262/**263* Unsets the designated column as the match column for this <code>RowSet</code>264* object.265* <P>266* <code>RowSet</code> objects that implement the <code>Joinable</code> interface267* must ensure that a key-like constraint continues to be enforced until the268* method <code>CachedRowSet.unsetKeyColumns</code> has been called on the269* designated column.270*271* @param columnName a <code>String</code> object giving the name of the column272* that is to be unset as a match column273* @throws SQLException if an invalid column name is designated or274* the designated column was not previously set as a match275* column276* @see #setMatchColumn277*/278public void unsetMatchColumn(String columnName) throws SQLException;279280/**281* Unsets the designated columns as the match columns for this <code>RowSet</code>282* object.283*284* @param columnName an array of <code>String</code> objects giving the names of285* the columns that are to be unset as the match columns286* @throws SQLException if an invalid column name is designated or the287* designated column was not previously set as a match column288* @see #setMatchColumn289*/290public void unsetMatchColumn(String[] columnName) throws SQLException;291}292293294