|                                                                                                              1
 21
 22  package org.apache.derby.iapi.types;
 23
 24  import org.apache.derby.iapi.types.DataValueDescriptor;
 25  import org.apache.derby.iapi.types.TypeId;
 26  import org.apache.derby.iapi.error.StandardException;
 27
 28  import org.apache.derby.iapi.reference.SQLState;
 29  import org.apache.derby.iapi.services.io.StoredFormatIds;
 30
 31  import org.apache.derby.iapi.services.sanity.SanityManager;
 32
 33  import java.sql.Blob
  ; 34  import java.sql.Clob
  ; 35  import java.sql.Date
  ; 36  import java.sql.SQLException
  ; 37  import java.sql.Time
  ; 38  import java.sql.Timestamp
  ; 39  import java.util.Calendar
  ; 40
 41
 42
 53  public class SQLClob
 54      extends SQLVarchar
 55  {
 56
 63
 64      public String
  getTypeName() 65      {
 66          return TypeId.CLOB_NAME;
 67      }
 68
 69
 72
 73
 74      public DataValueDescriptor getClone()
 75      {
 76          try
 77          {
 78              return new SQLClob(getString());
 79          }
 80          catch (StandardException se)
 81          {
 82              if (SanityManager.DEBUG)
 83                  SanityManager.THROWASSERT("Unexpected exception " + se);
 84              return null;
 85          }
 86      }
 87
 88
 92      public DataValueDescriptor getNewNull()
 93      {
 94          return new SQLClob();
 95      }
 96
 97
 100
 101
 106     public int getTypeFormatId() {
 107         return StoredFormatIds.SQL_CLOB_ID;
 108     }
 109
 110
 113
 114     public SQLClob()
 115     {
 116     }
 117
 118     public SQLClob(String
  val) 119     {
 120         super(val);
 121     }
 122
 123
 126
 127
 128     public int typePrecedence()
 129     {
 130         return TypeId.CLOB_PRECEDENCE;
 131     }
 132
 133
 138
 139     public Object
  getObject() throws StandardException 140     {
 141         throw dataTypeConversion("java.lang.Object");
 142     }
 143
 144     public boolean  getBoolean() throws StandardException
 145     {
 146         throw dataTypeConversion("boolean");
 147     }
 148
 149     public byte getByte() throws StandardException
 150     {
 151         throw dataTypeConversion("byte");
 152     }
 153
 154     public short    getShort() throws StandardException
 155     {
 156         throw dataTypeConversion("short");
 157     }
 158
 159     public int  getInt() throws StandardException
 160     {
 161         throw dataTypeConversion("int");
 162     }
 163
 164     public long getLong() throws StandardException
 165     {
 166         throw dataTypeConversion("long");
 167     }
 168
 169     public float    getFloat() throws StandardException
 170     {
 171         throw dataTypeConversion("float");
 172     }
 173
 174     public double   getDouble() throws StandardException
 175     {
 176         throw dataTypeConversion("double");
 177     }
 178     public int typeToBigDecimal() throws StandardException
 179     {
 180         throw dataTypeConversion("java.math.BigDecimal");
 181     }
 182     public byte[]   getBytes() throws StandardException
 183     {
 184         throw dataTypeConversion("byte[]");
 185     }
 186
 187     public Date
  getDate(java.util.Calendar  cal) throws StandardException 188     {
 189         throw dataTypeConversion("java.sql.Date");
 190     }
 191
 192     public Time
  getTime(java.util.Calendar  cal) throws StandardException 193     {
 194         throw dataTypeConversion("java.sql.Time");
 195     }
 196
 197     public Timestamp
  getTimestamp(java.util.Calendar  cal) throws StandardException 198     {
 199         throw dataTypeConversion("java.sql.Timestamp");
 200     }
 201
 202
 207     public final String
  getTraceString() throws StandardException { 208                 if (isNull()) {
 210             return "NULL";
 211         }
 212
 213                 if (getStream() != null) {
 215             return ("CLOB(" + getStream().toString() + ")");
 216         }
 217
 218         return ("CLOB(" + getLength() + ")");
 219     }
 220
 221
 237
 238     public void normalize(
 239                 DataTypeDescriptor desiredType,
 240                 DataValueDescriptor sourceValue)
 241                     throws StandardException
 242     {
 243                                                                 if( sourceValue instanceof SQLClob)
 251         {
 252             SQLClob clob = (SQLClob)sourceValue;
 253             if (clob.stream != null)
 254             {
 255                 copyState(clob);
 256                 return;
 257             }
 258         }
 259
 260         super.normalize(desiredType,sourceValue);
 261     }
 262
 263     public void setValue(Time
  theValue, Calendar  cal) throws StandardException 264     {
 265         throwLangSetMismatch("java.sql.Time");
 266     }
 267
 268     public void setValue(Timestamp
  theValue, Calendar  cal) throws StandardException 269     {
 270         throwLangSetMismatch("java.sql.Timestamp");
 271     }
 272
 273     public void setValue(Date
  theValue, Calendar  cal) throws StandardException 274     {
 275         throwLangSetMismatch("java.sql.Date");
 276     }
 277
 278     public void setBigDecimal(Number
  bigDecimal) throws StandardException 279     {
 280         throwLangSetMismatch("java.math.BigDecimal");
 281     }
 282
 283     public void setValue(int theValue) throws StandardException
 284     {
 285         throwLangSetMismatch("int");
 286     }
 287
 288     public void setValue(double theValue) throws StandardException
 289     {
 290         throwLangSetMismatch("double");
 291     }
 292
 293     public void setValue(float theValue) throws StandardException
 294     {
 295         throwLangSetMismatch("float");
 296     }
 297
 298     public void setValue(short theValue) throws StandardException
 299     {
 300         throwLangSetMismatch("short");
 301     }
 302
 303     public void setValue(long theValue) throws StandardException
 304     {
 305         throwLangSetMismatch("long");
 306     }
 307
 308
 309     public void setValue(byte theValue) throws StandardException
 310     {
 311         throwLangSetMismatch("byte");
 312     }
 313
 314     public void setValue(boolean theValue) throws StandardException
 315     {
 316         throwLangSetMismatch("boolean");
 317     }
 318
 319     public void setValue(byte[] theValue) throws StandardException
 320     {
 321         throwLangSetMismatch("byte[]");
 322     }
 323
 324
 327     final void setObject(Object
  theValue) 328         throws StandardException
 329     {
 330         Clob
  vc = (Clob  ) theValue; 331
 332         try {
 333             long vcl = vc.length();
 334             if (vcl < 0L || vcl > Integer.MAX_VALUE)
 335                 throw this.outOfRange();
 336
 337             setValue(new ReaderToUTF8Stream(vc.getCharacterStream(),
 338                     (int) vcl, 0, TypeId.CLOB_NAME), (int) vcl);
 339
 340         } catch (SQLException
  e) { 341             throw dataTypeConversion("DAN-438-tmp");
 342        }
 343     }
 344 }
 345
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |