1 package com.daffodilwoods.daffodildb.utils.field; 2 3 import java.math.*; 4 5 6 import com.daffodilwoods.daffodildb.server.sql99.common.*; 7 import com.daffodilwoods.daffodildb.utils.*; 8 import com.daffodilwoods.database.resource.*; 9 10 public class FieldNumber extends FieldBase implements Datatypes,Comparable { 11 12 13 public FieldNumber(BufferRange bufferRange0,int datatype0) { 14 bufferRange = bufferRange0; 15 datatype = datatype0; 16 } 17 18 public FieldNumber(Object object0,int datatype0) { 19 object = object0; 20 datatype = datatype0; 21 } 22 23 public Object getObject() throws DException{ 24 if (bufferRange.getNull()) 25 return null; 26 if (object != null) 27 return object; 28 switch (datatype) { 29 case TINYINT: 30 case BYTE: 31 object = getByte(); 32 break; 33 case SHORT: 34 case SMALLINT: 35 object = getShort(); 36 break; 37 case INT: 38 case INTEGER: 39 object = getInt(); 40 break; 41 case BIGINT: 42 case LONG: 43 object = getLong(); 44 break; 45 case REAL: 46 object = getFloat(); 47 break; 48 case DOUBLE: 49 case DOUBLEPRECISION: 50 case FLOAT: 51 object = getDouble(); 52 case BIGDECIMAL: 53 case DEC: 54 case DECIMAL: 55 case NUMERIC: 56 object = getBigDecimal(); 57 break; 58 default: 59 throw new DException("DSE514", 60 new Object [] {StaticClass.getDataTypeName(datatype)}); 61 } 62 return object; 63 } 64 65 66 private Byte getByte(){ 67 return new Byte (bufferRange.getByte(0)); 68 } 69 70 private Short getShort(){ 71 short a= 0; 72 for(int i = 0 , j = 8 ; i < 2 ; i++ , j -= 8) 73 a += ( (short)bufferRange.getByte(i) & 0xFF) << j; 74 Short aa = new Short (a); 75 return aa; 76 } 77 78 private Integer getInt(){ 79 int a = 0; 80 for(int i = 0 , j = 24 ; i < 4; i++,j-=8) 81 a += ( (int)bufferRange.getByte(i) & 0xFF) << j; 82 Integer aa = new Integer (a); 83 return aa; 84 } 85 86 private Long getLong(){ 87 long a = 0; 88 for(int i = 0 , j = 56 ; i < 8 ; i++ , j -= 8) 89 a += ((long)bufferRange.getByte(i) & 0xFF) << j; 90 return new Long (a); 91 } 92 93 private Float getFloat(){ 94 int a = 0; 95 for(int i = 0 , j = 24; i < 4 ; i++ , j -= 8) 96 a += ( (int)bufferRange.getByte(i) & 0xFF) << j; 97 float f = Float.intBitsToFloat(a); 98 Float ff = new Float (f); 99 return ff; 100 } 101 102 private Double getDouble(){ 103 long a= 0; 104 for(int i = 0 , j = 56 ; i < 8; i++ , j -= 8) 105 a += ( (long)bufferRange.getByte(i) & 0xFF) << j; 106 double f=Double.longBitsToDouble(a); 107 Double d = new Double (f); 108 return d; 109 } 110 111 private BigDecimal getBigDecimal(){ 112 String ss1 = new String ( bufferRange.getFulBytes(),bufferRange.getOffSet(),bufferRange.getLength() ); 113 BigDecimal aa = new BigDecimal(ss1); 114 return aa; 115 } 116 117 public int compareTo(Object fieldBase){ 118 throw new java.lang.UnsupportedOperationException ("Method not yet implemented."); 119 } 120 121 122 } 123 | Popular Tags |