| 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 getResult(int type, Object 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 operand = (Number ) object; 37 return new FieldLiteral(new Integer (new Double (Math.ceil(operand.doubleValue())).intValue()), Datatype.INTEGER); 38 case LONG: 39 case BIGINT: 40 return new FieldLiteral(new Long (new Double (Math.ceil( ( (Number ) 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 ) object).doubleValue())), Datatype.BIGDECIMAL); 46 47 default: 48 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "CEILING"}); 49 } 50 51 } 52 53 81 82 public AbstractRowValueExpression[] getChilds() { 83 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parennumericvalueexpression0}; 84 return childs; 85 } 86 87 public String getType() throws DException { 88 return (String ) _SNONRESERVEDWORD1364442551.run(null); 89 } 90 91 public String toString() { 92 StringBuffer sb = new StringBuffer (); 93 sb.append(" "); 94 sb.append(_SNONRESERVEDWORD1364442551); 95 sb.append(_parennumericvalueexpression0); 96 return sb.toString(); 97 } 98 99 public Object clone() throws CloneNotSupportedException { 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 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 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 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 [] {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 [] {StaticClass.getDataTypeName(type), "CEILING"}); 166 } 167 168 public int getColumnSize(Object 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 |