Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/sql/DataTruncation.java
38829 views
/*1* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627/**28* An exception thrown as a <code>DataTruncation</code> exception29* (on writes) or reported as a30* <code>DataTruncation</code> warning (on reads)31* when a data values is unexpectedly truncated for reasons other than its having32* exceeded <code>MaxFieldSize</code>.33*34* <P>The SQLstate for a <code>DataTruncation</code> during read is <code>01004</code>.35* <P>The SQLstate for a <code>DataTruncation</code> during write is <code>22001</code>.36*/3738public class DataTruncation extends SQLWarning {3940/**41* Creates a <code>DataTruncation</code> object42* with the SQLState initialized43* to 01004 when <code>read</code> is set to <code>true</code> and 2200144* when <code>read</code> is set to <code>false</code>,45* the reason set to "Data truncation", the46* vendor code set to 0, and47* the other fields set to the given values.48* The <code>cause</code> is not initialized, and may subsequently be49* initialized by a call to the50* {@link Throwable#initCause(java.lang.Throwable)} method.51* <p>52*53* @param index The index of the parameter or column value54* @param parameter true if a parameter value was truncated55* @param read true if a read was truncated56* @param dataSize the original size of the data57* @param transferSize the size after truncation58*/59public DataTruncation(int index, boolean parameter,60boolean read, int dataSize,61int transferSize) {62super("Data truncation", read == true?"01004":"22001");63this.index = index;64this.parameter = parameter;65this.read = read;66this.dataSize = dataSize;67this.transferSize = transferSize;6869}7071/**72* Creates a <code>DataTruncation</code> object73* with the SQLState initialized74* to 01004 when <code>read</code> is set to <code>true</code> and 2200175* when <code>read</code> is set to <code>false</code>,76* the reason set to "Data truncation", the77* vendor code set to 0, and78* the other fields set to the given values.79* <p>80*81* @param index The index of the parameter or column value82* @param parameter true if a parameter value was truncated83* @param read true if a read was truncated84* @param dataSize the original size of the data85* @param transferSize the size after truncation86* @param cause the underlying reason for this <code>DataTruncation</code>87* (which is saved for later retrieval by the <code>getCause()</code> method);88* may be null indicating the cause is non-existent or unknown.89*90* @since 1.691*/92public DataTruncation(int index, boolean parameter,93boolean read, int dataSize,94int transferSize, Throwable cause) {95super("Data truncation", read == true?"01004":"22001",cause);96this.index = index;97this.parameter = parameter;98this.read = read;99this.dataSize = dataSize;100this.transferSize = transferSize;101}102103/**104* Retrieves the index of the column or parameter that was truncated.105*106* <P>This may be -1 if the column or parameter index is unknown, in107* which case the <code>parameter</code> and <code>read</code> fields should be ignored.108*109* @return the index of the truncated parameter or column value110*/111public int getIndex() {112return index;113}114115/**116* Indicates whether the value truncated was a parameter value or117* a column value.118*119* @return <code>true</code> if the value truncated was a parameter;120* <code>false</code> if it was a column value121*/122public boolean getParameter() {123return parameter;124}125126/**127* Indicates whether or not the value was truncated on a read.128*129* @return <code>true</code> if the value was truncated when read from130* the database; <code>false</code> if the data was truncated on a write131*/132public boolean getRead() {133return read;134}135136/**137* Gets the number of bytes of data that should have been transferred.138* This number may be approximate if data conversions were being139* performed. The value may be <code>-1</code> if the size is unknown.140*141* @return the number of bytes of data that should have been transferred142*/143public int getDataSize() {144return dataSize;145}146147/**148* Gets the number of bytes of data actually transferred.149* The value may be <code>-1</code> if the size is unknown.150*151* @return the number of bytes of data actually transferred152*/153public int getTransferSize() {154return transferSize;155}156157/**158* @serial159*/160private int index;161162/**163* @serial164*/165private boolean parameter;166167/**168* @serial169*/170private boolean read;171172/**173* @serial174*/175private int dataSize;176177/**178* @serial179*/180private int transferSize;181182/**183* @serial184*/185private static final long serialVersionUID = 6464298989504059473L;186187}188189190