Path: blob/master/src/java.sql/share/classes/java/sql/SQLClientInfoException.java
41153 views
/*1* Copyright (c) 2006, 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*/24package java.sql;2526import java.util.Map;2728/**29* The subclass of {@link SQLException} is thrown when one or more client info properties30* could not be set on a {@code Connection}. In addition to the information provided31* by {@code SQLException}, a {@code SQLClientInfoException} provides a list of client info32* properties that were not set.33*34* Some databases do not allow multiple client info properties to be set35* atomically. For those databases, it is possible that some of the client36* info properties had been set even though the {@code Connection.setClientInfo}37* method threw an exception. An application can use the {@code getFailedProperties}38* method to retrieve a list of client info properties that were not set. The39* properties are identified by passing a40* {@code Map<String,ClientInfoStatus>} to41* the appropriate {@code SQLClientInfoException} constructor.42*43* @see ClientInfoStatus44* @see Connection#setClientInfo45* @since 1.646*/47public class SQLClientInfoException extends SQLException {4849/**50* A {@code Map} containing the client info properties that could not be set.51*/52@SuppressWarnings("serial") // Not statically typed as Serializable53private Map<String, ClientInfoStatus> failedProperties;5455/**56* Constructs a {@code SQLClientInfoException} Object.57* The {@code reason},58* {@code SQLState}, and failedProperties list are initialized to59* {@code null} and the vendor code is initialized to 0.60* The {@code cause} is not initialized, and may subsequently be61* initialized by a call to the62* {@link Throwable#initCause(java.lang.Throwable)} method.63*64* @since 1.665*/66public SQLClientInfoException() {6768this.failedProperties = null;69}7071/**72* Constructs a {@code SQLClientInfoException} object initialized with a73* given {@code failedProperties}.74* The {@code reason} and {@code SQLState} are initialized75* to {@code null} and the vendor code is initialized to 0.76*77* The {@code cause} is not initialized, and may subsequently be78* initialized by a call to the79* {@link Throwable#initCause(java.lang.Throwable)} method.80*81* @param failedProperties A Map containing the property values that could not82* be set. The keys in the Map83* contain the names of the client info84* properties that could not be set and85* the values contain one of the reason codes86* defined in {@code ClientInfoStatus}87*88* @since 1.689*/90public SQLClientInfoException(Map<String, ClientInfoStatus> failedProperties) {9192this.failedProperties = failedProperties;93}9495/**96* Constructs a {@code SQLClientInfoException} object initialized with97* a given {@code cause} and {@code failedProperties}.98*99* The {@code reason} is initialized to {@code null} if100* {@code cause==null} or to {@code cause.toString()} if101* {@code cause!=null} and the vendor code is initialized to 0.102*103* @param failedProperties A Map containing the property values that could not104* be set. The keys in the Map105* contain the names of the client info106* properties that could not be set and107* the values contain one of the reason codes108* defined in {@code ClientInfoStatus}109* @param cause the (which is saved for later retrieval by the {@code getCause()} method); may be null indicating110* the cause is non-existent or unknown.111*112* @since 1.6113*/114public SQLClientInfoException(Map<String, ClientInfoStatus> failedProperties,115Throwable cause) {116117super(cause != null?cause.toString():null);118initCause(cause);119this.failedProperties = failedProperties;120}121122/**123* Constructs a {@code SQLClientInfoException} object initialized with a124* given {@code reason} and {@code failedProperties}.125* The {@code SQLState} is initialized126* to {@code null} and the vendor code is initialized to 0.127*128* The {@code cause} is not initialized, and may subsequently be129* initialized by a call to the130* {@link Throwable#initCause(java.lang.Throwable)} method.131*132* @param reason a description of the exception133* @param failedProperties A Map containing the property values that could not134* be set. The keys in the Map135* contain the names of the client info136* properties that could not be set and137* the values contain one of the reason codes138* defined in {@code ClientInfoStatus}139*140* @since 1.6141*/142public SQLClientInfoException(String reason,143Map<String, ClientInfoStatus> failedProperties) {144145super(reason);146this.failedProperties = failedProperties;147}148149/**150* Constructs a {@code SQLClientInfoException} object initialized with a151* given {@code reason}, {@code cause} and152* {@code failedProperties}.153* The {@code SQLState} is initialized154* to {@code null} and the vendor code is initialized to 0.155*156* @param reason a description of the exception157* @param failedProperties A Map containing the property values that could not158* be set. The keys in the Map159* contain the names of the client info160* properties that could not be set and161* the values contain one of the reason codes162* defined in {@code ClientInfoStatus}163* @param cause the underlying reason for this {@code SQLException} (which is saved for later retrieval by the {@code getCause()} method); may be null indicating164* the cause is non-existent or unknown.165*166* @since 1.6167*/168public SQLClientInfoException(String reason,169Map<String, ClientInfoStatus> failedProperties,170Throwable cause) {171172super(reason);173initCause(cause);174this.failedProperties = failedProperties;175}176177/**178* Constructs a {@code SQLClientInfoException} object initialized with a179* given {@code reason}, {@code SQLState} and180* {@code failedProperties}.181* The {@code cause} is not initialized, and may subsequently be182* initialized by a call to the183* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code184* is initialized to 0.185*186* @param reason a description of the exception187* @param SQLState an XOPEN or SQL:2003 code identifying the exception188* @param failedProperties A Map containing the property values that could not189* be set. The keys in the Map190* contain the names of the client info191* properties that could not be set and192* the values contain one of the reason codes193* defined in {@code ClientInfoStatus}194*195* @since 1.6196*/197public SQLClientInfoException(String reason,198String SQLState,199Map<String, ClientInfoStatus> failedProperties) {200201super(reason, SQLState);202this.failedProperties = failedProperties;203}204205/**206* Constructs a {@code SQLClientInfoException} object initialized with a207* given {@code reason}, {@code SQLState}, {@code cause}208* and {@code failedProperties}. The vendor code is initialized to 0.209*210* @param reason a description of the exception211* @param SQLState an XOPEN or SQL:2003 code identifying the exception212* @param failedProperties A Map containing the property values that could not213* be set. The keys in the Map214* contain the names of the client info215* properties that could not be set and216* the values contain one of the reason codes217* defined in {@code ClientInfoStatus}218* @param cause the underlying reason for this {@code SQLException} (which is saved for later retrieval by the {@code getCause()} method); may be null indicating219* the cause is non-existent or unknown.220*221* @since 1.6222*/223public SQLClientInfoException(String reason,224String SQLState,225Map<String, ClientInfoStatus> failedProperties,226Throwable cause) {227228super(reason, SQLState);229initCause(cause);230this.failedProperties = failedProperties;231}232233/**234* Constructs a {@code SQLClientInfoException} object initialized with a235* given {@code reason}, {@code SQLState},236* {@code vendorCode} and {@code failedProperties}.237* The {@code cause} is not initialized, and may subsequently be238* initialized by a call to the239* {@link Throwable#initCause(java.lang.Throwable)} method.240*241* @param reason a description of the exception242* @param SQLState an XOPEN or SQL:2003 code identifying the exception243* @param vendorCode a database vendor-specific exception code244* @param failedProperties A Map containing the property values that could not245* be set. The keys in the Map246* contain the names of the client info247* properties that could not be set and248* the values contain one of the reason codes249* defined in {@code ClientInfoStatus}250*251* @since 1.6252*/253public SQLClientInfoException(String reason,254String SQLState,255int vendorCode,256Map<String, ClientInfoStatus> failedProperties) {257258super(reason, SQLState, vendorCode);259this.failedProperties = failedProperties;260}261262/**263* Constructs a {@code SQLClientInfoException} object initialized with a264* given {@code reason}, {@code SQLState},265* {@code cause}, {@code vendorCode} and266* {@code failedProperties}.267*268* @param reason a description of the exception269* @param SQLState an XOPEN or SQL:2003 code identifying the exception270* @param vendorCode a database vendor-specific exception code271* @param failedProperties A Map containing the property values that could not272* be set. The keys in the Map273* contain the names of the client info274* properties that could not be set and275* the values contain one of the reason codes276* defined in {@code ClientInfoStatus}277* @param cause the underlying reason for this {@code SQLException} (which is saved for later retrieval by the {@code getCause()} method); may be null indicating278* the cause is non-existent or unknown.279*280* @since 1.6281*/282public SQLClientInfoException(String reason,283String SQLState,284int vendorCode,285Map<String, ClientInfoStatus> failedProperties,286Throwable cause) {287288super(reason, SQLState, vendorCode);289initCause(cause);290this.failedProperties = failedProperties;291}292293/**294* Returns the list of client info properties that could not be set. The295* keys in the Map contain the names of the client info296* properties that could not be set and the values contain one of the297* reason codes defined in {@code ClientInfoStatus}298*299* @return Map list containing the client info properties that could300* not be set301*302* @since 1.6303*/304public Map<String, ClientInfoStatus> getFailedProperties() {305306return this.failedProperties;307}308309private static final long serialVersionUID = -4319604256824655880L;310}311312313