src/java.sql/share/classes/java/sql/DataTruncation.java
author herrick
Wed, 20 Nov 2019 10:17:37 -0500
branchJDK-8200758-branch
changeset 59160 e90068e7afa1
parent 47216 71c04702a3d5
permissions -rw-r--r--
JDK-8234402: revert change that stopped providing JPackageToolProvider Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * An exception  thrown as a <code>DataTruncation</code> exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * (on writes) or reported as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <code>DataTruncation</code> warning (on reads)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  when a data values is unexpectedly truncated for reasons other than its having
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
    33
 *  exceeded <code>MaxFieldSize</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <P>The SQLstate for a <code>DataTruncation</code> during read is <code>01004</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <P>The SQLstate for a <code>DataTruncation</code> during write is <code>22001</code>.
44256
12050b22e372 8176721: @since value errors java.sql module
mli
parents: 25859
diff changeset
    37
 *
12050b22e372 8176721: @since value errors java.sql module
mli
parents: 25859
diff changeset
    38
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class DataTruncation extends SQLWarning {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * Creates a <code>DataTruncation</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * with the SQLState initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * to 01004 when <code>read</code> is set to <code>true</code> and 22001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * when <code>read</code> is set to <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * the reason set to "Data truncation", the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * vendor code set to 0, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * the other fields set to the given values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * {@link Throwable#initCause(java.lang.Throwable)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param index The index of the parameter or column value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param parameter true if a parameter value was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param read true if a read was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param dataSize the original size of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @param transferSize the size after truncation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public DataTruncation(int index, boolean parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                          boolean read, int dataSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                          int transferSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super("Data truncation", read == true?"01004":"22001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.parameter = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.read = read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.dataSize = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.transferSize = transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Creates a <code>DataTruncation</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * with the SQLState initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * to 01004 when <code>read</code> is set to <code>true</code> and 22001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * when <code>read</code> is set to <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * the reason set to "Data truncation", the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * vendor code set to 0, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * the other fields set to the given values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param index The index of the parameter or column value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param parameter true if a parameter value was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param read true if a read was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param dataSize the original size of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param transferSize the size after truncation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param cause the underlying reason for this <code>DataTruncation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public DataTruncation(int index, boolean parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                          boolean read, int dataSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                          int transferSize, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super("Data truncation", read == true?"01004":"22001",cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.parameter = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.read = read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.dataSize = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.transferSize = transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Retrieves the index of the column or parameter that was truncated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <P>This may be -1 if the column or parameter index is unknown, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * which case the <code>parameter</code> and <code>read</code> fields should be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   110
     * @return the index of the truncated parameter or column value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public int getIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Indicates whether the value truncated was a parameter value or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * a column value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return <code>true</code> if the value truncated was a parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         *         <code>false</code> if it was a column value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public boolean getParameter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Indicates whether or not the value was truncated on a read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @return <code>true</code> if the value was truncated when read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         *         the database; <code>false</code> if the data was truncated on a write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public boolean getRead() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Gets the number of bytes of data that should have been transferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * This number may be approximate if data conversions were being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * performed.  The value may be <code>-1</code> if the size is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return the number of bytes of data that should have been transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public int getDataSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Gets the number of bytes of data actually transferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * The value may be <code>-1</code> if the size is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the number of bytes of data actually transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public int getTransferSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private boolean parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private boolean read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private int dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private int transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static final long serialVersionUID = 6464298989504059473L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
}