jdk/src/java.sql/share/classes/java/sql/DataTruncation.java
author lana
Thu, 13 Jul 2017 17:32:50 +0000
changeset 46004 df6671f0f8f3
parent 25859 3317bb8137f4
child 44256 12050b22e372
permissions -rw-r--r--
Added tag jdk-9+178 for changeset df8265c4f940
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>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class DataTruncation extends SQLWarning {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Creates a <code>DataTruncation</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * with the SQLState initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * to 01004 when <code>read</code> is set to <code>true</code> and 22001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * when <code>read</code> is set to <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * the reason set to "Data truncation", the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * vendor code set to 0, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * the other fields set to the given values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * The <code>cause</code> is not initialized, and may subsequently be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * initialized by a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * {@link Throwable#initCause(java.lang.Throwable)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param index The index of the parameter or column value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @param parameter true if a parameter value was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param read true if a read was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param dataSize the original size of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param transferSize the size after truncation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public DataTruncation(int index, boolean parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                          boolean read, int dataSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                          int transferSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super("Data truncation", read == true?"01004":"22001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.parameter = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.read = read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.dataSize = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.transferSize = transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Creates a <code>DataTruncation</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * with the SQLState initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * to 01004 when <code>read</code> is set to <code>true</code> and 22001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * when <code>read</code> is set to <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * the reason set to "Data truncation", the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * vendor code set to 0, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * the other fields set to the given values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param index The index of the parameter or column value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param parameter true if a parameter value was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param read true if a read was truncated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param dataSize the original size of the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param transferSize the size after truncation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param cause the underlying reason for this <code>DataTruncation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * (which is saved for later retrieval by the <code>getCause()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * may be null indicating the cause is non-existent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public DataTruncation(int index, boolean parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                          boolean read, int dataSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                          int transferSize, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        super("Data truncation", read == true?"01004":"22001",cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.parameter = parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.read = read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.dataSize = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.transferSize = transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Retrieves the index of the column or parameter that was truncated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <P>This may be -1 if the column or parameter index is unknown, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * which case the <code>parameter</code> and <code>read</code> fields should be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   108
     * @return the index of the truncated parameter or column value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public int getIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Indicates whether the value truncated was a parameter value or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * a column value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return <code>true</code> if the value truncated was a parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         *         <code>false</code> if it was a column value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public boolean getParameter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Indicates whether or not the value was truncated on a read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return <code>true</code> if the value was truncated when read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         *         the database; <code>false</code> if the data was truncated on a write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public boolean getRead() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Gets the number of bytes of data that should have been transferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * This number may be approximate if data conversions were being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * performed.  The value may be <code>-1</code> if the size is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return the number of bytes of data that should have been transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public int getDataSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Gets the number of bytes of data actually transferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * The value may be <code>-1</code> if the size is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return the number of bytes of data actually transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public int getTransferSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private boolean parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private boolean read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private int dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private int transferSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private static final long serialVersionUID = 6464298989504059473L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}