src/jdk.incubator.adba/share/classes/jdk/incubator/sql2/SqlException.java
author lancea
Sat, 20 Oct 2018 08:17:38 -0400
branchJDK-8188051-branch
changeset 56997 c9cbac2979fb
parent 56797 fb523d4d9185
permissions -rwxr-xr-x
JDK-8188051-branch October 20 ABDA updates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     1
/*
56475
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
     2
 * Copyright (c)  2017, 2018, Oracle and/or its affiliates. All rights reserved.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     4
 *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    10
 *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    15
 * accompanied this code).
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    16
 *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    20
 *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    23
 * questions.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    24
 */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    25
package jdk.incubator.sql2;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    26
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    27
/**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    28
 * An exception that provides information on a database access error or other
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    29
 * errors.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    30
 *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    31
 * <P>
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
    32
 * Each {@code SqlException} provides several kinds of information:
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    33
 * <UL>
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    34
 * <LI> a string describing the error. This is used as the Java Exception
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
    35
 * message, available via the method {@link getMessage}.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    36
 * <LI> a "SQLstate" string, which follows either the XOPEN SQLstate conventions
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    37
 * or the SQL:2003 conventions. The values of the SQLState string are described
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
    38
 * in the appropriate spec.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    39
 * <LI> an integer error code that is specific to each vendor. Normally this
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    40
 * will be the actual error code returned by the underlying database.
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
    41
 * <LI> the causal relationship, if any for this {@code SqlException}.
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
    42
 * <LI> the SQL string that was executing when the error occurred. May be {@code null}.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    43
 * <LI> the position in the SQL string where the error was detected.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    44
 * </UL>
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    45
 */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    46
public class SqlException extends RuntimeException {
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    47
  
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    48
  private static final long serialVersionUID = 1L;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    49
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    50
  // Fields
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    51
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    52
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    53
   */
56475
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    54
  private final String sqlState;
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    55
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    56
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    57
   */
56475
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    58
  private final int vendorCode;
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    59
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    60
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    61
   * The SQL string that was sent to the database.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    62
   */
56475
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    63
  private final String sqlString;
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    64
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    65
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    66
   * The index of the first character in SQL where an error is detected. Zero
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    67
   * based.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    68
   */
56475
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    69
  private final int position;
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    70
  
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    71
  // Constructors
56797
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    72
  
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    73
  public SqlException(Throwable ex) {
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    74
    super(ex);
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    75
    this.sqlState = null;
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    76
    this.vendorCode = -1;
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    77
    this.sqlString = null;
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    78
    this.position = -1;
fb523d4d9185 JDK-8188051-branch updates
lancea
parents: 56475
diff changeset
    79
  }
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    80
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    81
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    82
   *
56475
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    83
   * @param message
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    84
   * @param cause
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    85
   * @param sqlState
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    86
   * @param vendorCode
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    87
   * @param sql
e700edfac7ad JDK-8188051-branch: Updates to sync with AOJ
lancea
parents: 56397
diff changeset
    88
   * @param position
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    89
   */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    90
  public SqlException(String message, Throwable cause, String sqlState, int vendorCode, String sql, int position) {
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    91
    super(message, cause);
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    92
    this.sqlState = sqlState;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    93
    this.vendorCode = vendorCode;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    94
    this.sqlString = sql;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    95
    this.position = position;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    96
  }
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    97
  
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    98
  // Methods
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
    99
  
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   100
  /**
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
   101
   * Retrieves the SqlState for this {@code SqlException} object.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   102
   *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   103
   * @return the SQLState value
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   104
   */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   105
  public String getSqlState() {
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   106
    return (sqlState);
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   107
  }
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   108
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   109
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   110
   * Retrieves the vendor-specific exception code for this
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
   111
   * {@code SqlException} object.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   112
   *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   113
   * @return the vendor's error code
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   114
   */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   115
  public int getVendorCode() {
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   116
    return (vendorCode);
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   117
  }
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   118
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   119
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   120
   * Get the position.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   121
   *
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   122
   * @return the index of the first character in sql where an error is detected.
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
   123
   * Zero based. {@code -1} if the position is not defined or unknown.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   124
   */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   125
  public int getPosition() {
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   126
    return position;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   127
  }
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   128
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   129
  /**
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   130
   * Get the sql.
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   131
   *
56997
c9cbac2979fb JDK-8188051-branch October 20 ABDA updates
lancea
parents: 56797
diff changeset
   132
   * @return the SQL string sent to the database. May be {@code null}.
56380
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   133
   */
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   134
  public String getSqlString() {
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   135
    return sqlString;
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   136
  }
f06946e00a26 JDK-8188051-branch: add jdk.incubator.adba
lancea
parents:
diff changeset
   137
}