Path: blob/master/src/java.sql/share/classes/java/sql/Array.java
41153 views
/*1* Copyright (c) 1998, 2020, 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 java.sql;2627/**28* The mapping in the Java programming language for the SQL type29* {@code ARRAY}.30* By default, an {@code Array} value is a transaction-duration31* reference to an SQL {@code ARRAY} value. By default, an {@code Array}32* object is implemented using an SQL LOCATOR(array) internally, which33* means that an {@code Array} object contains a logical pointer34* to the data in the SQL {@code ARRAY} value rather35* than containing the {@code ARRAY} value's data.36* <p>37* The {@code Array} interface provides methods for bringing an SQL38* {@code ARRAY} value's data to the client as either an array or a39* {@code ResultSet} object.40* If the elements of the SQL {@code ARRAY}41* are a UDT, they may be custom mapped. To create a custom mapping,42* a programmer must do two things:43* <ul>44* <li>create a class that implements the {@link SQLData}45* interface for the UDT to be custom mapped.46* <li>make an entry in a type map that contains47* <ul>48* <li>the fully-qualified SQL type name of the UDT49* <li>the {@code Class} object for the class implementing50* {@code SQLData}51* </ul>52* </ul>53* <p>54* When a type map with an entry for55* the base type is supplied to the methods {@code getArray}56* and {@code getResultSet}, the mapping57* it contains will be used to map the elements of the {@code ARRAY} value.58* If no type map is supplied, which would typically be the case,59* the connection's type map is used by default.60* If the connection's type map or a type map supplied to a method has no entry61* for the base type, the elements are mapped according to the standard mapping.62* <p>63* All methods on the {@code Array} interface must be fully implemented if the64* JDBC driver supports the data type.65*66* @since 1.267*/6869public interface Array {7071/**72* Retrieves the SQL type name of the elements in73* the array designated by this {@code Array} object.74* If the elements are a built-in type, it returns75* the database-specific type name of the elements.76* If the elements are a user-defined type (UDT),77* this method returns the fully-qualified SQL type name.78*79* @return a {@code String} that is the database-specific80* name for a built-in base type; or the fully-qualified SQL type81* name for a base type that is a UDT82* @throws SQLException if an error occurs while attempting83* to access the type name84* @throws SQLFeatureNotSupportedException if the JDBC driver does not support85* this method86* @since 1.287*/88String getBaseTypeName() throws SQLException;8990/**91* Retrieves the JDBC type of the elements in the array designated92* by this {@code Array} object.93*94* @return a constant from the class {@link java.sql.Types} that is95* the type code for the elements in the array designated by this96* {@code Array} object97* @throws SQLException if an error occurs while attempting98* to access the base type99* @throws SQLFeatureNotSupportedException if the JDBC driver does not support100* this method101* @since 1.2102*/103int getBaseType() throws SQLException;104105/**106* Retrieves the contents of the SQL {@code ARRAY} value designated107* by this108* {@code Array} object in the form of an array in the Java109* programming language. This version of the method {@code getArray}110* uses the type map associated with the connection for customizations of111* the type mappings.112* <p>113* <strong>Note:</strong> When {@code getArray} is used to materialize114* a base type that maps to a primitive data type, then it is115* implementation-defined whether the array returned is an array of116* that primitive data type or an array of {@code Object}.117*118* @return an array in the Java programming language that contains119* the ordered elements of the SQL {@code ARRAY} value120* designated by this {@code Array} object121* @throws SQLException if an error occurs while attempting to122* access the array123* @throws SQLFeatureNotSupportedException if the JDBC driver does not support124* this method125* @since 1.2126*/127Object getArray() throws SQLException;128129/**130* Retrieves the contents of the SQL {@code ARRAY} value designated by this131* {@code Array} object.132* This method uses133* the specified {@code map} for type map customizations134* unless the base type of the array does not match a user-defined135* type in {@code map}, in which case it136* uses the standard mapping. This version of the method137* {@code getArray} uses either the given type map or the standard mapping;138* it never uses the type map associated with the connection.139* <p>140* <strong>Note:</strong> When {@code getArray} is used to materialize141* a base type that maps to a primitive data type, then it is142* implementation-defined whether the array returned is an array of143* that primitive data type or an array of {@code Object}.144*145* @param map a {@code java.util.Map} object that contains mappings146* of SQL type names to classes in the Java programming language147* @return an array in the Java programming language that contains the ordered148* elements of the SQL array designated by this object149* @throws SQLException if an error occurs while attempting to150* access the array151* @throws SQLFeatureNotSupportedException if the JDBC driver does not support152* this method153* @since 1.2154*/155Object getArray(java.util.Map<String,Class<?>> map) throws SQLException;156157/**158* Retrieves a slice of the SQL {@code ARRAY}159* value designated by this {@code Array} object, beginning with the160* specified {@code index} and containing up to {@code count}161* successive elements of the SQL array. This method uses the type map162* associated with the connection for customizations of the type mappings.163* <p>164* <strong>Note:</strong> When {@code getArray} is used to materialize165* a base type that maps to a primitive data type, then it is166* implementation-defined whether the array returned is an array of167* that primitive data type or an array of {@code Object}.168*169* @param index the array index of the first element to retrieve;170* the first element is at index 1171* @param count the number of successive SQL array elements to retrieve172* @return an array containing up to {@code count} consecutive elements173* of the SQL array, beginning with element {@code index}174* @throws SQLException if an error occurs while attempting to175* access the array176* @throws SQLFeatureNotSupportedException if the JDBC driver does not support177* this method178* @since 1.2179*/180Object getArray(long index, int count) throws SQLException;181182/**183* Retrieves a slice of the SQL {@code ARRAY} value184* designated by this {@code Array} object, beginning with the specified185* {@code index} and containing up to {@code count}186* successive elements of the SQL array.187* <P>188* This method uses189* the specified {@code map} for type map customizations190* unless the base type of the array does not match a user-defined191* type in {@code map}, in which case it192* uses the standard mapping. This version of the method193* {@code getArray} uses either the given type map or the standard mapping;194* it never uses the type map associated with the connection.195* <p>196* <strong>Note:</strong> When {@code getArray} is used to materialize197* a base type that maps to a primitive data type, then it is198* implementation-defined whether the array returned is an array of199* that primitive data type or an array of {@code Object}.200*201* @param index the array index of the first element to retrieve;202* the first element is at index 1203* @param count the number of successive SQL array elements to204* retrieve205* @param map a {@code java.util.Map} object206* that contains SQL type names and the classes in207* the Java programming language to which they are mapped208* @return an array containing up to {@code count}209* consecutive elements of the SQL {@code ARRAY} value designated by this210* {@code Array} object, beginning with element211* {@code index}212* @throws SQLException if an error occurs while attempting to213* access the array214* @throws SQLFeatureNotSupportedException if the JDBC driver does not support215* this method216* @since 1.2217*/218Object getArray(long index, int count, java.util.Map<String,Class<?>> map)219throws SQLException;220221/**222* Retrieves a result set that contains the elements of the SQL223* {@code ARRAY} value224* designated by this {@code Array} object. If appropriate,225* the elements of the array are mapped using the connection's type226* map; otherwise, the standard mapping is used.227* <p>228* The result set contains one row for each array element, with229* two columns in each row. The second column stores the element230* value; the first column stores the index into the array for231* that element (with the first array element being at index 1).232* The rows are in ascending order corresponding to233* the order of the indices.234*235* @return a {@link ResultSet} object containing one row for each236* of the elements in the array designated by this {@code Array}237* object, with the rows in ascending order based on the indices.238* @throws SQLException if an error occurs while attempting to239* access the array240* @throws SQLFeatureNotSupportedException if the JDBC driver does not support241* this method242* @since 1.2243*/244ResultSet getResultSet () throws SQLException;245246/**247* Retrieves a result set that contains the elements of the SQL248* {@code ARRAY} value designated by this {@code Array} object.249* This method uses250* the specified {@code map} for type map customizations251* unless the base type of the array does not match a user-defined252* type in {@code map}, in which case it253* uses the standard mapping. This version of the method254* {@code getResultSet} uses either the given type map or the standard mapping;255* it never uses the type map associated with the connection.256* <p>257* The result set contains one row for each array element, with258* two columns in each row. The second column stores the element259* value; the first column stores the index into the array for260* that element (with the first array element being at index 1).261* The rows are in ascending order corresponding to262* the order of the indices.263*264* @param map contains the mapping of SQL user-defined types to265* classes in the Java programming language266* @return a {@code ResultSet} object containing one row for each267* of the elements in the array designated by this {@code Array}268* object, with the rows in ascending order based on the indices.269* @throws SQLException if an error occurs while attempting to270* access the array271* @throws SQLFeatureNotSupportedException if the JDBC driver does not support272* this method273* @since 1.2274*/275ResultSet getResultSet (java.util.Map<String,Class<?>> map) throws SQLException;276277/**278* Retrieves a result set holding the elements of the subarray that279* starts at index {@code index} and contains up to280* {@code count} successive elements. This method uses281* the connection's type map to map the elements of the array if282* the map contains an entry for the base type. Otherwise, the283* standard mapping is used.284* <P>285* The result set has one row for each element of the SQL array286* designated by this object, with the first row containing the287* element at index {@code index}. The result set has288* up to {@code count} rows in ascending order based on the289* indices. Each row has two columns: The second column stores290* the element value; the first column stores the index into the291* array for that element.292*293* @param index the array index of the first element to retrieve;294* the first element is at index 1295* @param count the number of successive SQL array elements to retrieve296* @return a {@code ResultSet} object containing up to297* {@code count} consecutive elements of the SQL array298* designated by this {@code Array} object, starting at299* index {@code index}.300* @throws SQLException if an error occurs while attempting to301* access the array302* @throws SQLFeatureNotSupportedException if the JDBC driver does not support303* this method304* @since 1.2305*/306ResultSet getResultSet(long index, int count) throws SQLException;307308/**309* Retrieves a result set holding the elements of the subarray that310* starts at index {@code index} and contains up to311* {@code count} successive elements.312* This method uses313* the specified {@code map} for type map customizations314* unless the base type of the array does not match a user-defined315* type in {@code map}, in which case it316* uses the standard mapping. This version of the method317* {@code getResultSet} uses either the given type map or the standard mapping;318* it never uses the type map associated with the connection.319* <P>320* The result set has one row for each element of the SQL array321* designated by this object, with the first row containing the322* element at index {@code index}. The result set has323* up to {@code count} rows in ascending order based on the324* indices. Each row has two columns: The second column stores325* the element value; the first column stores the index into the326* array for that element.327*328* @param index the array index of the first element to retrieve;329* the first element is at index 1330* @param count the number of successive SQL array elements to retrieve331* @param map the {@code Map} object that contains the mapping332* of SQL type names to classes in the Java(tm) programming language333* @return a {@code ResultSet} object containing up to334* {@code count} consecutive elements of the SQL array335* designated by this {@code Array} object, starting at336* index {@code index}.337* @throws SQLException if an error occurs while attempting to338* access the array339* @throws SQLFeatureNotSupportedException if the JDBC driver does not support340* this method341* @since 1.2342*/343ResultSet getResultSet (long index, int count,344java.util.Map<String,Class<?>> map)345throws SQLException;346/**347* This method frees the {@code Array} object and releases the resources that348* it holds. The object is invalid once the {@code free}349* method is called.350* <p>351* After {@code free} has been called, any attempt to invoke a352* method other than {@code free} will result in a {@code SQLException}353* being thrown. If {@code free} is called multiple times, the subsequent354* calls to {@code free} are treated as a no-op.355*356* @throws SQLException if an error occurs releasing357* the Array's resources358* @throws SQLFeatureNotSupportedException if the JDBC driver does not support359* this method360* @since 1.6361*/362void free() throws SQLException;363364}365366367