/projects/jre-1.6.0/src/java/sql/BatchUpdateException.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 328 lines · 52 code · 16 blank · 260 comment · 0 complexity · eccfd937c93c1d79cd4554d1d54e4952 MD5 · raw file

  1. /*
  2. * %W% %E%
  3. *
  4. * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
  5. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * The subclass of {@link SQLException} thrown when an error
  10. * occurs during a batch update operation. In addition to the
  11. * information provided by {@link SQLException}, a
  12. * <code>BatchUpdateException</code> provides the update
  13. * counts for all commands that were executed successfully during the
  14. * batch update, that is, all commands that were executed before the error
  15. * occurred. The order of elements in an array of update counts
  16. * corresponds to the order in which commands were added to the batch.
  17. * <P>
  18. * After a command in a batch update fails to execute properly
  19. * and a <code>BatchUpdateException</code> is thrown, the driver
  20. * may or may not continue to process the remaining commands in
  21. * the batch. If the driver continues processing after a failure,
  22. * the array returned by the method
  23. * <code>BatchUpdateException.getUpdateCounts</code> will have
  24. * an element for every command in the batch rather than only
  25. * elements for the commands that executed successfully before
  26. * the error. In the case where the driver continues processing
  27. * commands, the array element for any command
  28. * that failed is <code>Statement.EXECUTE_FAILED</code>.
  29. * <P>
  30. * @since 1.2
  31. */
  32. public class BatchUpdateException extends SQLException {
  33. /**
  34. * Constructs a <code>BatchUpdateException</code> object initialized with a given
  35. * <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code> and
  36. * <code>updateCounts</code>.
  37. * The <code>cause</code> is not initialized, and may subsequently be
  38. * initialized by a call to the
  39. * {@link Throwable#initCause(java.lang.Throwable)} method.
  40. * <p>
  41. *
  42. * @param reason a description of the error
  43. * @param SQLState an XOPEN or SQL:2003 code identifying the exception
  44. * @param vendorCode an exception code used by a particular
  45. * database vendor
  46. * @param updateCounts an array of <code>int</code>, with each element
  47. * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  48. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  49. * the batch for JDBC drivers that continue processing
  50. * after a command failure; an update count or
  51. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  52. * prior to the failure for JDBC drivers that stop processing after a command
  53. * failure
  54. * @since 1.2
  55. */
  56. public BatchUpdateException( String reason, String SQLState, int vendorCode,
  57. int[] updateCounts ) {
  58. super(reason, SQLState, vendorCode);
  59. this.updateCounts = updateCounts;
  60. }
  61. /**
  62. * Constructs a <code>BatchUpdateException</code> object initialized with a given
  63. * <code>reason</code>, <code>SQLState</code> and
  64. * <code>updateCounts</code>.
  65. * The <code>cause</code> is not initialized, and may subsequently be
  66. * initialized by a call to the
  67. * {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
  68. * is intialized to 0.
  69. * <p>
  70. *
  71. * @param reason a description of the exception
  72. * @param SQLState an XOPEN or SQL:2003 code identifying the exception
  73. * @param updateCounts an array of <code>int</code>, with each element
  74. * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  75. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  76. * the batch for JDBC drivers that continue processing
  77. * after a command failure; an update count or
  78. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  79. * prior to the failure for JDBC drivers that stop processing after a command
  80. * failure
  81. * @since 1.2
  82. */
  83. public BatchUpdateException(String reason, String SQLState,
  84. int[] updateCounts) {
  85. super(reason, SQLState);
  86. this.updateCounts = updateCounts;
  87. }
  88. /**
  89. * Constructs a <code>BatchUpdateException</code> object initialized with a given
  90. * <code>reason</code> and <code>updateCounts</code>.
  91. * The <code>cause</code> is not initialized, and may subsequently be
  92. * initialized by a call to the
  93. * {@link Throwable#initCause(java.lang.Throwable)} method. The
  94. * <code>SQLState</code> is initialized to <code>null</code>
  95. * and the vender code is initialized to 0.
  96. * <p>
  97. *
  98. *
  99. * @param reason a description of the exception
  100. * @param updateCounts an array of <code>int</code>, with each element
  101. * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  102. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  103. * the batch for JDBC drivers that continue processing
  104. * after a command failure; an update count or
  105. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  106. * prior to the failure for JDBC drivers that stop processing after a command
  107. * failure
  108. * @since 1.2
  109. */
  110. public BatchUpdateException(String reason, int[] updateCounts) {
  111. super(reason);
  112. this.updateCounts = updateCounts;
  113. }
  114. /**
  115. * Constructs a <code>BatchUpdateException</code> object initialized with a given
  116. * <code>updateCounts</code>.
  117. * initialized by a call to the
  118. * {@link Throwable#initCause(java.lang.Throwable)} method. The <code>reason</code>
  119. * and <code>SQLState</code> are initialized to null and the vendor code
  120. * is initialized to 0.
  121. * <p>
  122. *
  123. * @param updateCounts an array of <code>int</code>, with each element
  124. * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  125. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  126. * the batch for JDBC drivers that continue processing
  127. * after a command failure; an update count or
  128. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  129. * prior to the failure for JDBC drivers that stop processing after a command
  130. * failure
  131. * @since 1.2
  132. */
  133. public BatchUpdateException(int[] updateCounts) {
  134. super();
  135. this.updateCounts = updateCounts;
  136. }
  137. /**
  138. * Constructs a <code>BatchUpdateException</code> object.
  139. * The <code>reason</code>, <code>SQLState</code> and <code>updateCounts</code>
  140. * are initialized to <code>null</code> and the vendor code is initialized to 0.
  141. * The <code>cause</code> is not initialized, and may subsequently be
  142. * initialized by a call to the
  143. * {@link Throwable#initCause(java.lang.Throwable)} method.
  144. * <p>
  145. *
  146. * @since 1.2
  147. */
  148. public BatchUpdateException() {
  149. super();
  150. this.updateCounts = null;
  151. }
  152. /**
  153. * Constructs a <code>BatchUpdateException</code> object initialized with
  154. * a given <code>cause</code>.
  155. * The <code>SQLState</code> and <code>updateCounts</code>
  156. * are initialized
  157. * to <code>null</code> and the vendor code is initialized to 0.
  158. * The <code>reason</code> is initialized to <code>null</code> if
  159. * <code>cause==null</code> or to <code>cause.toString()</code> if
  160. * <code>cause!=null</code>.
  161. * @param cause the underlying reason for this <code>SQLException</code>
  162. * (which is saved for later retrieval by the <code>getCause()</code> method);
  163. * may be null indicating the cause is non-existent or unknown.
  164. * @since 1.6
  165. */
  166. public BatchUpdateException(Throwable cause) {
  167. super(cause);
  168. this.updateCounts = null;
  169. }
  170. /**
  171. * Constructs a <code>BatchUpdateException</code> object initialized with a
  172. * given <code>cause</code> and <code>updateCounts</code>.
  173. * The <code>SQLState</code> is initialized
  174. * to <code>null</code> and the vendor code is initialized to 0.
  175. * The <code>reason</code> is initialized to <code>null</code> if
  176. * <code>cause==null</code> or to <code>cause.toString()</code> if
  177. * <code>cause!=null</code>.
  178. *
  179. * @param updateCounts an array of <code>int</code>, with each element
  180. * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  181. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  182. * the batch for JDBC drivers that continue processing
  183. * after a command failure; an update count or
  184. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  185. * prior to the failure for JDBC drivers that stop processing after a command
  186. * failure
  187. * @param cause the underlying reason for this <code>SQLException</code>
  188. * (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
  189. * the cause is non-existent or unknown.
  190. * @since 1.6
  191. */
  192. public BatchUpdateException(int []updateCounts , Throwable cause) {
  193. super(cause);
  194. this.updateCounts = updateCounts;
  195. }
  196. /**
  197. * Constructs a <code>BatchUpdateException</code> object initialized with
  198. * a given <code>reason</code>, <code>cause</code>
  199. * and <code>updateCounts</code>. The <code>SQLState</code> is initialized
  200. * to <code>null</code> and the vendor code is initialized to 0.
  201. *
  202. * @param reason a description of the exception
  203. * @param updateCounts an array of <code>int</code>, with each element
  204. *indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  205. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  206. * the batch for JDBC drivers that continue processing
  207. * after a command failure; an update count or
  208. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  209. * prior to the failure for JDBC drivers that stop processing after a command
  210. * failure
  211. * @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method);
  212. * may be null indicating
  213. * the cause is non-existent or unknown.
  214. * @since 1.6
  215. */
  216. public BatchUpdateException(String reason, int []updateCounts, Throwable cause) {
  217. super(reason,cause);
  218. this.updateCounts = updateCounts;
  219. }
  220. /**
  221. * Constructs a <code>BatchUpdateException</code> object initialized with
  222. * a given <code>reason</code>, <code>SQLState</code>,<code>cause</code>, and
  223. * <code>updateCounts</code>. The vendor code is initialized to 0.
  224. *
  225. * @param reason a description of the exception
  226. * @param SQLState an XOPEN or SQL:2003 code identifying the exception
  227. * @param updateCounts an array of <code>int</code>, with each element
  228. * indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  229. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  230. * the batch for JDBC drivers that continue processing
  231. * after a command failure; an update count or
  232. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  233. * prior to the failure for JDBC drivers that stop processing after a command
  234. * failure
  235. * @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method);
  236. * may be null indicating
  237. * the cause is non-existent or unknown.
  238. * @since 1.6
  239. */
  240. public BatchUpdateException(String reason, String SQLState,
  241. int []updateCounts, Throwable cause) {
  242. super(reason,SQLState,cause);
  243. this.updateCounts = updateCounts;
  244. }
  245. /**
  246. * Constructs a <code>BatchUpdateException</code> object initialized with
  247. * a given <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
  248. * <code>cause</code> and <code>updateCounts</code>.
  249. *
  250. * @param reason a description of the error
  251. * @param SQLState an XOPEN or SQL:2003 code identifying the exception
  252. * @param vendorCode an exception code used by a particular
  253. * database vendor
  254. * @param updateCounts an array of <code>int</code>, with each element
  255. *indicating the update count, <code>Statement.SUCCESS_NO_INFO</code> or
  256. * <code>Statement.EXECUTE_FAILED</code> for each SQL command in
  257. * the batch for JDBC drivers that continue processing
  258. * after a command failure; an update count or
  259. * <code>Statement.SUCCESS_NO_INFO</code> for each SQL command in the batch
  260. * prior to the failure for JDBC drivers that stop processing after a command
  261. * failure
  262. * @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method);
  263. * may be null indicating
  264. * the cause is non-existent or unknown.
  265. * @since 1.6
  266. */
  267. public BatchUpdateException(String reason, String SQLState, int vendorCode,
  268. int []updateCounts,Throwable cause) {
  269. super(reason,SQLState,vendorCode,cause);
  270. this.updateCounts = updateCounts;
  271. }
  272. /**
  273. * Retrieves the update count for each update statement in the batch
  274. * update that executed successfully before this exception occurred.
  275. * A driver that implements batch updates may or may not continue to
  276. * process the remaining commands in a batch when one of the commands
  277. * fails to execute properly. If the driver continues processing commands,
  278. * the array returned by this method will have as many elements as
  279. * there are commands in the batch; otherwise, it will contain an
  280. * update count for each command that executed successfully before
  281. * the <code>BatchUpdateException</code> was thrown.
  282. *<P>
  283. * The possible return values for this method were modified for
  284. * the Java 2 SDK, Standard Edition, version 1.3. This was done to
  285. * accommodate the new option of continuing to process commands
  286. * in a batch update after a <code>BatchUpdateException</code> object
  287. * has been thrown.
  288. *
  289. * @return an array of <code>int</code> containing the update counts
  290. * for the updates that were executed successfully before this error
  291. * occurred. Or, if the driver continues to process commands after an
  292. * error, one of the following for every command in the batch:
  293. * <OL>
  294. * <LI>an update count
  295. * <LI><code>Statement.SUCCESS_NO_INFO</code> to indicate that the command
  296. * executed successfully but the number of rows affected is unknown
  297. * <LI><code>Statement.EXECUTE_FAILED</code> to indicate that the command
  298. * failed to execute successfully
  299. * </OL>
  300. * @since 1.3
  301. */
  302. public int[] getUpdateCounts() {
  303. return updateCounts;
  304. }
  305. /**
  306. * The array that describes the outcome of a batch execution.
  307. * @serial
  308. * @since 1.2
  309. */
  310. private int[] updateCounts;
  311. private static final long serialVersionUID = 5977529877145521757L;
  312. }