KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > numericvalueexpression > floorfunction


1 package com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression;
2
3 import java.math.*;
4
5 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
9 import com.daffodilwoods.daffodildb.server.sql99.token.*;
10 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
11 import com.daffodilwoods.daffodildb.utils.*;
12 import com.daffodilwoods.daffodildb.utils.field.*;
13 import com.daffodilwoods.database.resource.*;
14
15 public class floorfunction extends AbstractNumericValueFunction {
16
17    public parennumericvalueexpression _parennumericvalueexpression0;
18    public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442551;
19
20    protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
21       if (object == null) {
22          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.INTEGER);
23       }
24       switch (type) {
25          case BYTE:
26          case TINYINT:
27          case SHORT:
28          case SMALLINT:
29          case INTEGER:
30          case INT:
31          case REAL:
32          case DOUBLE:
33          case FLOAT:
34          case DOUBLEPRECISION:
35             Number JavaDoc operand = (Number JavaDoc) object;
36             return new FieldLiteral(new Integer JavaDoc( (new Double JavaDoc( (Math.floor(operand.doubleValue())))).intValue()), Datatype.INTEGER);
37          case LONG:
38          case BIGINT:
39             return new FieldLiteral(new Long JavaDoc(new Double JavaDoc(Math.floor( ( (Number JavaDoc) object).doubleValue())).longValue()), Datatype.LONG);
40          case BIGDECIMAL:
41          case DEC:
42          case DECIMAL:
43          case NUMERIC:
44             return new FieldLiteral(new BigDecimal(Math.floor( ( (Number JavaDoc) object).doubleValue())), Datatype.BIGDECIMAL);
45
46          default:
47             throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "FLOOR"});
48
49       }
50    }
51
52    /* protected Object getResult(int type,Object object) throws DException {
53      if(object == null)
54        return new FieldLiteral(FieldUtility.NULLBUFFERRANGE,Datatype.INTEGER);
55       switch(type){
56         case BYTE :
57         case TINYINT :
58             return new FieldLiteral(new Integer( new Double(Math.floor(((Byte)object).doubleValue())).intValue()),Datatype.INTEGER);
59         case INTEGER :
60         case INT :
61             Integer integer = (Integer)object;
62             return new FieldLiteral(new Integer( ( new Double((Math.floor(integer.doubleValue())))).intValue() ),Datatype.INTEGER);
63         case REAL :
64             Float floatV = (Float)object;
65             return new FieldLiteral(new Integer( ( new Double((Math.floor(floatV.doubleValue())))).intValue() ),Datatype.INTEGER);
66         case DOUBLE :
67         case FLOAT :
68         case DOUBLEPRECISION :
69             Double doubleV = (Double)object;
70             return new FieldLiteral(new Integer( ( new Double((Math.floor(doubleV.doubleValue())))).intValue() ),Datatype.INTEGER);
71         case LONG :
72         case BIGINT :
73             Long longV = (Long)object;
74             return new FieldLiteral(new Long( new Double( Math.floor(longV.doubleValue())).longValue() ),Datatype.LONG);
75         case SHORT :
76         case SMALLINT :
77             Short shortV = (Short)object;
78             return new FieldLiteral(new Short ( new Double( Math.floor(shortV.doubleValue())).shortValue() ),Datatype.SHORT);
79         case BIGDECIMAL :
80         case DEC :
81         case DECIMAL :
82         case NUMERIC :
83             BigDecimal bigDecimal = (BigDecimal)object;
84             return new FieldLiteral(new BigDecimal ( Math.floor(bigDecimal.doubleValue()) ),Datatype.BIGDECIMAL);
85          default :
86             throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type),"FLOOR"});
87       }
88       } */

89
90    public AbstractRowValueExpression[] getChilds() {
91       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parennumericvalueexpression0};
92       return childs;
93    }
94
95    public String JavaDoc getType() throws DException {
96       return (String JavaDoc) _SNONRESERVEDWORD1364442551.run(null);
97    }
98
99    public String JavaDoc toString() {
100       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
101       sb.append(" ");
102       sb.append(_SNONRESERVEDWORD1364442551);
103       sb.append(_parennumericvalueexpression0);
104       return sb.toString();
105    }
106
107    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
108       floorfunction tempClass = new floorfunction();
109       tempClass._parennumericvalueexpression0 = (parennumericvalueexpression) _parennumericvalueexpression0.clone();
110       tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone();
111       return tempClass;
112    }
113
114    public ParameterInfo[] getParameterInfo() throws DException {
115      ParameterInfo[] paramInfo = super.getParameterInfo();
116      for (int i = 0; i < paramInfo.length; i++) {
117        if (paramInfo[i].getQuestionMark()) {
118          paramInfo[i].setDataType(Datatypes.BIGDECIMAL);
119          paramInfo[i].setName("FLOOR Arg");
120        }
121      }
122      return paramInfo;
123    }
124
125    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
126    ByteComparison byteComparison = new ByteComparison(false, new int[] {getDatatype(object)});
127    byteComparison.setSize(getColumnSize(object));
128    return byteComparison;
129    }
130
131    private int getDatatype(Object JavaDoc object) throws DException {
132         int type = getDataTypeForByte(_parennumericvalueexpression0.getByteComparison(object));
133         switch (type) {
134           case BYTE:
135         case TINYINT:
136         case SHORT:
137         case SMALLINT:
138         case INTEGER:
139         case INT:
140         case REAL:
141         case DOUBLE:
142         case FLOAT:
143         case DOUBLEPRECISION:
144             return INTEGER;
145          case BIGINT:
146          case LONG:
147             return LONG;
148            /*In case of question mark I get data type -1
149              So to resolve the bug 11823 data type BigDecimal
150             is set. ---- Sube Singh
151             */

152            case -1 :
153            case BIGDECIMAL:
154            case DEC:
155            case DECIMAL:
156            case NUMERIC:
157               return BIGDECIMAL;
158            default:
159               throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "FLOOR"});
160         }
161      }
162
163    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
164       _Reference[] ref = super.checkSemantic(parent);
165       if(ref!=null) {
166         return ref;
167        }
168       int type = _parennumericvalueexpression0.getByteComparison(parent).getDataTypes()[0];
169       if (type == -1 || type <= 15) {
170          return ref;
171       }
172       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "FLOOR"});
173    }
174
175    public int getColumnSize(Object JavaDoc object) throws DException {
176      ColumnDetails[] columnDetails = getChildColumnDetails();
177      if(columnDetails[0].getType()!=TypeConstants.CONSTANT) {
178        int datatype = columnDetails[0].getDatatype();
179        switch (datatype) {
180          case BYTE:
181             case TINYINT:
182             case SHORT:
183             case SMALLINT:
184              return SHORTSIZE;
185             case INTEGER:
186             case INT:
187               return INTSIZE;
188             case REAL:
189               return FLOATSIZE;
190             case DOUBLE:
191             case FLOAT:
192             case DOUBLEPRECISION:
193              return DOUBLESIZE;
194             case LONG:
195             case BIGINT:
196               return LONGSIZE;
197               default :
198               if (columnDetails[0].getSize() != -5) {
199                 return columnDetails[0].getSize();
200               }
201
202        }
203      } else if(columnDetails[0].getQuestion()) {
204          return Datatypes.DOUBLESIZE;
205      } else {
206        FieldBase field = (FieldBase) _parennumericvalueexpression0.run(object);
207        field.setDatatype(columnDetails[0].getDatatype());
208        return field.getLength();
209      }
210      return -1;
211   }
212
213 }
214
Popular Tags