0N/A/*
2362N/A * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.sql;
0N/A
0N/A/**
0N/A * An exception thrown as a <code>DataTruncation</code> exception
0N/A * (on writes) or reported as a
0N/A * <code>DataTruncation</code> warning (on reads)
0N/A * when a data values is unexpectedly truncated for reasons other than its having
0N/A * execeeded <code>MaxFieldSize</code>.
0N/A *
0N/A * <P>The SQLstate for a <code>DataTruncation</code> during read is <code>01004</code>.
0N/A * <P>The SQLstate for a <code>DataTruncation</code> during write is <code>22001</code>.
0N/A */
0N/A
0N/Apublic class DataTruncation extends SQLWarning {
0N/A
0N/A /**
0N/A * Creates a <code>DataTruncation</code> object
0N/A * with the SQLState initialized
0N/A * to 01004 when <code>read</code> is set to <code>true</code> and 22001
0N/A * when <code>read</code> is set to <code>false</code>,
0N/A * the reason set to "Data truncation", the
0N/A * vendor code set to 0, and
0N/A * the other fields set to the given values.
0N/A * The <code>cause</code> is not initialized, and may subsequently be
0N/A * initialized by a call to the
0N/A * {@link Throwable#initCause(java.lang.Throwable)} method.
0N/A * <p>
0N/A *
0N/A * @param index The index of the parameter or column value
0N/A * @param parameter true if a parameter value was truncated
0N/A * @param read true if a read was truncated
0N/A * @param dataSize the original size of the data
0N/A * @param transferSize the size after truncation
0N/A */
0N/A public DataTruncation(int index, boolean parameter,
0N/A boolean read, int dataSize,
0N/A int transferSize) {
0N/A super("Data truncation", read == true?"01004":"22001");
0N/A this.index = index;
0N/A this.parameter = parameter;
0N/A this.read = read;
0N/A this.dataSize = dataSize;
0N/A this.transferSize = transferSize;
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>DataTruncation</code> object
0N/A * with the SQLState initialized
0N/A * to 01004 when <code>read</code> is set to <code>true</code> and 22001
0N/A * when <code>read</code> is set to <code>false</code>,
0N/A * the reason set to "Data truncation", the
0N/A * vendor code set to 0, and
0N/A * the other fields set to the given values.
0N/A * <p>
0N/A *
0N/A * @param index The index of the parameter or column value
0N/A * @param parameter true if a parameter value was truncated
0N/A * @param read true if a read was truncated
0N/A * @param dataSize the original size of the data
0N/A * @param transferSize the size after truncation
0N/A * @param cause the underlying reason for this <code>DataTruncation</code>
0N/A * (which is saved for later retrieval by the <code>getCause()</code> method);
0N/A * may be null indicating the cause is non-existent or unknown.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public DataTruncation(int index, boolean parameter,
0N/A boolean read, int dataSize,
0N/A int transferSize, Throwable cause) {
0N/A super("Data truncation", read == true?"01004":"22001",cause);
0N/A this.index = index;
0N/A this.parameter = parameter;
0N/A this.read = read;
0N/A this.dataSize = dataSize;
0N/A this.transferSize = transferSize;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the index of the column or parameter that was truncated.
0N/A *
0N/A * <P>This may be -1 if the column or parameter index is unknown, in
0N/A * which case the <code>parameter</code> and <code>read</code> fields should be ignored.
0N/A *
0N/A * @return the index of the truncated paramter or column value
0N/A */
0N/A public int getIndex() {
0N/A return index;
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether the value truncated was a parameter value or
0N/A * a column value.
0N/A *
0N/A * @return <code>true</code> if the value truncated was a parameter;
0N/A * <code>false</code> if it was a column value
0N/A */
0N/A public boolean getParameter() {
0N/A return parameter;
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether or not the value was truncated on a read.
0N/A *
0N/A * @return <code>true</code> if the value was truncated when read from
0N/A * the database; <code>false</code> if the data was truncated on a write
0N/A */
0N/A public boolean getRead() {
0N/A return read;
0N/A }
0N/A
0N/A /**
0N/A * Gets the number of bytes of data that should have been transferred.
0N/A * This number may be approximate if data conversions were being
0N/A * performed. The value may be <code>-1</code> if the size is unknown.
0N/A *
0N/A * @return the number of bytes of data that should have been transferred
0N/A */
0N/A public int getDataSize() {
0N/A return dataSize;
0N/A }
0N/A
0N/A /**
0N/A * Gets the number of bytes of data actually transferred.
0N/A * The value may be <code>-1</code> if the size is unknown.
0N/A *
0N/A * @return the number of bytes of data actually transferred
0N/A */
0N/A public int getTransferSize() {
0N/A return transferSize;
0N/A }
0N/A
0N/A /**
0N/A * @serial
0N/A */
0N/A private int index;
0N/A
0N/A /**
0N/A * @serial
0N/A */
0N/A private boolean parameter;
0N/A
0N/A /**
0N/A * @serial
0N/A */
0N/A private boolean read;
0N/A
0N/A /**
0N/A * @serial
0N/A */
0N/A private int dataSize;
0N/A
0N/A /**
0N/A * @serial
0N/A */
0N/A private int transferSize;
0N/A
0N/A /**
0N/A * @serial
0N/A */
0N/A private static final long serialVersionUID = 6464298989504059473L;
0N/A
0N/A}