KickJava   Java API By Example, From Geeks To Geeks.

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


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 ceilingfunction 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
22       if (object == null) {
23          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.INTEGER);
24       }
25       switch (type) {
26          case BYTE:
27          case TINYINT:
28          case SHORT:
29          case SMALLINT:
30          case INTEGER:
31          case INT:
32          case REAL:
33          case DOUBLE:
34          case FLOAT:
35          case DOUBLEPRECISION:
36             Number JavaDoc operand = (Number JavaDoc) object;
37             return new FieldLiteral(new Integer JavaDoc(new Double JavaDoc(Math.ceil(operand.doubleValue())).intValue()), Datatype.INTEGER);
38          case LONG:
39          case BIGINT:
40             return new FieldLiteral(new Long JavaDoc(new Double JavaDoc(Math.ceil( ( (Number JavaDoc) object).doubleValue())).longValue()), Datatype.LONG);
41          case BIGDECIMAL:
42          case DEC:
43          case DECIMAL:
44          case NUMERIC:
45             return new FieldLiteral(new BigDecimal(Math.ceil( ( (Number JavaDoc) object).doubleValue())), Datatype.BIGDECIMAL);
46
47          default:
48             throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "CEILING"});
49       }
50
51    }
52
53    /* protected Object getResult(int type,Object object) throws DException {
54      if(object == null)
55        return new FieldLiteral(FieldUtility.NULLBUFFERRANGE,Datatype.INTEGER);
56       switch(type){
57         case BYTE : case TINYINT :
58             return new FieldLiteral(new Integer( new Double(Math.ceil(((Byte)object).doubleValue())).intValue() ),Datatype.INTEGER);
59           case INTEGER : case INT :
60             Integer integer = (Integer)object;
61             return new FieldLiteral(new Integer( new Double(Math.ceil(integer.doubleValue())).intValue() ),Datatype.INTEGER);
62          case REAL :
63             Float floatV = (Float)object;
64             return new FieldLiteral(new Integer( new Double(Math.ceil(floatV.doubleValue())).intValue() ),Datatype.INTEGER);
65           case DOUBLE : case FLOAT : case DOUBLEPRECISION :
66             Double doubleV = (Double)object;
67             return new FieldLiteral(new Integer( new Double(Math.ceil(doubleV.doubleValue())).intValue() ),Datatype.INTEGER);
68           case LONG : case BIGINT :
69             Long longV = (Long)object;
70             return new FieldLiteral( new Long( new Double(Math.ceil(longV.doubleValue())).longValue() ),Datatype.LONG);
71           case SHORT : case SMALLINT :
72             Short shortV = (Short)object;
73             return new FieldLiteral(new Short( new Double(Math.ceil(shortV.doubleValue())).shortValue() ),Datatype.SHORT);
74           case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
75             BigDecimal bigDecimal = (BigDecimal)object;
76             return new FieldLiteral(new BigDecimal( Math.ceil(bigDecimal.doubleValue())),Datatype.BIGDECIMAL);
77          default :
78             throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type), "CEILING"});
79       }
80     } */

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

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