| 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 modulusexpression extends AbstractNumericValueFunction { 14 15 public parencommanumericvalueexpression _parencommanumericvalueexpression0; 16 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442551; 17 18 public Object run(Object object) throws com.daffodilwoods.database.resource.DException { 19 FieldBase[] res = GeneralPurposeStaticClass.changeIntoFieldBase( (Object []) _parencommanumericvalueexpression0.run(object)); 20 FieldBase result1 = res[0]; 21 FieldBase result2 = res[1]; 22 if (result1.isNull() || result2.isNull()) { 23 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, DOUBLE); 24 } 25 if (result2.getObject().hashCode() == 0) { 26 throw new DException("DSE334", null); 27 } 28 return getResult(getDataType(result1), getDataType(result2), 29 result1.getObject(), result2.getObject()); 30 } 31 32 public ParameterInfo[] getParameterInfo() throws DException { 33 ParameterInfo[] paramInfo = super.getParameterInfo(); 34 for (int i = 0; i < paramInfo.length; i++) { 35 if (paramInfo[i].getQuestionMark()) { 36 paramInfo[i].setDataType(Datatypes.DOUBLE); 37 paramInfo[i].setName("MODULUS Arg"); 38 } 39 } 40 return paramInfo; 41 } 42 43 public ColumnDetails[] getExistingColumnDetails() throws DException { 44 return columnDetails; 45 } 46 47 private Object getResult(int type1, int type2, Object result1, Object result2) throws DException { 48 if(result2 instanceof Number ) { 49 if ( ( (Number ) result2).intValue() == 0) { 50 throw new DException("DSE334", null); 51 } 52 } 53 switch(type1){ 54 case BYTE : case TINYINT : 55 case SHORT : case SMALLINT : 56 case INTEGER : case INT : 57 case LONG : case BIGINT : 58 switch(type2) { 59 case BYTE : case TINYINT : 60 case SHORT : case SMALLINT : 61 case INTEGER : case INT : 62 case LONG : case BIGINT : 63 long operand1 = ((Number )result1).longValue(); 64 long operand2 = ((Number )result2).longValue(); 65 return new FieldLiteral(new Double (operand1 % operand2),Datatype.DOUBLE); 66 case REAL : case DOUBLE : 67 case FLOAT : case DOUBLEPRECISION : 68 case DEC : 69 case DECIMAL : case NUMERIC : 70 long operand01 = ((Number )result1).longValue(); 71 double operand02 = ((Number )result2).doubleValue(); 72 return new FieldLiteral(new Double (operand01 % operand02),Datatype.DOUBLE); 73 default: 74 throw new DException("DSE4108",new Object []{StaticClass.getDataTypeName(type2),"MOD"}); 75 } 76 case REAL : 77 case DOUBLE : case FLOAT : case DOUBLEPRECISION : 78 case DEC : case DECIMAL : case NUMERIC : 79 switch(type2){ 80 case BYTE : case TINYINT : 81 case SHORT : case SMALLINT : 82 case INTEGER : case INT : 83 case LONG : case BIGINT : 84 case REAL : case DOUBLE : 85 case FLOAT : case DOUBLEPRECISION : 86 case DEC : 87 case DECIMAL : case NUMERIC : 88 double operand1 = ((Number )result1).doubleValue(); 89 double operand2 = ((Number )result2).doubleValue(); 90 return new FieldLiteral(new Double (operand1 % operand2),Datatype.DOUBLE); 91 default: 92 throw new DException("DSE4108",new Object []{StaticClass.getDataTypeName(type2),"MOD"}); 93 } 94 default: 95 throw new DException("DSE4108",new Object []{StaticClass.getDataTypeName(type1),"MOD"}); 96 } 97 } 98 99 293 294 public AbstractRowValueExpression[] getChilds() { 295 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {_parencommanumericvalueexpression0}; 296 return childs; 297 } 298 299 public String getType() throws DException { 300 return (String ) _SNONRESERVEDWORD1364442551.run(null); 301 } 302 303 public String toString() { 304 StringBuffer sb = new StringBuffer (); 305 sb.append(" "); 306 sb.append(_SNONRESERVEDWORD1364442551); 307 sb.append(_parencommanumericvalueexpression0); 308 return sb.toString(); 309 } 310 311 public Object clone() throws CloneNotSupportedException { 312 modulusexpression tempClass = new modulusexpression(); 313 tempClass._parencommanumericvalueexpression0 = (parencommanumericvalueexpression) _parencommanumericvalueexpression0.clone(); 314 tempClass._SNONRESERVEDWORD1364442551 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442551.clone(); 315 return tempClass; 316 } 317 318 public ByteComparison getByteComparison(Object object) throws DException { 319 ByteComparison byteComparison = new ByteComparison(false, new int[] {DOUBLE}); 320 byteComparison.setSize(getColumnSize(object)); 321 return byteComparison; 322 } 323 324 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 325 _Reference[] ref = super.checkSemantic(parent); 326 if(ref!=null) { 327 return ref; 328 } 329 int type[] = _parencommanumericvalueexpression0.getByteComparison(parent).getDataTypes(); 330 if (type[0] == -1 || type[0] <= 15) { 331 if (type[1] == -1 || type[1] <= 15) { 332 return ref; 333 } 334 throw new DException("DSE4108", 335 new Object [] {StaticClass.getDataTypeName(type[1]), 336 "MOD"}); 337 } 338 throw new DException("DSE4108", 339 new Object [] {StaticClass.getDataTypeName(type[0]), 340 "MOD"}); 341 342 } 343 public int getColumnSize(Object object) throws DException { 344 return Datatypes.DOUBLESIZE; 345 } 346 } 347 | Popular Tags |