1 package com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary; 2 import com.daffodilwoods.database.resource.*; 3 import com.daffodilwoods.daffodildb.server.sql99.token.*; 4 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference; 5 import com.daffodilwoods.daffodildb.server.serversystem._ServerSession; 6 import com.daffodilwoods.daffodildb.server.sql99.common.ColumnDetails; 7 import com.daffodilwoods.daffodildb.server.sql99.common.ParameterInfo; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.ByteComparison; 9 import com.daffodilwoods.daffodildb.server.sql99.expression.stringvalueexpression.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.*; 11 import com.daffodilwoods.daffodildb.utils.field.*; 12 import com.daffodilwoods.daffodildb.server.sql99.common.*; 13 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 14 import com.daffodilwoods.daffodildb.utils.*; 15 16 public class nullIffunction extends AbstractGeneralFunction implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter ,generalvaluespecification { 17 18 public Srightparen_1874859514 _Srightparen_18748595140 ; 19 public valueexpression _valueexpression1 ; 20 public Scomma94843605 _Scomma948436052 ; 21 public valueexpression _valueexpression3 ; 22 public Sleftparen653880241 _Sleftparen6538802414 ; 23 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442555 ; 24 25 private int resultType = -1; 26 private int type1 = -1; 27 private int type2 = -1; 28 29 43 44 public Object run(Object object) throws com.daffodilwoods.database.resource.DException { 45 if (resultType == -1) { 46 resultType = getAppropriateDatatype(object); 47 } 48 FieldBase result1 = (FieldBase) _valueexpression3.run(object); 49 if (result1.isNull()) { 50 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 51 } 52 FieldBase result2 = (FieldBase) _valueexpression1.run(object); 53 if (result2.isNull()) { 54 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 55 } 56 type1 =getDataType(result1); 57 type2 =getDataType(result1); 58 try { 59 Check.checkForDatatype(type1, type2); 60 } 61 catch (DException ex) { 62 if (ex.getDseCode().equalsIgnoreCase("DSE514") || 63 ex.getDseCode().equalsIgnoreCase("DSE6001")) { 64 throw new DException("DSE8100", new Object [] {StaticClass.getDataTypeName(type1), 65 StaticClass.getDataTypeName(type2)}); 66 } 67 throw ex; 68 } 69 return getResult(result1 ,result2); 70 } 71 72 public ColumnDetails[] getChildColumnDetails() throws DException { 73 ColumnDetails[] cd1 = _valueexpression3.getColumnDetails(); 74 ColumnDetails[] cd2 = _valueexpression1.getColumnDetails(); 75 return GeneralPurposeStaticClass.getCombinedCDArray(cd1, cd2); 76 } 77 78 79 public AbstractRowValueExpression[] getChilds() { 80 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_valueexpression3), (AbstractRowValueExpression) (_valueexpression1)}; 81 return childs; 82 } 83 84 85 86 public String toString() { 87 StringBuffer sb = new StringBuffer (); 88 sb.append(" "); 89 sb.append(_SNONRESERVEDWORD1364442555); 90 sb.append(" "); 91 sb.append(_Sleftparen6538802414); 92 sb.append(" "); 93 sb.append(_valueexpression3); 94 sb.append(" "); 95 sb.append(_Scomma948436052); 96 sb.append(" "); 97 sb.append(_valueexpression1); 98 sb.append(" "); 99 sb.append(_Srightparen_18748595140); 100 return sb.toString(); 101 } 102 103 public Object clone() throws CloneNotSupportedException { 104 nullIffunction tempClass = new nullIffunction(); 105 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) _Srightparen_18748595140.clone(); 106 tempClass._valueexpression1 = (valueexpression)_valueexpression1.clone(); 107 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 108 tempClass._valueexpression3 = (valueexpression) _valueexpression3.clone(); 109 tempClass._Sleftparen6538802414 = (Sleftparen653880241) _Sleftparen6538802414.clone(); 110 tempClass._SNONRESERVEDWORD1364442555 = (SNONRESERVEDWORD136444255) _SNONRESERVEDWORD1364442555.clone(); 111 return tempClass; 112 } 113 114 public ParameterInfo[] getParameterInfo() throws DException { 115 126 return new ParameterInfo[0]; 127 } 128 129 130 public ByteComparison getByteComparison(Object object) throws DException { 131 int dt = resultType == -1 ? getAppropriateDatatype(object) : resultType; 132 ByteComparison byteComparison = new ByteComparison(false, new int[] {dt}); 133 byteComparison.setSize(getColumnSize(object)); 134 return byteComparison; 135 } 136 137 138 private int getAppropriateDatatype(Object object) throws DException { 139 type1 = getDataTypeForByte(_valueexpression3.getByteComparison(object)); 140 type2 = getDataTypeForByte(_valueexpression1.getByteComparison(object)); 141 try { 142 Check.checkForDatatype(type1, type2); 143 } catch (DException ex) { 144 if (ex.getDseCode().equalsIgnoreCase("DSE514") || 145 ex.getDseCode().equalsIgnoreCase("DSE6001")) { 146 throw new DException("DSE8100", new Object [] {StaticClass.getDataTypeName(type1), 147 StaticClass.getDataTypeName(type2)}); 148 } 149 throw ex; 150 } 151 return (type1 > type2) ? type1 : type2; 152 } 153 154 306 307 308 private FieldBase getResult(FieldBase expression1,FieldBase expression2) throws DException { 309 GetByteComparator gbc =new GetByteComparator(); 310 if (gbc.objectComparator.compare(expression1,expression2)==0) { 311 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, resultType); 312 } else { 313 return expression1; 314 } 315 } 316 317 318 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 319 _Reference[] ref = super.checkSemantic(parent); 320 getAppropriateDatatype(parent); 321 return ref; 322 } 323 324 325 int getColumnSize(Object object) throws DException { 326 ColumnDetails[] columnDetails = getChildColumnDetails(); 327 int type =columnDetails[0].getType(); 328 if(type!=TypeConstants.CONSTANT) { 329 int datatype = columnDetails[0].getDatatype(); 330 switch (datatype) { 331 case BYTE: 332 case TINYINT: 333 case INTEGER: 334 case INT: 335 return INTSIZE; 336 case REAL: 337 return FLOATSIZE; 338 case DOUBLE: 339 case FLOAT: 340 case DOUBLEPRECISION: 341 return DOUBLESIZE; 342 case LONG: 343 case BIGINT: 344 return LONGSIZE; 345 case SHORT: 346 case SMALLINT: 347 return SHORTSIZE; 348 case BIGDECIMAL: 349 case DEC: 350 case DECIMAL: 351 case NUMERIC: 352 if (columnDetails[0].getSize() != -5) { 353 return columnDetails[0].getSize(); 354 } 355 break; 356 case DATE : 357 return DATESIZE; 358 case TIME : 359 return TIMESIZE; 360 case TIMESTAMP : 361 return TIMESTAMPSIZE; 362 default : 363 if (columnDetails[0].getSize() != -5) { 364 return columnDetails[0].getSize(); 365 } 366 break; 367 } 368 } else if(columnDetails[0].getQuestion()) { 369 return 255; 370 } else { 371 FieldBase field = (FieldBase)_valueexpression3.run(object); 372 field.setDatatype(columnDetails[0].getDatatype()); 373 return field.getLength(); 374 } 375 return -1; 376 } 377 378 379 } 380 | Popular Tags |