home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1998 September / maximum-cd-1998-09.iso / Hotmetal / hm4ev.exe / applets.z / CharField.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-19  |  5.2 KB  |  257 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import symjava.lang.Bignum;
  8. import symjava.sql.Date;
  9. import symjava.sql.SQLException;
  10. import symjava.sql.Time;
  11. import symjava.sql.Timestamp;
  12.  
  13. abstract class CharField extends Field {
  14.    String _data;
  15.  
  16.    void read(DataInputStream var1) throws SQLException, IOException, ErrorException {
  17.       super.read(var1);
  18.       this._data = new String("");
  19.    }
  20.  
  21.    void write(DataOutputStream var1) throws IOException {
  22.       super.write(var1);
  23.    }
  24.  
  25.    public String getString() throws SQLException {
  26.       return ((Field)this).isNull() ? null : new String(this._data);
  27.    }
  28.  
  29.    public boolean getBoolean() throws SQLException {
  30.       if (((Field)this).isNull()) {
  31.          return false;
  32.       } else {
  33.          byte var1 = (byte)this._data.charAt(0);
  34.          return var1 != 0;
  35.       }
  36.    }
  37.  
  38.    public byte getByte() throws SQLException {
  39.       if (((Field)this).isNull()) {
  40.          return 0;
  41.       } else {
  42.          try {
  43.             Double var1 = new Double(this._data);
  44.             return (byte)var1.intValue();
  45.          } catch (Exception var2) {
  46.             throw new SQLException(((Throwable)var2).getMessage());
  47.          }
  48.       }
  49.    }
  50.  
  51.    public short getShort() throws SQLException {
  52.       if (((Field)this).isNull()) {
  53.          return 0;
  54.       } else {
  55.          try {
  56.             Double var1 = new Double(this._data);
  57.             return (short)var1.intValue();
  58.          } catch (Exception var2) {
  59.             throw new SQLException(((Throwable)var2).getMessage());
  60.          }
  61.       }
  62.    }
  63.  
  64.    public int getInt() throws SQLException {
  65.       if (((Field)this).isNull()) {
  66.          return 0;
  67.       } else {
  68.          try {
  69.             Double var1 = new Double(this._data);
  70.             return var1.intValue();
  71.          } catch (Exception var2) {
  72.             throw new SQLException(((Throwable)var2).getMessage());
  73.          }
  74.       }
  75.    }
  76.  
  77.    public long getLong() throws SQLException {
  78.       if (((Field)this).isNull()) {
  79.          return 0L;
  80.       } else {
  81.          try {
  82.             Double var1 = new Double(this._data);
  83.             return var1.longValue();
  84.          } catch (Exception var2) {
  85.             throw new SQLException(((Throwable)var2).getMessage());
  86.          }
  87.       }
  88.    }
  89.  
  90.    public float getFloat() throws SQLException {
  91.       if (((Field)this).isNull()) {
  92.          return 0.0F;
  93.       } else {
  94.          try {
  95.             Double var1 = new Double(this._data);
  96.             return var1.floatValue();
  97.          } catch (Exception var2) {
  98.             throw new SQLException(((Throwable)var2).getMessage());
  99.          }
  100.       }
  101.    }
  102.  
  103.    public double getDouble() throws SQLException {
  104.       if (((Field)this).isNull()) {
  105.          return (double)0.0F;
  106.       } else {
  107.          try {
  108.             Double var1 = new Double(this._data);
  109.             return var1;
  110.          } catch (Exception var2) {
  111.             throw new SQLException(((Throwable)var2).getMessage());
  112.          }
  113.       }
  114.    }
  115.  
  116.    public Bignum getBignum(int var1) throws SQLException {
  117.       return ((Field)this).isNull() ? null : new Bignum(this._data, var1);
  118.    }
  119.  
  120.    public byte[] getBytes() throws SQLException {
  121.       if (((Field)this).isNull()) {
  122.          return new byte[0];
  123.       } else {
  124.          try {
  125.             byte[] var1 = new byte[this._data.length()];
  126.             this._data.getBytes(0, this._data.length() - 1, var1, 0);
  127.             return var1;
  128.          } catch (Exception var2) {
  129.             throw new SQLException(((Throwable)var2).getMessage());
  130.          }
  131.       }
  132.    }
  133.  
  134.    public Date getDate() throws SQLException {
  135.       return ((Field)this).isNull() ? null : Date.valueOf(this._data);
  136.    }
  137.  
  138.    public Time getTime() throws SQLException {
  139.       return ((Field)this).isNull() ? null : Time.valueOf(this._data);
  140.    }
  141.  
  142.    public Timestamp getTimestamp() throws SQLException {
  143.       return ((Field)this).isNull() ? null : Timestamp.valueOf(this._data);
  144.    }
  145.  
  146.    public InputStream getAsciiStream() throws SQLException {
  147.       return ((Field)this).isNull() ? null : new BinaryInputStream(this._data);
  148.    }
  149.  
  150.    public InputStream getUnicodeStream() throws SQLException {
  151.       return ((Field)this).isNull() ? null : new BinaryInputStream(this._data);
  152.    }
  153.  
  154.    public InputStream getBinaryStream() throws SQLException {
  155.       return ((Field)this).isNull() ? null : new BinaryInputStream(this._data);
  156.    }
  157.  
  158.    public void setBoolean(boolean var1) throws SQLException {
  159.       if (var1) {
  160.          this._data = new String("true");
  161.       } else {
  162.          this._data = new String("false");
  163.       }
  164.  
  165.       super._null = false;
  166.    }
  167.  
  168.    public void setByte(byte var1) throws SQLException {
  169.       this._data = Integer.toString(var1);
  170.       super._null = false;
  171.    }
  172.  
  173.    public void setShort(short var1) throws SQLException {
  174.       this._data = Integer.toString(var1);
  175.       super._null = false;
  176.    }
  177.  
  178.    public void setInt(int var1) throws SQLException {
  179.       this._data = Integer.toString(var1);
  180.       super._null = false;
  181.    }
  182.  
  183.    public void setLong(long var1) throws SQLException {
  184.       this._data = Long.toString(var1);
  185.       super._null = false;
  186.    }
  187.  
  188.    public void setFloat(float var1) throws SQLException {
  189.       this._data = Float.toString(var1);
  190.       super._null = false;
  191.    }
  192.  
  193.    public void setDouble(double var1) throws SQLException {
  194.       this._data = Double.toString(var1);
  195.       super._null = false;
  196.    }
  197.  
  198.    public void setBignum(Bignum var1) throws SQLException {
  199.       this._data = var1.toString();
  200.       super._null = false;
  201.    }
  202.  
  203.    public void setString(String var1) throws SQLException {
  204.       this._data = var1;
  205.       super._null = false;
  206.    }
  207.  
  208.    public void setBytes(byte[] var1) throws SQLException {
  209.       this._data = new String(var1, 0);
  210.       super._null = false;
  211.    }
  212.  
  213.    public void setDate(Date var1) throws SQLException {
  214.       this._data = var1.toString();
  215.       super._null = false;
  216.    }
  217.  
  218.    public void setTime(Time var1) throws SQLException {
  219.       this._data = var1.toString();
  220.       super._null = false;
  221.    }
  222.  
  223.    public void setTimestamp(Timestamp var1) throws SQLException {
  224.       this._data = var1.toString();
  225.       super._null = false;
  226.    }
  227.  
  228.    public void setStream(InputStream var1, int var2) throws SQLException {
  229.       if (var2 >= 0 && var2 <= 255) {
  230.          byte[] var3 = new byte[var2];
  231.  
  232.          try {
  233.             var1.read(var3, 0, var2);
  234.          } catch (IOException var5) {
  235.             throw new SQLException(((Throwable)var5).getMessage());
  236.          }
  237.  
  238.          this._data = new String(var3, 0, 0, var3.length);
  239.          super._null = false;
  240.       } else {
  241.          throw new SQLException("Stream length out of range.");
  242.       }
  243.    }
  244.  
  245.    public void setAsciiStream(InputStream var1, int var2) throws SQLException {
  246.       this.setStream(var1, var2);
  247.    }
  248.  
  249.    public void setUnicodeStream(InputStream var1, int var2) throws SQLException {
  250.       this.setStream(var1, var2);
  251.    }
  252.  
  253.    public void setBinaryStream(InputStream var1, int var2) throws SQLException {
  254.       this.setStream(var1, var2);
  255.    }
  256. }
  257.