FileDocCategorySizeDatePackage
DataTruncation.javaAPI DocAndroid 1.5 API4449Wed May 06 22:41:06 BST 2009java.sql

DataTruncation.java

/* 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package java.sql;

import java.io.Serializable;

/**
 * An exception which is thrown when a JDBC driver unexpectedly truncates a data
 * value either when reading (resulting in warning), or when writing data
 * (resulting in an error). The {@code SQLState} error code for truncated data
 * is {@code 01004}.
 *  
 * @since Android 1.0
 */
public class DataTruncation extends SQLWarning implements Serializable {

    private static final long serialVersionUID = 6464298989504059473L;

    private int index = 0;

    private boolean parameter = false;

    private boolean read = false;

    private int dataSize = 0;

    private int transferSize = 0;

    private static final String THE_REASON = "Data truncation"; //$NON-NLS-1$

    private static final String THE_SQLSTATE = "01004"; //$NON-NLS-1$

    private static final int THE_ERROR_CODE = 0;

    /**
     * Creates the {@code DataTruncation} object. The reason is set to {@code
     * "Data truncation"}, the {@code ErrorCode} is set to the {@code
     * SQLException} default value, and the other fields are set to the values
     * supplied as arguments.
     * 
     * @param index
     *            the Index value of the column value or parameter that was
     *            truncated.
     * @param parameter
     *            {@code true} if it was a parameter value that was truncated,
     *            {@code false} otherwise.
     * @param read
     *            {@code true} if the truncation occurred on a read operation,
     *            {@code false} otherwise.
     * @param dataSize
     *            the original size of the truncated data.
     * @param transferSize
     *            the size of the data after truncation.
     * @since Android 1.0
     */
    public DataTruncation(int index, boolean parameter, boolean read,
            int dataSize, int transferSize) {
        super(THE_REASON, THE_SQLSTATE, THE_ERROR_CODE);
        this.index = index;
        this.parameter = parameter;
        this.read = read;
        this.dataSize = dataSize;
        this.transferSize = transferSize;
    }

    /**
     * Gets the number of bytes of data that should have been read/written.
     * 
     * @return the number of bytes that should have been read or written. The
     *         value is set to {@code -1} if the size is unknown.
     * @since Android 1.0
     */
    public int getDataSize() {
        return dataSize;
    }

    /**
     * Gets the index of the column or of the parameter that was truncated.
     * 
     * @return the index number of the column or of the parameter.
     * @since Android 1.0
     */
    public int getIndex() {
        return index;
    }

    /**
     * Gets whether the value truncated was a parameter value or a column value.
     * 
     * @return {@code true} if the value truncated was a parameter value,
     *         {@code false} if it was a column value.
     * @since Android 1.0
     */
    public boolean getParameter() {
        return parameter;
    }

    /**
     * Gets whether the value was truncated on a read operation or a write
     * operation
     * 
     * @return {@code true} if the value was truncated on a read operation,
     *         {@code false} otherwise.
     * @since Android 1.0
     */
    public boolean getRead() {
        return read;
    }

    /**
     * Gets the number of bytes of data that was actually read or written.
     * 
     * @return the number of bytes actually read/written. The value may be set
     *         to {@code -1} if the size is unknown.
     * @since Android 1.0
     */
    public int getTransferSize() {
        return transferSize;
    }
}