KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression;
2
3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
4 import com.daffodilwoods.daffodildb.server.serversystem.*;
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
7 import com.daffodilwoods.daffodildb.server.sql99.token.*;
8 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
9 import com.daffodilwoods.daffodildb.utils.*;
10 import com.daffodilwoods.daffodildb.utils.field.*;
11 import com.daffodilwoods.database.resource.*;
12
13 public class sqrtfunction extends AbstractNumericValueFunction {
14
15    public parennumericvalueexpression _parennumericvalueexpression0;
16    public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442551;
17
18    protected Object JavaDoc getResult(int type, Object JavaDoc object) throws DException {
19       if (object == null) {
20          return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.DOUBLE);
21       }
22       if (type <= 15) {
23         /**
24          * Any Number started with minus not supported because
25          * result of minus value is not a valid number.Output is
26          * NaN. Handling has been done to resolve the bug 12208
27          * ---Sube Singh
28          */

29          if(object.toString().startsWith("-")) {
30            throw new DException("DSE419", new Object JavaDoc[] {"SQRT"});
31          }
32          return sqrt( ( (Number JavaDoc) object).doubleValue());
33       }
34       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "SQRT"});
35       /* switch(type){
36           case BYTE : case TINYINT :
37           case INTEGER : case INT :
38           case REAL :
39           case DOUBLE : case FLOAT : case DOUBLEPRECISION :
40           case LONG : case BIGINT :
41           case SHORT : case SMALLINT :
42           case BIGDECIMAL : case DEC : case DECIMAL : case NUMERIC :
43             return sqrt(((Number)object).doubleValue());
44           default :
45              throw new DException("DSE4108",new Object[]{StaticClass.getDataTypeName(type),"SQRT"});
46        }*/

47    }
48
49    private Object JavaDoc sqrt(double value) throws DException {
50      /**
51       * Commented because checking performed below has been
52       * completed before the call to the method. This has been done
53       * in case of bug 12208
54       */

55       return new FieldLiteral(new Double JavaDoc(Math.sqrt(value)), Datatype.DOUBLE);
56    }
57
58    public AbstractRowValueExpression[] getChilds() {
59       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parennumericvalueexpression0};
60       return childs;
61    }
62
63    public String JavaDoc getType() throws DException {
64       return (String JavaDoc) _SNONRESERVEDWORD1364442551.run(null);
65    }
66
67    public String JavaDoc toString() {
68       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
69       sb.append(" ");
70       sb.append(_SNONRESERVEDWORD1364442551);
71       sb.append(_parennumericvalueexpression0);
72       return sb.toString();
73    }
74
75    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
76       sqrtfunction tempClass = new sqrtfunction();
77       tempClass._parennumericvalueexpression0 = (parennumericvalueexpression) _parennumericvalueexpression0.clone();
78       tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone();
79       return tempClass;
80    }
81
82    public ParameterInfo[] getParameterInfo() throws DException {
83      ParameterInfo[] paramInfo = super.getParameterInfo();
84     for (int i = 0; i < paramInfo.length; i++) {
85       if (paramInfo[i].getQuestionMark()) {
86         paramInfo[i].setDataType(Datatypes.DOUBLE);
87         paramInfo[i].setName("SQRT Arg");
88       }
89     }
90      return paramInfo;
91    }
92
93    public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
94    ByteComparison byteComparison = new ByteComparison(false, new int[] {DOUBLE});
95    byteComparison.setSize(getColumnSize(object));
96    return byteComparison;
97    }
98
99    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
100       _Reference[] ref = super.checkSemantic(parent);
101       if(ref!=null) {
102         return ref;
103        }
104       int type = _parennumericvalueexpression0.getByteComparison(parent).getDataTypes()[0];
105       if (type == -1 || type <= 15) {
106          return ref;
107       }
108       throw new DException("DSE4108", new Object JavaDoc[] {StaticClass.getDataTypeName(type), "SQRT"});
109    }
110  public int getColumnSize(Object JavaDoc object) throws DException {
111           return Datatypes.DOUBLESIZE;
112     }
113
114
115 }
116
Popular Tags