home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / sql / DataTruncation.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.7 KB  |  136 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)DataTruncation.java    1.16 98/09/29
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.sql;
  16.  
  17. /**
  18.  * An exception that reports a
  19.  * DataTruncation warning (on reads) or throws a DataTruncation exception
  20.  * (on writes) when JDBC unexpectedly truncates a data value.
  21.  *
  22.  * <P>The SQLstate for a <code>DataTruncation</code> is <code>01004</code>.
  23.  */
  24.  
  25. public class DataTruncation extends SQLWarning {
  26.  
  27.     /**
  28.      * Creates a <code>DataTruncation</code> object 
  29.      * with the SQLState initialized
  30.      * to 01004, the reason set to "Data truncation", the
  31.      * vendorCode set to the SQLException default, and
  32.      * the other fields set to the given values.
  33.      *
  34.      * @param index The index of the parameter or column value
  35.      * @param parameter true if a parameter value was truncated
  36.      * @param read true if a read was truncated
  37.      * @param dataSize the original size of the data
  38.      * @param transferSize the size after truncation 
  39.      */
  40.     public DataTruncation(int index, boolean parameter, 
  41.               boolean read, int dataSize, 
  42.               int transferSize) {
  43.     super("Data truncation", "01004");
  44.     this.index = index;
  45.     this.parameter = parameter;
  46.     this.read = read;
  47.     this.dataSize = dataSize;
  48.     this.transferSize = transferSize;
  49.     DriverManager.println("    DataTruncation: index(" + index + 
  50.                   ") parameter(" + parameter +
  51.                   ") read(" + read +
  52.                   ") data size(" + dataSize +
  53.                   ") transfer size(" + transferSize + ")");
  54.     }
  55.  
  56.     /**
  57.      * Retrieves the index of the column or parameter that was truncated.
  58.      *
  59.      * <P>This may be -1 if the column or parameter index is unknown, in 
  60.      * which case the <code>parameter</code> and <code>read</code> fields should be ignored.
  61.      *
  62.      * @return the index of the truncated paramter or column value
  63.      */
  64.     public int getIndex() {
  65.     return index;
  66.     }
  67.  
  68.     /**
  69.      * Indicates whether the value truncated was a parameter value or
  70.      * a column value.
  71.      *
  72.      * @return <code>true</code> if the value truncated was a parameter;
  73.      *         <code>false</code> if it was a column value
  74.      */
  75.     public boolean getParameter() {
  76.     return parameter;
  77.     }
  78.  
  79.     /**
  80.      * Indicates whether or not the value was truncated on a read.
  81.      *
  82.      * @return <code>true</code> if the value was truncated when read from
  83.      *         the database; <code>false</code> if the data was truncated on a write
  84.      */
  85.     public boolean getRead() {
  86.     return read;
  87.     }
  88.  
  89.     /**
  90.      * Gets the number of bytes of data that should have been transferred.
  91.      * This number may be approximate if data conversions were being
  92.      * performed.  The value may be <code>-1</code> if the size is unknown.
  93.      *
  94.      * @return the number of bytes of data that should have been transferred
  95.      */
  96.     public int getDataSize() {
  97.     return dataSize;
  98.     }
  99.  
  100.     /**
  101.      * Gets the number of bytes of data actually transferred.
  102.      * The value may be <code>-1</code> if the size is unknown.
  103.      *
  104.      * @return the number of bytes of data actually transferred
  105.      */
  106.     public int getTransferSize() {
  107.     return transferSize;
  108.     }
  109.  
  110.     /**
  111.        * @serial
  112.     */
  113.     private int index;
  114.  
  115.     /**
  116.     * @serial
  117.     */
  118.     private boolean parameter;
  119.  
  120.     /**
  121.     * @serial
  122.     */
  123.     private boolean read;    
  124.  
  125.     /**
  126.     * @serial
  127.     */
  128.     private int dataSize;
  129.  
  130.     /**
  131.     * @serial
  132.     */
  133.     private int transferSize;
  134.  
  135. }
  136.