001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.sql;
019:
020: import java.io.Serializable;
021:
022: /**
023: * An exception thrown if a problem occurs during a batch update operation.
024: * <p>
025: * A BatchUpdateException provides additional information about the problem that
026: * occurred, compared with a standard SQLException. It supplies update counts
027: * for successful commands that executed within the batch update, but before the
028: * exception was encountered.
029: * <p>
030: * The element order in the array of update counts matches the order that the
031: * commands were added to the batch operation.
032: * <p>
033: * Once a batch update command fails and a BatchUpdateException is thrown, the
034: * JDBC driver may continue processing the remaining commands in the batch. If
035: * the driver does process more commands after the problem occurs, the array
036: * returned by BatchUpdateException.getUpdateCounts has an element for every
037: * command in the batch, not only those that executed successfully. In this
038: * case, the array element for any command which encountered a problem is set to
039: * Statement.EXECUTE_FAILED.
040: */
041: public class BatchUpdateException extends SQLException implements
042: Serializable {
043:
044: private static final long serialVersionUID = 5977529877145521757L;
045:
046: private int[] updateCounts = null;
047:
048: /**
049: * Creates a BatchUpdateException with the Reason, SQLState, and Update
050: * Counts set to null and a Vendor Code of 0.
051: */
052: public BatchUpdateException() {
053: super ();
054: }
055:
056: /**
057: * Creates a BatchUpdateException with the Update Counts set to the supplied
058: * value and the Reason, SQLState set to null and a Vendor Code of 0.
059: *
060: * @param updateCounts
061: * the array of Update Counts to use in initialization
062: */
063: public BatchUpdateException(int[] updateCounts) {
064: super ();
065: this .updateCounts = updateCounts;
066: }
067:
068: /**
069: * Creates a BatchUpdateException with the Update Counts set to the supplied
070: * value, the Reason set to the supplied value and SQLState set to null and
071: * a Vendor Code of 0.
072: *
073: * @param reason
074: * the initialization value for Reason
075: * @param updateCounts
076: * the array of Update Counts to set
077: */
078: public BatchUpdateException(String reason, int[] updateCounts) {
079: super (reason);
080: this .updateCounts = updateCounts;
081: }
082:
083: /**
084: * Creates a BatchUpdateException with the Update Counts set to the supplied
085: * value, the Reason set to the supplied value, the SQLState initialized to
086: * the supplied value and the Vendor Code initialized to 0.
087: *
088: * @param reason
089: * the value to use for the Reason
090: * @param SQLState
091: * the X/OPEN value to use for the SQLState
092: * @param updateCounts
093: * the array of Update Counts to set
094: */
095: public BatchUpdateException(String reason, String SQLState,
096: int[] updateCounts) {
097: super (reason, SQLState);
098: this .updateCounts = updateCounts;
099: }
100:
101: /**
102: * Creates a BatchUpdateException with the Update Counts set to the supplied
103: * value, the Reason set to the supplied value, the SQLState initialized to
104: * the supplied value and the Vendor Code set to the supplied value.
105: *
106: * @param reason
107: * the value to use for the Reason
108: * @param SQLState
109: * the X/OPEN value to use for the SQLState
110: * @param vendorCode
111: * the value to use for the vendor error code
112: * @param updateCounts
113: * the array of Update Counts to set
114: */
115: public BatchUpdateException(String reason, String SQLState,
116: int vendorCode, int[] updateCounts) {
117: super (reason, SQLState, vendorCode);
118: this .updateCounts = updateCounts;
119: }
120:
121: /**
122: * Gets the Update Counts array.
123: * <p>
124: * If a batch update command fails and a BatchUpdateException is thrown, the
125: * JDBC driver may continue processing the remaining commands in the batch.
126: * If the driver does process more commands after the problem occurs, the
127: * array returned by <code>BatchUpdateException.getUpdateCounts</code> has
128: * an element for every command in the batch, not only those that executed
129: * successfully. In this case, the array element for any command which
130: * encountered a problem is set to Statement.EXECUTE_FAILED.
131: *
132: * @return an array that contains the successful update counts, before this
133: * exception. Alternatively, if the driver continues to process
134: * commands following an error, one of these listed items for every
135: * command the batch contains:
136: * <ol>
137: * <li>an count of the updates</li>
138: * <li><code>Statement.SUCCESS_NO_INFO</code> indicating that the
139: * command completed successfully, but the amount of altered rows is
140: * not known.</li>
141: * <li><code>Statement.EXECUTE_FAILED</code> indicating that the
142: * command was unsuccessful.
143: * </ol>
144: */
145: public int[] getUpdateCounts() {
146: return updateCounts;
147: }
148: }
|