src/share/classes/java/sql/BatchUpdateException.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,10 +23,12 @@
  * questions.
  */
 
 package java.sql;
 
+import java.util.Arrays;
+
 /**
  * The subclass of {@link SQLException} thrown when an error
  * occurs during a batch update operation.  In addition to the
  * information provided by {@link SQLException}, a
  * <code>BatchUpdateException</code> provides the update

@@ -75,12 +77,11 @@
    * failure
    * @since 1.2
    */
   public BatchUpdateException( String reason, String SQLState, int vendorCode,
                                int[] updateCounts ) {
-    super(reason, SQLState, vendorCode);
-    this.updateCounts = updateCounts;
+      this(reason, SQLState, vendorCode, updateCounts, null);
   }
 
   /**
    * Constructs a <code>BatchUpdateException</code> object initialized with a given
    * <code>reason</code>, <code>SQLState</code> and

@@ -103,12 +104,11 @@
    * failure
    * @since 1.2
    */
   public BatchUpdateException(String reason, String SQLState,
                               int[] updateCounts) {
-    super(reason, SQLState);
-    this.updateCounts = updateCounts;
+      this(reason, SQLState, 0, updateCounts, null);
   }
 
   /**
    * Constructs a <code>BatchUpdateException</code> object initialized with a given
    * <code>reason</code> and <code>updateCounts</code>.

@@ -130,12 +130,11 @@
    * prior to the failure for JDBC drivers that stop processing after a command
    * failure
    * @since 1.2
    */
   public  BatchUpdateException(String reason, int[] updateCounts) {
-    super(reason);
-    this.updateCounts = updateCounts;
+      this(reason, null, 0, updateCounts, null);
   }
 
   /**
    * Constructs a <code>BatchUpdateException</code> object initialized with a given
    * <code>updateCounts</code>.

@@ -154,12 +153,11 @@
    * prior to the failure for JDBC drivers that stop processing after a command
    * failure
    * @since 1.2
    */
   public BatchUpdateException(int[] updateCounts) {
-    super();
-    this.updateCounts = updateCounts;
+      this(null, null, 0, updateCounts, null);
   }
 
   /**
    * Constructs a <code>BatchUpdateException</code> object.
    * The <code>reason</code>, <code>SQLState</code> and <code>updateCounts</code>

@@ -170,12 +168,11 @@
    * <p>
    *
    * @since 1.2
    */
   public BatchUpdateException() {
-    super();
-    this.updateCounts = null;
+        this(null, null, 0, null, null);
   }
 
     /**
      * Constructs a <code>BatchUpdateException</code> object initialized with
      *  a given <code>cause</code>.

@@ -189,12 +186,11 @@
      * (which is saved for later retrieval by the <code>getCause()</code> method);
      * may be null indicating the cause is non-existent or unknown.
      * @since 1.6
      */
     public BatchUpdateException(Throwable cause) {
-        super(cause);
-        this.updateCounts = null;
+        this(null, null, 0, null, cause);
     }
 
     /**
      * Constructs a <code>BatchUpdateException</code> object initialized with a
      * given <code>cause</code> and <code>updateCounts</code>.

@@ -216,12 +212,11 @@
      * (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
      * the cause is non-existent or unknown.
      * @since 1.6
      */
     public BatchUpdateException(int []updateCounts , Throwable cause) {
-        super(cause);
-        this.updateCounts = updateCounts;
+        this(null, null, 0, updateCounts, cause);
     }
 
     /**
      * Constructs a <code>BatchUpdateException</code> object initialized with
      * a given <code>reason</code>, <code>cause</code>

@@ -241,12 +236,11 @@
      * may be null indicating
      * the cause is non-existent or unknown.
      * @since 1.6
      */
     public BatchUpdateException(String reason, int []updateCounts, Throwable cause) {
-        super(reason,cause);
-        this.updateCounts = updateCounts;
+        this(reason, null, 0, updateCounts, cause);
     }
 
     /**
      * Constructs a <code>BatchUpdateException</code> object initialized with
      * a given <code>reason</code>, <code>SQLState</code>,<code>cause</code>, and

@@ -267,12 +261,11 @@
      * the cause is non-existent or unknown.
      * @since 1.6
      */
     public BatchUpdateException(String reason, String SQLState,
                                 int []updateCounts, Throwable cause) {
-        super(reason,SQLState,cause);
-        this.updateCounts = updateCounts;
+        this(reason, SQLState, 0, updateCounts, cause);
     }
 
     /**
      * Constructs a <code>BatchUpdateException</code> object initialized with
      * a given <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>

@@ -295,12 +288,14 @@
      * the cause is non-existent or unknown.
      * @since 1.6
      */
     public BatchUpdateException(String reason, String SQLState, int vendorCode,
                                 int []updateCounts,Throwable cause) {
-        super(reason,SQLState,vendorCode,cause);
-        this.updateCounts = updateCounts;
+        super(reason, SQLState, vendorCode, cause);
+        if(updateCounts != null) {
+            this.updateCounts = Arrays.copyOf(updateCounts, updateCounts.length);
+        }
     }
 
   /**
    * Retrieves the update count for each update statement in the batch
    * update that executed successfully before this exception occurred.

@@ -330,11 +325,11 @@
    *     failed to execute successfully
    * </OL>
    * @since 1.3
    */
   public int[] getUpdateCounts() {
-    return updateCounts;
+    return updateCounts != null ? Arrays.copyOf(updateCounts, updateCounts.length) : null;
   }
 
   /**
    * The array that describes the outcome of a batch execution.
    * @serial