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 getResult(int type, Object object) throws DException { 19 if (object == null) { 20 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.DOUBLE); 21 } 22 if (type <= 15) { 23 29 if(object.toString().startsWith("-")) { 30 throw new DException("DSE419", new Object [] {"SQRT"}); 31 } 32 return sqrt( ( (Number ) object).doubleValue()); 33 } 34 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "SQRT"}); 35 47 } 48 49 private Object sqrt(double value) throws DException { 50 55 return new FieldLiteral(new Double (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 getType() throws DException { 64 return (String ) _SNONRESERVEDWORD1364442551.run(null); 65 } 66 67 public String toString() { 68 StringBuffer sb = new StringBuffer (); 69 sb.append(" "); 70 sb.append(_SNONRESERVEDWORD1364442551); 71 sb.append(_parennumericvalueexpression0); 72 return sb.toString(); 73 } 74 75 public Object clone() throws CloneNotSupportedException { 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 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 [] {StaticClass.getDataTypeName(type), "SQRT"}); 109 } 110 public int getColumnSize(Object object) throws DException { 111 return Datatypes.DOUBLESIZE; 112 } 113 114 115 } 116 | Popular Tags |