KickJava   Java API By Example, From Geeks To Geeks.

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


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 radiansfunction 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       /*dst*/
22       if (object == null) {
23          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.DOUBLE);
24       }
25       switch (type) {
26          case BYTE:
27          case TINYINT:
28             return new FieldLiteral(new Double JavaDoc(Math.toRadians( ( (Byte JavaDoc) object).doubleValue())), Datatype.DOUBLE);
29          case INTEGER:
30          case INT:
31             Integer JavaDoc integer = (Integer JavaDoc) object;
32             return new FieldLiteral(new Double JavaDoc(Math.toRadians(integer.doubleValue())), Datatype.DOUBLE);
33          case REAL:
34             Float JavaDoc floatV = (Float JavaDoc) object;
35             return new FieldLiteral(new Double JavaDoc(Math.toRadians(floatV.doubleValue())), Datatype.DOUBLE);
36          case DOUBLE:
37          case FLOAT:
38          case DOUBLEPRECISION:
39             Double JavaDoc doubleV = (Double JavaDoc) object;
40             return new FieldLiteral(new Double JavaDoc(Math.toRadians(doubleV.doubleValue())), Datatype.DOUBLE);
41          case LONG:
42          case BIGINT:
43             Long JavaDoc longV = (Long JavaDoc) object;
44             return new FieldLiteral(new Double JavaDoc(Math.toRadians(longV.doubleValue())), Datatype.DOUBLE);
45          case SHORT:
46          case SMALLINT:
47             Short JavaDoc shortV = (Short JavaDoc) object;
48             return new FieldLiteral(new Double JavaDoc(Math.toRadians(shortV.doubleValue())), Datatype.DOUBLE);
49          case BIGDECIMAL:
50          case DEC:
51          case DECIMAL:
52          case NUMERIC:
53             BigDecimal bigDecimal = (BigDecimal) object;
54             return new FieldLiteral(new BigDecimal(Math.toRadians(bigDecimal.doubleValue())), Datatype.DOUBLE);
55          default:
56             throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "RADIANS"});
57       }
58       /*dend*/
59    }
60
61    public AbstractRowValueExpression[] getChilds() {
62       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parennumericvalueexpression0};
63       return childs;
64    }
65
66    public String JavaDoc getType() throws DException {
67       return (String JavaDoc) _SNONRESERVEDWORD1364442551.run(null);
68    }
69
70    public String JavaDoc toString() {
71       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
72       sb.append(" ");
73       sb.append(_SNONRESERVEDWORD1364442551);
74       sb.append(_parennumericvalueexpression0);
75       return sb.toString();
76    }
77
78    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
79       radiansfunction tempClass = new radiansfunction();
80       tempClass._parennumericvalueexpression0 = (parennumericvalueexpression) _parennumericvalueexpression0.clone();
81       tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone();
82       return tempClass;
83    }
84
85    public ParameterInfo[] getParameterInfo() throws DException {
86      ParameterInfo[] paramInfo = super.getParameterInfo();
87      for (int i = 0; i < paramInfo.length; i++) {
88        if (paramInfo[i].getQuestionMark()) {
89          paramInfo[i].setDataType(Datatypes.BIGDECIMAL);
90          paramInfo[i].setName("RADIANS Arg");
91        }
92      }
93      return paramInfo;
94    }
95
96    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
97      ByteComparison byteComparison = new ByteComparison(false, new int[] {DOUBLE});
98      byteComparison.setSize(getColumnSize(object));
99      return byteComparison;
100    }
101
102   /* private int getDatatype(Object object) throws DException {
103      int type = getDataTypeForByte(_parennumericvalueexpression0.getByteComparison(object));
104      switch(type){
105        case BYTE : case TINYINT :
106        case INTEGER : case INT :
107        case REAL :
108        case DOUBLE : case FLOAT : case DOUBLEPRECISION :
109        case CHARACTER :case VARCHAR: case CHAR: case CHARACTERVARYING:
110          return INTEGER;
111        case LONG : case BIGINT :
112          return LONG;
113        case SHORT : case SMALLINT :
114          return SHORT;
115        case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
116          return BIGDECIMAL;
117         default :
118            throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type), "CEILING"});
119      }
120     }*/

121
122    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
123       _Reference[] ref = super.checkSemantic(parent);
124       if(ref!=null) {
125         return ref;
126        }
127       int type = _parennumericvalueexpression0.getByteComparison(parent).getDataTypes()[0];
128       if (type == -1 || type <= 15) {
129          return ref;
130       }
131       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "RADIANS"});
132    }
133   public int getColumnSize(Object JavaDoc object) throws DException {
134           return Datatypes.DOUBLESIZE;
135        }
136
137 }
138
Popular Tags