home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / DataTruncation.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  121 lines

  1. /*
  2.  * @(#)DataTruncation.java    1.5 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.sql;
  24.  
  25. /**
  26.  * <P>When JDBC unexpectedly truncates a data value, it reports a
  27.  * DataTruncation warning (on reads) or throws a DataTruncation exception
  28.  * (on writes).
  29.  *
  30.  * <P>The SQLstate for a DataTruncation is "01004".
  31.  */
  32.  
  33. public class DataTruncation extends SQLWarning {
  34.  
  35.     /**
  36.      * <P>Create a DataTruncation object. The SQLState is initialized
  37.      * to 01004, the reason is set to "Data truncation" and the
  38.      * vendorCode is set to the SQLException default.
  39.      *
  40.      * @param index The index of the parameter or column value
  41.      * @param parameter true if a parameter value was truncated
  42.      * @param read true if a read was truncated
  43.      * @param dataSize the original size of the data
  44.      * @param transferSize the size after truncation 
  45.      */
  46.     public DataTruncation(int index, boolean parameter, 
  47.               boolean read, int dataSize, 
  48.               int transferSize) {
  49.     super("Data truncation", "01004");
  50.     this.index = index;
  51.     this.parameter = parameter;
  52.     this.read = read;
  53.     this.dataSize = dataSize;
  54.     this.transferSize = transferSize;
  55.     DriverManager.println("    DataTruncation: index(" + index + 
  56.                   ") parameter(" + parameter +
  57.                   ") read(" + read +
  58.                   ") data size(" + dataSize +
  59.                   ") transfer size(" + transferSize + ")");
  60.     }
  61.  
  62.     /**
  63.      * Get the index of the column or parameter that was truncated.
  64.      *
  65.      * <P>This may be -1 if the column or parameter index is unknown, in 
  66.      * which case the "parameter" and "read" fields should be ignored.
  67.      *
  68.      * @return the index of the truncated paramter or column value.
  69.      */
  70.     public int getIndex() {
  71.     return index;
  72.     }
  73.  
  74.     /**
  75.      * Is this a truncated parameter value?
  76.      *
  77.      * @return True if the value was a parameter; false if it was a column value.
  78.      */
  79.     public boolean getParameter() {
  80.     return parameter;
  81.     }
  82.  
  83.     /**
  84.      * Was this a read truncation?
  85.      *
  86.      * @return True if the value was truncated when read from the database; false
  87.      * if the data was truncated on a write.
  88.      */
  89.     public boolean getRead() {
  90.     return read;
  91.     }
  92.  
  93.     /**
  94.      * Get the number of bytes of data that should have been transferred.
  95.      * This number may be approximate if data conversions were being
  96.      * performed.  The value may be "-1" if the size is unknown.
  97.      *
  98.      * @return the number of bytes of data that should have been transferred
  99.      */
  100.     public int getDataSize() {
  101.     return dataSize;
  102.     }
  103.  
  104.     /**
  105.      * Get the number of bytes of data actually transferred.
  106.      * The value may be "-1" if the size is unknown.
  107.      *
  108.      * @return the number of bytes of data actually transferred
  109.      */
  110.     public int getTransferSize() {
  111.     return transferSize;
  112.     }
  113.  
  114.     private int index;
  115.     private boolean parameter;
  116.     private boolean read;    
  117.     private int dataSize;
  118.     private int transferSize;
  119.  
  120. }
  121.