Coverage report

  %line %branch
com.workingdogs.village.Value
0% 
0% 

 1  
 package com.workingdogs.village;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.math.BigDecimal;
 23  
 
 24  
 import java.sql.Blob;
 25  
 import java.sql.PreparedStatement;
 26  
 import java.sql.ResultSet;
 27  
 import java.sql.SQLException;
 28  
 import java.sql.Time;
 29  
 import java.sql.Timestamp;
 30  
 import java.sql.Types;
 31  
 
 32  
 import java.util.Calendar;
 33  
 
 34  
 /**
 35  
  * A Value represents a single cell in a database table. In other words, 
 36  
  * it is the cross between a row and column and contains the
 37  
  * information held there.
 38  
  *
 39  
  * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
 40  
  * @version $Revision: 568 $
 41  
  */
 42  
 public class Value
 43  
 {
 44  
     /** the object that is stored in this object */
 45  
     private Object valueObject;
 46  
 
 47  
     /** the column number that this object came from */
 48  
     private int columnNumber;
 49  
 
 50  
     /** what sql type of object is this? */
 51  
     private int type;
 52  
 
 53  
     /**
 54  
      * Creates a new Value object based on the ResultSet, columnNumber and 
 55  
      * type
 56  
      *
 57  
      * @param rs
 58  
      * @param columnNumber
 59  
      * @param type
 60  
      *
 61  
      * @exception SQLException
 62  
      */
 63  
     public Value(ResultSet rs, int columnNumber, class="keyword">int type)
 64  
             throws SQLException
 65  0
     {
 66  0
         this.columnNumber = columnNumber;
 67  0
         this.type = type;
 68  0
         this.valueObject = null;
 69  
 
 70  0
         if (rs == null)
 71  
         {
 72  0
             return;
 73  
         }
 74  
 
 75  0
         switch (type())
 76  
         {
 77  
         case Types.BIT:
 78  
 
 79  0
             String tmp = rs.getString(columnNumber);
 80  
 
 81  0
             if (tmp == null)
 82  
             {
 83  0
                 valueObject = Boolean.FALSE;
 84  
             }
 85  0
             else if (isTrue(tmp))
 86  
             {
 87  0
                 valueObject = Boolean.TRUE;
 88  
             }
 89  
             else
 90  
             {
 91  0
                 valueObject = Boolean.FALSE;
 92  
             }
 93  
 
 94  0
             break;
 95  
 
 96  
         case Types.TINYINT:
 97  0
             valueObject = new Byte(rs.getByte(columnNumber));
 98  
 
 99  0
             break;
 100  
 
 101  
         case Types.BIGINT:
 102  0
             valueObject = new Long(rs.getLong(columnNumber));
 103  
 
 104  0
             break;
 105  
 
 106  
         case Types.SMALLINT:
 107  0
             valueObject = new Short(rs.getShort(columnNumber));
 108  
 
 109  0
             break;
 110  
 
 111  
         case Types.INTEGER:
 112  0
             valueObject = new Integer(rs.getInt(columnNumber));
 113  
 
 114  0
             break;
 115  
 
 116  
         case Types.REAL:
 117  0
             valueObject = new Float(rs.getFloat(columnNumber));
 118  
 
 119  0
             break;
 120  
 
 121  
         case Types.FLOAT:
 122  
         case Types.DOUBLE:
 123  0
             valueObject = new Double(rs.getDouble(columnNumber));
 124  
 
 125  0
             break;
 126  
 
 127  
         case Types.NUMERIC:
 128  
         case Types.DECIMAL:
 129  
 
 130  0
             String number = rs.getString(columnNumber);
 131  
 
 132  0
             if (number == null)
 133  
             {
 134  0
                 valueObject = null;
 135  
             }
 136  
             else
 137  
             {
 138  0
                 valueObject = new BigDecimal(number);
 139  
             }
 140  
 
 141  0
             break;
 142  
 
 143  
         case Types.LONGVARBINARY:
 144  
         case Types.VARBINARY:
 145  
         case Types.BINARY:
 146  0
             valueObject = rs.getBytes(columnNumber);
 147  
 
 148  0
             break;
 149  
 
 150  
         case Types.BLOB:
 151  
 
 152  0
             Blob blob = rs.getBlob(columnNumber);
 153  0
             valueObject = blob.getBytes(1, (int) blob.length());
 154  
 
 155  0
             break;
 156  
 
 157  
         case Types.LONGVARCHAR:
 158  
         case Types.CHAR:
 159  
         case Types.VARCHAR:
 160  
         case Types.OTHER:
 161  0
             valueObject = rs.getString(columnNumber);
 162  
 
 163  0
             break;
 164  
 
 165  
         case Types.DATE:
 166  0
             valueObject = rs.getDate(columnNumber);
 167  
 
 168  0
             break;
 169  
 
 170  
         case Types.TIME:
 171  0
             valueObject = rs.getTime(columnNumber);
 172  
 
 173  0
             break;
 174  
 
 175  
         case Types.TIMESTAMP:
 176  0
             valueObject = rs.getTimestamp(columnNumber);
 177  
 
 178  0
             break;
 179  
 
 180  
         case Types.NULL:
 181  0
             valueObject = null;
 182  
 
 183  0
             break;
 184  
 
 185  
         default:
 186  0
             valueObject = rs.getString(columnNumber);
 187  
 
 188  
             break;
 189  
         }
 190  
 
 191  0
         if (rs.wasNull())
 192  
         {
 193  0
             valueObject = null;
 194  
         }
 195  
 
 196  0
         return;
 197  
     }
 198  
 
 199  
     /**
 200  
      * Sets the value of this object
 201  
      *
 202  
      * @param value
 203  
      */
 204  
     void setValue(Object value)
 205  
     {
 206  0
         this.valueObject = value;
 207  0
     }
 208  
 
 209  
     /**
 210  
      * Gets the object from this Value
 211  
      *
 212  
      * @return the object from this Value
 213  
      */
 214  
     Object getValue()
 215  
     {
 216  0
         return this.valueObject;
 217  
     }
 218  
 
 219  
     /**
 220  
      * This is used in Record in order to do a saveWithInsert/Update/Delete
 221  
      *
 222  
      * @param stmt
 223  
      * @param stmtNumber
 224  
      *
 225  
      * @exception DataSetException
 226  
      * @exception SQLException
 227  
      */
 228  
     void setPreparedStatementValue(PreparedStatement stmt, int stmtNumber)
 229  
             throws DataSetException, SQLException
 230  
     {
 231  0
         if (isNull())
 232  
         {
 233  0
             stmt.setNull(stmtNumber, type());
 234  
 
 235  0
             return;
 236  
         }
 237  
 
 238  0
         switch (type())
 239  
         {
 240  
         case Types.BIT:
 241  0
             stmt.setBoolean(stmtNumber, this.asBoolean());
 242  
 
 243  0
             break;
 244  
 
 245  
         case Types.TINYINT:
 246  0
             stmt.setByte(stmtNumber, this.asByte());
 247  
 
 248  0
             break;
 249  
 
 250  
         case Types.BIGINT:
 251  0
             stmt.setLong(stmtNumber, this.asLong());
 252  
 
 253  0
             break;
 254  
 
 255  
         case Types.SMALLINT:
 256  0
             stmt.setShort(stmtNumber, this.asShort());
 257  
 
 258  0
             break;
 259  
 
 260  
         case Types.INTEGER:
 261  0
             stmt.setInt(stmtNumber, this.asInt());
 262  
 
 263  0
             break;
 264  
 
 265  
         case Types.REAL:
 266  0
             stmt.setFloat(stmtNumber, this.asFloat());
 267  
 
 268  0
             break;
 269  
 
 270  
         case Types.FLOAT:
 271  
         case Types.DOUBLE:
 272  0
             stmt.setDouble(stmtNumber, this.asDouble());
 273  
 
 274  0
             break;
 275  
 
 276  
         case Types.NUMERIC:
 277  
         case Types.DECIMAL:
 278  0
             stmt.setBigDecimal(stmtNumber, this.asBigDecimal());
 279  
 
 280  0
             break;
 281  
 
 282  
         case Types.LONGVARBINARY:
 283  
         case Types.VARBINARY:
 284  
         case Types.BINARY:
 285  
         case Types.BLOB:
 286  
 
 287  
             // The following form is reported to work and be necessary for
 288  
             // Oracle when the blob exceeds 4k.
 289  0
             byte [] value = this.asBytes();
 290  0
             stmt.setBinaryStream(stmtNumber, 
 291  
                     new java.io.ByteArrayInputStream(value), value.length);
 292  
 
 293  0
             break;
 294  
 
 295  
         case Types.LONGVARCHAR:
 296  
         case Types.CHAR:
 297  
         case Types.VARCHAR:
 298  
         case Types.OTHER:
 299  0
             stmt.setString(stmtNumber, this.asString());
 300  
 
 301  0
             break;
 302  
 
 303  
         case Types.DATE:
 304  0
             stmt.setDate(stmtNumber, this.asDate());
 305  
 
 306  0
             break;
 307  
 
 308  
         case Types.TIME:
 309  0
             stmt.setTime(stmtNumber, this.asTime());
 310  
 
 311  0
             break;
 312  
 
 313  
         case Types.TIMESTAMP:
 314  0
             stmt.setTimestamp(stmtNumber, this.asTimestamp());
 315  
 
 316  0
             break;
 317  
 
 318  
         case Types.NULL:
 319  0
             stmt.setNull(stmtNumber, 0);
 320  
 
 321  0
             break;
 322  
 
 323  
         default:
 324  0
             stmt.setString(stmtNumber, this.asString());
 325  
 
 326  
             break;
 327  
         }
 328  0
     }
 329  
 
 330  
     /**
 331  
      * Returns the string representation of this object
 332  
      *
 333  
      * @return a string
 334  
      */
 335  
     public String toString()
 336  
     {
 337  0
         return this.asString();
 338  
     }
 339  
 
 340  
     /**
 341  
      * Returns the string representation of this object
 342  
      *
 343  
      * @return a string
 344  
      */
 345  
     public String asString()
 346  
     {
 347  0
         if (isNull())
 348  
         {
 349  0
             return null;
 350  
         }
 351  0
         else if (isString())
 352  
         {
 353  0
             return (String) valueObject;
 354  
         }
 355  0
         else if (isBytes())
 356  
         {
 357  0
             return new String((byte []) valueObject);
 358  
         }
 359  
         else
 360  
         {
 361  0
             return valueObject.toString();
 362  
         }
 363  
     }
 364  
 
 365  
     /**
 366  
      * Get the value as a BigDecimal
 367  
      *
 368  
      * @return a BigDecimal
 369  
      *
 370  
      * @exception DataSetException
 371  
      */
 372  
     public BigDecimal asBigDecimal()
 373  
             throws DataSetException
 374  
     {
 375  
         try
 376  
         {
 377  0
             if (isNull())
 378  
             {
 379  0
                 return null;
 380  
             }
 381  0
             else if (isBigDecimal())
 382  
             {
 383  0
                 return (BigDecimal) valueObject;
 384  
             }
 385  0
             else if ( isDouble() ) {
 386  0
                 return new BigDecimal(((Double) valueObject).doubleValue() );
 387  
             }
 388  0
             else if ( isFloat() ) 
 389  
             {
 390  0
                 return new BigDecimal(((Float) valueObject).doubleValue());
 391  
             }
 392  0
             else if(isString() || isInt() || isLong() || isShort() || isByte())
 393  
             {
 394  0
                 return new BigDecimal(asString());
 395  
             }
 396  
             else
 397  
             {
 398  0
                 return null;
 399  
             }
 400  
         }
 401  0
         catch (Exception e)
 402  
         {
 403  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 404  
         }
 405  
     }
 406  
 
 407  
     /**
 408  
      * Get the value as a BigDecimal
 409  
      *
 410  
      * @param scale TODO: DOCUMENT ME!
 411  
      *
 412  
      * @return a BigDecimal
 413  
      *
 414  
      * @exception DataSetException
 415  
      */
 416  
     public BigDecimal asBigDecimal(int scale)
 417  
             throws DataSetException
 418  
     {
 419  
         try
 420  
         {
 421  0
             if (isNull())
 422  
             {
 423  0
                 return null;
 424  
             }
 425  0
             else if (isBigDecimal())
 426  
             {
 427  0
                 return ((BigDecimal) valueObject).setScale(scale);
 428  
             }
 429  0
             else if ( isDouble() )
 430  
             {
 431  0
                 return new BigDecimal( ((Double) valueObject).doubleValue())
 432  
                                                              .setScale(scale);
 433  
             } 
 434  0
             else if ( isFloat() ) 
 435  
             {
 436  0
                 return new BigDecimal(((Float) valueObject).doubleValue())
 437  
                                 .setScale(scale);
 438  
             }
 439  0
             else if(isString() || isInt() || isLong() || isShort() || isByte())
 440  
             {
 441  0
                 return new BigDecimal(asString()).setScale(scale);
 442  
             }
 443  
             else
 444  
             {
 445  0
                 return null;
 446  
             }
 447  
         }
 448  0
         catch (Exception e)
 449  
         {
 450  0
             throw new DataSetException("Bad conversion: " + e.toString());
 451  
         }
 452  
     }
 453  
 
 454  
     /**
 455  
      * Get the value as a asBoolean
 456  
      *
 457  
      * @return a boolean
 458  
      *
 459  
      * @exception DataSetException
 460  
      */
 461  
     public boolean asBoolean()
 462  
             throws DataSetException
 463  
     {
 464  
         try
 465  
         {
 466  0
             if (isNull())
 467  
             {
 468  0
                 return false;
 469  
             }
 470  0
             else if (isBoolean())
 471  
             {
 472  0
                 return ((Boolean) valueObject).booleanValue();
 473  
             }
 474  
 
 475  0
             String check = asString();
 476  
 
 477  0
             return (check == null) ? false : isTrue(check);
 478  
         }
 479  0
         catch (Exception e)
 480  
         {
 481  0
             throw new DataSetException("Bad conversion: " + e.toString());
 482  
         }
 483  
     }
 484  
 
 485  
     /**
 486  
      * Get the value as a Boolean object
 487  
      *
 488  
      * @return a Boolean
 489  
      *
 490  
      * @exception DataSetException
 491  
      */
 492  
     public Boolean asBooleanObj()
 493  
             throws DataSetException
 494  
     {
 495  
         try
 496  
         {
 497  0
             if (isNull())
 498  
             {
 499  0
                 return null;
 500  
             }
 501  0
             else if (isBoolean())
 502  
             {
 503  0
                 return (Boolean) valueObject;
 504  
             }
 505  
 
 506  0
             String check = asString();
 507  
 
 508  0
             if (check == null)
 509  
             {
 510  0
                 return null;
 511  
             }
 512  0
             else if (isTrue(check))
 513  
             {
 514  0
                 return Boolean.TRUE;
 515  
             }
 516  
             else
 517  
             {
 518  0
                 return Boolean.FALSE;
 519  
             }
 520  
         }
 521  0
         catch (Exception e)
 522  
         {
 523  0
             throw new DataSetException("Bad conversion: " + e.toString());
 524  
         }
 525  
     }
 526  
 
 527  
     /**
 528  
      * Get the value as a asInt
 529  
      *
 530  
      * @return an int
 531  
      *
 532  
      * @exception DataSetException
 533  
      */
 534  
     public int asInt()
 535  
             throws DataSetException
 536  
     {
 537  
         try
 538  
         {
 539  0
             if (isNull())
 540  
             {
 541  0
                 return 0;
 542  
             }
 543  0
             else if (isInt())
 544  
             {
 545  0
                 return ((Integer) valueObject).intValue();
 546  
             }
 547  0
             else if (isString())
 548  
             {
 549  0
                 return Integer.valueOf((String) valueObject).intValue();
 550  
             }
 551  0
             else if (isLong())
 552  
             {
 553  0
                 return ((Long) valueObject).intValue();
 554  
             }
 555  0
             else if (isDouble())
 556  
             {
 557  0
                 return ((Double) valueObject).intValue();
 558  
             }
 559  0
             else if (isFloat())
 560  
             {
 561  0
                 return ((Float) valueObject).intValue();
 562  
             }
 563  0
             else if (isBigDecimal())
 564  
             {
 565  0
                 return ((BigDecimal) valueObject).intValue();
 566  
             }
 567  
             else
 568  
             {
 569  0
                 return Integer.valueOf(asString()).intValue();
 570  
             }
 571  
         }
 572  0
         catch (Exception e)
 573  
         {
 574  0
             throw new DataSetException("Bad conversion: " + e.toString());
 575  
         }
 576  
     }
 577  
 
 578  
     /**
 579  
      * Get the value as a Integer Ojbect
 580  
      *
 581  
      * @return an Integer
 582  
      *
 583  
      * @exception DataSetException
 584  
      */
 585  
     public Integer asIntegerObj()
 586  
             throws DataSetException
 587  
     {
 588  
         try
 589  
         {
 590  0
             if (isNull())
 591  
             {
 592  0
                 return null;
 593  
             }
 594  0
             else if (isInt())
 595  
             {
 596  0
                 return ((Integer) valueObject);
 597  
             }
 598  0
             else if (isString() || isDouble() || isFloat() || isBigDecimal() 
 599  
                      || isLong() || isShort() || isByte())
 600  
             {
 601  0
                 return new Integer(asString());
 602  
             }
 603  
             else
 604  
             {
 605  0
                 throw new DataSetException("Invalid type for Integer");
 606  
             }
 607  
         }
 608  0
         catch (Exception e)
 609  
         {
 610  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 611  
         }
 612  
     }
 613  
 
 614  
     /**
 615  
      * Get the value as a asByte
 616  
      *
 617  
      * @return a byte
 618  
      *
 619  
      * @exception DataSetException
 620  
      */
 621  
     public byte asByte()
 622  
             throws DataSetException
 623  
     {
 624  
         try
 625  
         {
 626  0
             if (isNull())
 627  
             {
 628  0
                 return 0;
 629  
             }
 630  0
             else if (isByte())
 631  
             {
 632  0
                 return ((Byte) valueObject).byteValue();
 633  
             }
 634  0
             else if (isString())
 635  
             {
 636  0
                 return Integer.valueOf((String) valueObject).byteValue();
 637  
             }
 638  0
             else if (isShort())
 639  
             {
 640  0
                 return ((Short) valueObject).byteValue();
 641  
             }
 642  0
             else if (isInt())
 643  
             {
 644  0
                 return ((Integer) valueObject).byteValue();
 645  
             }
 646  0
             else if (isLong())
 647  
             {
 648  0
                 return ((Long) valueObject).byteValue();
 649  
             }
 650  0
             else if (isDouble())
 651  
             {
 652  0
                 return ((Double) valueObject).byteValue();
 653  
             }
 654  0
             else if (isFloat())
 655  
             {
 656  0
                 return ((Float) valueObject).byteValue();
 657  
             }
 658  0
             else if (isBigDecimal())
 659  
             {
 660  0
                 return ((BigDecimal) valueObject).byteValue();
 661  
             }
 662  
             else
 663  
             {
 664  0
                 return Integer.valueOf(asString()).byteValue();
 665  
             }
 666  
         }
 667  0
         catch (Exception e)
 668  
         {
 669  0
             throw new DataSetException("Bad conversion: " + e.toString());
 670  
         }
 671  
     }
 672  
 
 673  
     /**
 674  
      * Get the value as a Byte Object
 675  
      *
 676  
      * @return a Byte
 677  
      *
 678  
      * @exception DataSetException
 679  
      */
 680  
     public Byte asByteObj()
 681  
             throws DataSetException
 682  
     {
 683  
         try
 684  
         {
 685  0
             if (isNull())
 686  
             {
 687  0
                 return null;
 688  
             }
 689  0
             else if (isByte())
 690  
             {
 691  0
                 return ((Byte) valueObject);
 692  
             }
 693  0
             else if (isString() || isDouble() || isFloat() || isInt() || 
 694  
                      isLong() || isShort() || isBigDecimal())
 695  
             {
 696  0
                 return new Byte(asString());
 697  
             }
 698  
             else
 699  
             {
 700  0
                 throw new DataSetException("Invalid type for Byte");
 701  
             }
 702  
         }
 703  0
         catch (Exception e)
 704  
         {
 705  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 706  
         }
 707  
     }
 708  
 
 709  
     /**
 710  
      * Get the value as a asBytes
 711  
      *
 712  
      * @return a byte array
 713  
      *
 714  
      * @exception DataSetException
 715  
      */
 716  
     public byte [] asBytes()
 717  
             throws DataSetException
 718  
     {
 719  
         try
 720  
         {
 721  0
             if (isNull())
 722  
             {
 723  0
                 return new byte[0];
 724  
             }
 725  0
             else if (isBytes())
 726  
             {
 727  0
                 return (byte []) valueObject;
 728  
             }
 729  0
             else if (isString())
 730  
             {
 731  0
                 return ((String) valueObject).getBytes();
 732  
             }
 733  
         }
 734  0
         catch (Exception e)
 735  
         {
 736  0
             throw new DataSetException("Bad conversion: " + e.toString());
 737  0
         }
 738  
 
 739  0
         return new byte[0];
 740  
     }
 741  
 
 742  
     /**
 743  
      * Get the value as a asShort
 744  
      *
 745  
      * @return a short
 746  
      *
 747  
      * @exception DataSetException
 748  
      */
 749  
     public short asShort()
 750  
             throws DataSetException
 751  
     {
 752  
         try
 753  
         {
 754  0
             if (isNull())
 755  
             {
 756  0
                 return 0;
 757  
             }
 758  0
             else if (isShort())
 759  
             {
 760  0
                 return ((Short) valueObject).shortValue();
 761  
             }
 762  0
             else if (isString())
 763  
             {
 764  0
                 return Integer.valueOf((String) valueObject).shortValue();
 765  
             }
 766  0
             else if (isInt())
 767  
             {
 768  0
                 return ((Integer) valueObject).shortValue();
 769  
             }
 770  0
             else if (isLong())
 771  
             {
 772  0
                 return ((Long) valueObject).shortValue();
 773  
             }
 774  0
             else if (isDouble())
 775  
             {
 776  0
                 return ((Double) valueObject).shortValue();
 777  
             }
 778  0
             else if (isFloat())
 779  
             {
 780  0
                 return ((Float) valueObject).shortValue();
 781  
             }
 782  0
             else if (isBigDecimal())
 783  
             {
 784  0
                 return ((BigDecimal) valueObject).shortValue();
 785  
             }
 786  
             else
 787  
             {
 788  0
                 return Integer.valueOf(asString()).shortValue();
 789  
             }
 790  
         }
 791  0
         catch (Exception e)
 792  
         {
 793  0
             throw new DataSetException("Bad conversion: " + e.toString());
 794  
         }
 795  
     }
 796  
 
 797  
     /**
 798  
      * Get the value as a Short Object
 799  
      *
 800  
      * @return a Short
 801  
      *
 802  
      * @exception DataSetException
 803  
      */
 804  
     public Short asShortObj()
 805  
             throws DataSetException
 806  
     {
 807  
         try
 808  
         {
 809  0
             if (isNull())
 810  
             {
 811  0
                 return null;
 812  
             }
 813  0
             else if (isShort())
 814  
             {
 815  0
                 return ((Short) valueObject);
 816  
             }
 817  0
             else if (isString() || isDouble() || isFloat() || isInt() || 
 818  
                      isLong() || isBigDecimal() || isByte())
 819  
             {
 820  0
                 return new Short(asString());
 821  
             }
 822  
             else
 823  
             {
 824  0
                 throw new DataSetException("Invalid type for Short");
 825  
             }
 826  
         }
 827  0
         catch (Exception e)
 828  
         {
 829  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 830  
         }
 831  
     }
 832  
 
 833  
     /**
 834  
      * Get the value as a asLong
 835  
      *
 836  
      * @return a long
 837  
      *
 838  
      * @exception DataSetException
 839  
      */
 840  
     public long asLong()
 841  
             throws DataSetException
 842  
     {
 843  
         try
 844  
         {
 845  0
             if (isNull())
 846  
             {
 847  0
                 return 0;
 848  
             }
 849  0
             else if (isLong())
 850  
             {
 851  0
                 return ((Long) valueObject).longValue();
 852  
             }
 853  0
             else if (isString())
 854  
             {
 855  0
                 return Integer.valueOf((String) valueObject).longValue();
 856  
             }
 857  0
             else if (isShort())
 858  
             {
 859  0
                 return ((Short) valueObject).longValue();
 860  
             }
 861  0
             else if (isInt())
 862  
             {
 863  0
                 return ((Integer) valueObject).longValue();
 864  
             }
 865  0
             else if (isDouble())
 866  
             {
 867  0
                 return ((Double) valueObject).longValue();
 868  
             }
 869  0
             else if (isFloat())
 870  
             {
 871  0
                 return ((Float) valueObject).longValue();
 872  
             }
 873  0
             else if (isBigDecimal())
 874  
             {
 875  0
                 return ((BigDecimal) valueObject).longValue();
 876  
             }
 877  
             else
 878  
             {
 879  0
                 return Integer.valueOf(asString()).longValue();
 880  
             }
 881  
         }
 882  0
         catch (Exception e)
 883  
         {
 884  0
             throw new DataSetException("Bad conversion: " + e.toString());
 885  
         }
 886  
     }
 887  
 
 888  
     /**
 889  
      * Get the value as a Long Object
 890  
      *
 891  
      * @return a Long
 892  
      *
 893  
      * @exception DataSetException
 894  
      */
 895  
     public Long asLongObj()
 896  
             throws DataSetException
 897  
     {
 898  
         try
 899  
         {
 900  0
             if (isNull())
 901  
             {
 902  0
                 return null;
 903  
             }
 904  0
             else if (isLong())
 905  
             {
 906  0
                 return ((Long) valueObject);
 907  
             }
 908  0
             else if (isString() || isDouble() || isFloat() || isInt() || 
 909  
                      isBigDecimal() || isShort() || isByte())
 910  
             {
 911  0
                 return new Long(asString());
 912  
             }
 913  
             else
 914  
             {
 915  0
                 throw new DataSetException("Invalid type for Long");
 916  
             }
 917  
         }
 918  0
         catch (Exception e)
 919  
         {
 920  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 921  
         }
 922  
     }
 923  
 
 924  
     /**
 925  
      * Get the value as a asDouble
 926  
      *
 927  
      * @return a double
 928  
      *
 929  
      * @exception DataSetException
 930  
      */
 931  
     public double asDouble()
 932  
             throws DataSetException
 933  
     {
 934  
         try
 935  
         {
 936  0
             if (isNull())
 937  
             {
 938  0
                 return 0.0D;
 939  
             }
 940  0
             else if (isDouble())
 941  
             {
 942  0
                 return ((Double) valueObject).doubleValue();
 943  
             }
 944  0
             else if (isString())
 945  
             {
 946  0
                 return Integer.valueOf((String) valueObject).doubleValue();
 947  
             }
 948  0
             else if (isShort())
 949  
             {
 950  0
                 return ((Short) valueObject).doubleValue();
 951  
             }
 952  0
             else if (isInt())
 953  
             {
 954  0
                 return ((Integer) valueObject).doubleValue();
 955  
             }
 956  0
             else if (isLong())
 957  
             {
 958  0
                 return ((Long) valueObject).doubleValue();
 959  
             }
 960  0
             else if (isFloat())
 961  
             {
 962  0
                 return ((Float) valueObject).doubleValue();
 963  
             }
 964  0
             else if (isBigDecimal())
 965  
             {
 966  0
                 return ((BigDecimal) valueObject).doubleValue();
 967  
             }
 968  
             else
 969  
             {
 970  0
                 return Integer.valueOf(asString()).doubleValue();
 971  
             }
 972  
         }
 973  0
         catch (Exception e)
 974  
         {
 975  0
             throw new DataSetException("Bad conversion: " + e.toString());
 976  
         }
 977  
     }
 978  
 
 979  
     /**
 980  
      * Get the value as a Double Object
 981  
      *
 982  
      * @return a Double
 983  
      *
 984  
      * @exception DataSetException
 985  
      */
 986  
     public Double asDoubleObj()
 987  
             throws DataSetException
 988  
     {
 989  
         try
 990  
         {
 991  0
             if (isNull())
 992  
             {
 993  0
                 return null;
 994  
             }
 995  0
             else if (isDouble())
 996  
             {
 997  0
                 return ((Double) valueObject);
 998  
             }
 999  0
             else if (isString() || isBigDecimal() || isFloat() || isInt() || 
 1000  
                      isLong() || isShort() || isByte())
 1001  
             {
 1002  0
                 return new Double(asString());
 1003  
             }
 1004  
             else
 1005  
             {
 1006  0
                 throw new DataSetException("Invalid type for Double");
 1007  
             }
 1008  
         }
 1009  0
         catch (Exception e)
 1010  
         {
 1011  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 1012  
         }
 1013  
     }
 1014  
 
 1015  
     /**
 1016  
      * Get the value as a asFloat
 1017  
      *
 1018  
      * @return a float
 1019  
      *
 1020  
      * @exception DataSetException
 1021  
      */
 1022  
     public float asFloat()
 1023  
             throws DataSetException
 1024  
     {
 1025  
         try
 1026  
         {
 1027  0
             if (isNull())
 1028  
             {
 1029  0
                 return 0.0F;
 1030  
             }
 1031  0
             else if (isFloat())
 1032  
             {
 1033  0
                 return ((Float) valueObject).floatValue();
 1034  
             }
 1035  0
             else if (isString())
 1036  
             {
 1037  0
                 return Integer.valueOf((String) valueObject).floatValue();
 1038  
             }
 1039  0
             else if (isShort())
 1040  
             {
 1041  0
                 return ((Short) valueObject).floatValue();
 1042  
             }
 1043  0
             else if (isInt())
 1044  
             {
 1045  0
                 return ((Integer) valueObject).floatValue();
 1046  
             }
 1047  0
             else if (isLong())
 1048  
             {
 1049  0
                 return ((Long) valueObject).floatValue();
 1050  
             }
 1051  0
             else if (isDouble())
 1052  
             {
 1053  0
                 return ((Double) valueObject).floatValue();
 1054  
             }
 1055  0
             else if (isBigDecimal())
 1056  
             {
 1057  0
                 return ((BigDecimal) valueObject).floatValue();
 1058  
             }
 1059  
             else
 1060  
             {
 1061  0
                 return Integer.valueOf(asString()).floatValue();
 1062  
             }
 1063  
         }
 1064  0
         catch (Exception e)
 1065  
         {
 1066  0
             throw new DataSetException("Bad conversion: " + e.toString());
 1067  
         }
 1068  
     }
 1069  
 
 1070  
     /**
 1071  
      * Get the value as a Float Obj
 1072  
      *
 1073  
      * @return a Float
 1074  
      *
 1075  
      * @exception DataSetException
 1076  
      */
 1077  
     public Float asFloatObj()
 1078  
             throws DataSetException
 1079  
     {
 1080  
         try
 1081  
         {
 1082  0
             if (isNull())
 1083  
             {
 1084  0
                 return null;
 1085  
             }
 1086  0
             else if (isFloat())
 1087  
             {
 1088  0
                 return ((Float) valueObject);
 1089  
             }
 1090  0
             else if (isString() || isDouble() || isBigDecimal() || isInt() || 
 1091  
                      isLong() || isShort() || isByte())
 1092  
             {
 1093  0
                 return new Float(asString());
 1094  
             }
 1095  
             else
 1096  
             {
 1097  0
                 throw new DataSetException("Invalid type for Float");
 1098  
             }
 1099  
         }
 1100  0
         catch (Exception e)
 1101  
         {
 1102  0
             throw new DataSetException("Illegal conversion: " + e.toString());
 1103  
         }
 1104  
     }
 1105  
 
 1106  
     /**
 1107  
      * Get the value as a asTime
 1108  
      *
 1109  
      * @return a Time
 1110  
      *
 1111  
      * @exception DataSetException
 1112  
      */
 1113  
     public Time asTime()
 1114  
             throws DataSetException
 1115  
     {
 1116  
         try
 1117  
         {
 1118  0
             if (isNull())
 1119  
             {
 1120  0
                 return null;
 1121  
             }
 1122  0
             else if (isTime())
 1123  
             {
 1124  0
                 return (Time) valueObject;
 1125  
             }
 1126  
 
 1127  0
             Calendar cal = Calendar.getInstance();
 1128  
 
 1129  0
             if (isTimestamp())
 1130  
             {
 1131  0
                 cal.setTime((Timestamp) valueObject);
 1132  
 
 1133  0
                 return new Time(cal.getTime().getTime());
 1134  
             }
 1135  0
             else if (isUtilDate())
 1136  
             {
 1137  0
                 cal.setTime((java.util.Date) valueObject);
 1138  
 
 1139  0
                 return new Time(cal.getTime().getTime());
 1140  
             }
 1141  0
             else if (isString())
 1142  
             {
 1143  0
                 return Time.valueOf((String) valueObject);
 1144  
             }
 1145  
             else
 1146  
             {
 1147  0
                 return Time.valueOf(asString());
 1148  
             }
 1149  
         }
 1150  0
         catch (IllegalArgumentException a)
 1151  
         {
 1152  0
             throw new DataSetException("Bad date value - " + 
 1153  
                     "Java Time Objects cannot be earlier than 1/1/70");
 1154  
         }
 1155  0
         catch (Exception b)
 1156  
         {
 1157  0
             throw new DataSetException("Bad conversion: " + b.toString());
 1158  
         }
 1159  
     }
 1160  
 
 1161  
     /**
 1162  
      * Get the value as a asTimestamp
 1163  
      *
 1164  
      * @return a Timestamp
 1165  
      *
 1166  
      * @exception DataSetException
 1167  
      */
 1168  
     public Timestamp asTimestamp()
 1169  
             throws DataSetException
 1170  
     {
 1171  
         try
 1172  
         {
 1173  0
             if (isNull())
 1174  
             {
 1175  0
                 return null;
 1176  
             }
 1177  0
             else if (isTimestamp())
 1178  
             {
 1179  0
                 return (Timestamp) valueObject;
 1180  
             }
 1181  
 
 1182  0
             if (isTime())
 1183  
             {
 1184  0
                 Calendar cal = Calendar.getInstance();
 1185  0
                 cal.setTime((Time) valueObject);
 1186  
 
 1187  0
                 return new Timestamp(cal.getTime().getTime());
 1188  
             }
 1189  0
             else if (isUtilDate())
 1190  
             {
 1191  0
                 return new Timestamp(((java.util.Date) valueObject).getTime());
 1192  
             }
 1193  0
             else if (isString())
 1194  
             {
 1195  0
                 return Timestamp.valueOf((String) valueObject);
 1196  
             }
 1197  
             else
 1198  
             {
 1199  0
                 return Timestamp.valueOf(asString());
 1200  
             }
 1201  
         }
 1202  0
         catch (IllegalArgumentException a)
 1203  
         {
 1204  0
             throw new DataSetException("Bad date value - " + 
 1205  
                        "Java Timestamp Objects cannot be earlier than 1/1/70");
 1206  
         }
 1207  0
         catch (Exception b)
 1208  
         {
 1209  0
             throw new DataSetException("Bad conversion: " + b.toString());
 1210  
         }
 1211  
     }
 1212  
 
 1213  
     /**
 1214  
      * Get the value as a asDate
 1215  
      *
 1216  
      * @return a java.sql.Date
 1217  
      *
 1218  
      * @exception DataSetException
 1219  
      */
 1220  
     public java.sql.Date asDate()
 1221  
             throws DataSetException
 1222  
     {
 1223  
         try
 1224  
         {
 1225  0
             if (isNull())
 1226  
             {
 1227  0
                 return null;
 1228  
             }
 1229  0
             else if (isDate())
 1230  
             {
 1231  0
                 return (java.sql.Date) valueObject;
 1232  
             }
 1233  
 
 1234  0
             Calendar cal = Calendar.getInstance();
 1235  
 
 1236  0
             if (isTimestamp())
 1237  
             {
 1238  0
                 Timestamp ts = (Timestamp) valueObject;
 1239  0
                 long date = ts.getTime();
 1240  0
                 int nanos = ts.getNanos();
 1241  
 
 1242  0
                 return new java.sql.Date(date + (nanos / 1000000));
 1243  
             }
 1244  0
             else if (isTime())
 1245  
             {
 1246  0
                 cal.setTime((Time) valueObject);
 1247  
 
 1248  0
                 return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
 1249  
                                             (cal.get(Calendar.MONTH) + 1) + "-"
 1250  
                                             + cal.get(Calendar.DAY_OF_MONTH));
 1251  
             }
 1252  0
             else if (isUtilDate())
 1253  
             {
 1254  0
                 cal.setTime((java.util.Date) valueObject);
 1255  
 
 1256  0
                 return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
 1257  
                                             (cal.get(Calendar.MONTH) + 1) + "-"
 1258  
                                             + cal.get(Calendar.DAY_OF_MONTH));
 1259  
             }
 1260  0
             else if (isString())
 1261  
             {
 1262  0
                 return java.sql.Date.valueOf((String) valueObject);
 1263  
             }
 1264  
             else
 1265  
             {
 1266  0
                 return java.sql.Date.valueOf(asString());
 1267  
             }
 1268  
         }
 1269  0
         catch (IllegalArgumentException a)
 1270  
         {
 1271  0
             throw new DataSetException("Bad date value - " + 
 1272  
                     "Java Timestamp Objects cannot be earlier than 1/1/70");
 1273  
         }
 1274  0
         catch (Exception b)
 1275  
         {
 1276  0
             throw new DataSetException("Bad conversion: " + b.toString());
 1277  
         }
 1278  
     }
 1279  
 
 1280  
     /**
 1281  
      * Get the value as a asUtilDate
 1282  
      *
 1283  
      * @return a java.util.Date
 1284  
      *
 1285  
      * @exception DataSetException
 1286  
      */
 1287  
     public java.util.Date asUtilDate()
 1288  
             throws DataSetException
 1289  
     {
 1290  
         try
 1291  
         {
 1292  0
             if (isNull())
 1293  
             {
 1294  0
                 return null;
 1295  
             }
 1296  0
             else if (isUtilDate())
 1297  
             {
 1298  0
                 return (java.util.Date) valueObject;
 1299  
             }
 1300  
 
 1301  0
             Calendar cal = Calendar.getInstance();
 1302  
 
 1303  0
             if (isTimestamp())
 1304  
             {
 1305  0
                 Timestamp ts = (Timestamp) valueObject;
 1306  0
                 long date = ts.getTime();
 1307  0
                 int nanos = ts.getNanos();
 1308  
 
 1309  0
                 return new java.util.Date(date + (nanos / 1000000));
 1310  
             }
 1311  0
             else if (isTime())
 1312  
             {
 1313  0
                 cal.setTime((Time) valueObject);
 1314  
 
 1315  0
                 return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
 1316  
                                             (cal.get(Calendar.MONTH) + 1) + "-"
 1317  
                                             + cal.get(Calendar.DAY_OF_MONTH));
 1318  
             }
 1319  0
             else if (isUtilDate())
 1320  
             {
 1321  0
                 cal.setTime((java.util.Date) valueObject);
 1322  
 
 1323  0
                 return java.sql.Date.valueOf(cal.get(Calendar.YEAR) + "-" + 
 1324  
                                             (cal.get(Calendar.MONTH) + 1) + "-"
 1325  
                                             + cal.get(Calendar.DAY_OF_MONTH));
 1326  
             }
 1327  
             else
 1328  
             {
 1329  0
                 return null;
 1330  
             }
 1331  
         }
 1332  0
         catch (IllegalArgumentException a)
 1333  
         {
 1334  0
             throw new DataSetException("Bad date value - " + 
 1335  
                   "Java java.util.Date Objects cannot be earlier than 1/1/70");
 1336  
         }
 1337  0
         catch (Exception b)
 1338  
         {
 1339  0
             throw new DataSetException("Bad conversion: " + b.toString());
 1340  
         }
 1341  
     }
 1342  
 
 1343  
     /**
 1344  
      * Is the value a isBigDecimal
 1345  
      *
 1346  
      * @return true if BigDecimal
 1347  
      */
 1348  
     public boolean isBigDecimal()
 1349  
     {
 1350  0
         return valueObject instanceof BigDecimal;
 1351  
     }
 1352  
 
 1353  
     /**
 1354  
      * Is the value a isByte
 1355  
      *
 1356  
      * @return true if is Byte
 1357  
      */
 1358  
     public boolean isByte()
 1359  
     {
 1360  0
         return valueObject instanceof Byte;
 1361  
     }
 1362  
 
 1363  
     /**
 1364  
      * Is the value a isBytes
 1365  
      *
 1366  
      * @return true if is byte[]
 1367  
      */
 1368  
     public boolean isBytes()
 1369  
     {
 1370  0
         return valueObject instanceof byte [];
 1371  
     }
 1372  
 
 1373  
     /**
 1374  
      * Is the value a isDate
 1375  
      *
 1376  
      * @return true if is java.sql.Date
 1377  
      */
 1378  
     public boolean isDate()
 1379  
     {
 1380  0
         return valueObject instanceof java.sql.Date;
 1381  
     }
 1382  
 
 1383  
     /**
 1384  
      * Is the value a isShort
 1385  
      *
 1386  
      * @return true if is Short
 1387  
      */
 1388  
     public boolean isShort()
 1389  
     {
 1390  0
         return valueObject instanceof Short;
 1391  
     }
 1392  
 
 1393  
     /**
 1394  
      * Is the value a isInt
 1395  
      *
 1396  
      * @return true if is Integer
 1397  
      */
 1398  
     public boolean isInt()
 1399  
     {
 1400  0
         return valueObject instanceof Integer;
 1401  
     }
 1402  
 
 1403  
     /**
 1404  
      * Is the value a isLong
 1405  
      *
 1406  
      * @return true if is Long
 1407  
      */
 1408  
     public boolean isLong()
 1409  
     {
 1410  0
         return valueObject instanceof Long;
 1411  
     }
 1412  
 
 1413  
     /**
 1414  
      * Is the value a isDouble
 1415  
      *
 1416  
      * @return true if is Double
 1417  
      */
 1418  
     public boolean isDouble()
 1419  
     {
 1420  0
         return valueObject instanceof Double;
 1421  
     }
 1422  
 
 1423  
     /**
 1424  
      * Is the value a isFloat
 1425  
      *
 1426  
      * @return true if is Float
 1427  
      */
 1428  
     public boolean isFloat()
 1429  
     {
 1430  0
         return valueObject instanceof Float;
 1431  
     }
 1432  
 
 1433  
     /**
 1434  
      * Is the value a isBoolean
 1435  
      *
 1436  
      * @return true if is Boolean
 1437  
      */
 1438  
     public boolean isBoolean()
 1439  
     {
 1440  0
         return valueObject instanceof Boolean;
 1441  
     }
 1442  
 
 1443  
     /**
 1444  
      * Is the value a isNull
 1445  
      *
 1446  
      * @return true if is null
 1447  
      */
 1448  
     public boolean isNull()
 1449  
     {
 1450  0
         return valueObject == null;
 1451  
     }
 1452  
 
 1453  
     /**
 1454  
      * Is the value a isString
 1455  
      *
 1456  
      * @return true if is String
 1457  
      */
 1458  
     public boolean isString()
 1459  
     {
 1460  0
         return valueObject instanceof String;
 1461  
     }
 1462  
 
 1463  
     /**
 1464  
      * Is the value a isTime
 1465  
      *
 1466  
      * @return true if is java.sql.Time
 1467  
      */
 1468  
     public boolean isTime()
 1469  
     {
 1470  0
         return valueObject instanceof java.sql.Time;
 1471  
     }
 1472  
 
 1473  
     /**
 1474  
      * Is the value a isTimestamp
 1475  
      *
 1476  
      * @return true if is java.sql.Timestamp
 1477  
      */
 1478  
     public boolean isTimestamp()
 1479  
     {
 1480  0
         return valueObject instanceof java.sql.Timestamp;
 1481  
     }
 1482  
 
 1483  
     /**
 1484  
      * Is the value a isUtilDate
 1485  
      *
 1486  
      * @return true if is java.util.Date
 1487  
      */
 1488  
     public boolean isUtilDate()
 1489  
     {
 1490  0
         return valueObject instanceof java.util.Date;
 1491  
     }
 1492  
 
 1493  
     /**
 1494  
      * Return the type of this value
 1495  
      *
 1496  
      * @return the type of this value
 1497  
      */
 1498  
     public int type()
 1499  
     {
 1500  0
         return this.type;
 1501  
     }
 1502  
 
 1503  
     /**
 1504  
      * Gets the columnNumber which this value represents.
 1505  
      *
 1506  
      * @return an int
 1507  
      */
 1508  
     int columnNumber()
 1509  
     {
 1510  0
         return this.columnNumber;
 1511  
     }
 1512  
 
 1513  
     /**
 1514  
      * DOCUMENT ME!
 1515  
      *
 1516  
      * @param value TODO: DOCUMENT ME!
 1517  
      *
 1518  
      * @return true if (true || t | yes | y | 1)
 1519  
      */
 1520  
     private boolean isTrue(String value)
 1521  
     {
 1522  0
         return (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("t") 
 1523  
                 || value.equalsIgnoreCase("yes")
 1524  
         || value.equalsIgnoreCase("y") || value.equals("1"));
 1525  
     }
 1526  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.