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 getResult(int type, Object 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 operand = (Number ) object; 36 return new FieldLiteral(new Integer ( (new Double ( (Math.floor(operand.doubleValue())))).intValue()), Datatype.INTEGER); 37 case LONG: 38 case BIGINT: 39 return new FieldLiteral(new Long (new Double (Math.floor( ( (Number ) 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 ) object).doubleValue())), Datatype.BIGDECIMAL); 45 46 default: 47 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "FLOOR"}); 48 49 } 50 } 51 52 89 90 public AbstractRowValueExpression[] getChilds() { 91 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parennumericvalueexpression0}; 92 return childs; 93 } 94 95 public String getType() throws DException { 96 return (String ) _SNONRESERVEDWORD1364442551.run(null); 97 } 98 99 public String toString() { 100 StringBuffer sb = new StringBuffer (); 101 sb.append(" "); 102 sb.append(_SNONRESERVEDWORD1364442551); 103 sb.append(_parennumericvalueexpression0); 104 return sb.toString(); 105 } 106 107 public Object clone() throws CloneNotSupportedException { 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 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 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 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 [] {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 [] {StaticClass.getDataTypeName(type), "FLOOR"}); 173 } 174 175 public int getColumnSize(Object 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 |