1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 stringvalueexpression; 3 4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 5 import com.daffodilwoods.daffodildb.server.serversystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.common.*; 7 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 8 import com.daffodilwoods.daffodildb.server.sql99.token.*; 9 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 10 import com.daffodilwoods.daffodildb.utils.*; 11 import com.daffodilwoods.daffodildb.utils.field.*; 12 import com.daffodilwoods.database.resource.*; 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import in.co.daffodil.db.jdbc.DatabaseProperties; 16 17 public class rightfunction extends AbstractStringValueExpression implements charactervaluefunction { 18 public Srightparen_1874859514 _Srightparen_18748595140; 19 public stringlength _stringlength1; 20 public Scomma94843605 _Scomma948436052; 21 public charactervalueexpression _charactervalueexpression3; 22 public Sleftparen653880241 _Sleftparen6538802414; 23 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439225; 24 25 26 public Object run(Object object) throws com.daffodilwoods.database.resource. 27 DException { 28 FieldBase result1 = (FieldBase) _charactervalueexpression3.run(object); 29 if (result1.isNull()) { 30 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 31 } 32 FieldBase result2 = (FieldBase) _stringlength1.run(object); 33 if (result2.isNull()) { 34 return result1; 35 } 36 return getResult(result1, getCount(result2).intValue()); 37 } 38 39 public ColumnDetails[] getChildColumnDetails() throws DException { 40 return columnDetails; 41 } 42 43 public ParameterInfo[] getParameterInfo() throws DException { 44 ArrayList list =new ArrayList (); 45 ParameterInfo[] param1 = _charactervalueexpression3.getParameterInfo(); 46 for (int i = 0; i < param1.length; i++) { 47 if (param1[i].getQuestionMark()) { 48 param1[i].setDataType(Datatypes.CHARACTER); 49 param1[i].setName("RIGHT Arg1"); 50 list.addAll(Arrays.asList(param1)); 51 } 52 } 53 ParameterInfo[] param2 = _stringlength1.getParameterInfo(); 54 for (int i = 0; i < param2.length; i++) { 55 if (param2[i].getQuestionMark()) { 56 param2[i].setDataType(Datatypes.INTEGER); 57 param2[i].setName("RIGHT Arg2"); 58 list.addAll(Arrays.asList(param2)); 59 } 60 } 61 ParameterInfo[] param3 = new ParameterInfo[list.size()]; 62 list.toArray(param3); 63 for (int i = 0; i < param3.length; i++) { 64 if(param3[i].getQuestionMark()) 65 return param3; 66 } 67 return getThisParameterInfo(); 68 } 69 70 protected ParameterInfo[] getThisParameterInfo() throws DException { 71 ParameterInfo parameterInfo = new ParameterInfo(); 72 parameterInfo.setName(toString()); 73 parameterInfo.setDataType(Datatypes.CHARACTER); 74 return new ParameterInfo[] { 75 parameterInfo}; 76 } 77 78 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 79 DException { 80 String nameOfColumn = ""; 81 for (int i = 0; i < columnDetails.length; ++i) { 82 nameOfColumn += columnDetails[i].getColumn(); 83 } 84 return nameOfColumn; 85 } 86 87 private ColumnDetails[] mergeColumnDetails(ColumnDetails[] columnDetails1, 88 ColumnDetails[] columnDetails2) throws 89 DException { 90 ColumnDetails[] objectTarget = new ColumnDetails[columnDetails1.length + 91 columnDetails2.length]; 92 int i = 0; 93 for (; i < columnDetails1.length; ++i) { 94 objectTarget[i] = columnDetails1[i]; 95 } 96 for (int j = 0; j < columnDetails2.length; ++i, ++j) { 97 objectTarget[i] = columnDetails2[j]; 98 } 99 return objectTarget; 100 101 } 102 103 123 124 private Object getResult(FieldBase result, int value) throws 125 DException { 126 int type = getDataType(result); 127 Object object = result.getObject(); 128 switch (type) { 129 case BYTE: 130 case TINYINT: 131 case INTEGER: 132 case INT: 133 case REAL: 134 case DOUBLE: 135 case FLOAT: 136 case DOUBLEPRECISION: 137 case LONG: 138 case BIGINT: 139 case SHORT: 140 case SMALLINT: 141 case BIGDECIMAL: 142 case DEC: 143 case DECIMAL: 144 case NUMERIC: 145 Number operand = (Number ) object; 146 return right(operand.toString(), value); 147 case CHARACTER: 148 case VARCHAR: 149 case CHAR: 150 case CHARACTERVARYING: 151 String string = (String ) object; 152 return right(string, value); 153 default: 154 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 155 } 156 } 157 158 190 191 private Object right(String string, int count) throws DException { 192 if (count < 0) { 193 throw new DException("DSE1160", null); 194 } 195 if (count > string.length()) { 196 return new FieldStringLiteral(string, Datatype.CHARACTER); } 198 return new FieldStringLiteral(string.substring(string.length() - count), Datatype.CHARACTER); 199 } 200 201 202 private Integer getCount(FieldBase length) throws DException { 203 Object object = length.getObject(); 204 int type = getDataType(length); 205 switch (type) { 206 case BYTE: 207 case TINYINT: 208 case INTEGER: 209 case FLOAT: 210 case DOUBLE: 211 case LONG: 212 case SHORT: 213 case BIGDECIMAL: 214 Number operand = (Number ) object; 215 return new Integer (operand.intValue()); 216 case CHARACTER: 217 String string = (String ) object; 218 Double d = null; 219 try { 220 d = new Double (string); 221 } catch (Exception e) { 222 throw new DException("DSE87", new Object [] {"Character", "Double"}); 223 } 224 return new Integer (d.intValue()); 225 default: 226 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "right"}); 227 } 228 } 229 230 269 270 public AbstractRowValueExpression[] getChilds() { 271 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 272 (AbstractRowValueExpression) (_charactervalueexpression3), 273 (AbstractRowValueExpression) (_stringlength1)}; 274 return childs; 275 276 } 277 278 public String getType() throws DException { 279 return (String ) _SRESERVEDWORD12065439225.run(null); 280 } 281 282 public String toString() { 283 StringBuffer sb = new StringBuffer (); 284 sb.append(" "); 285 sb.append(_SRESERVEDWORD12065439225); 286 sb.append(" "); 287 sb.append(_Sleftparen6538802414); 288 sb.append(" "); 289 sb.append(_charactervalueexpression3); 290 sb.append(" "); 291 sb.append(_Scomma948436052); 292 sb.append(" "); 293 sb.append(_stringlength1); 294 sb.append(" "); 295 sb.append(_Srightparen_18748595140); 296 return sb.toString(); 297 } 298 299 public Object clone() throws CloneNotSupportedException { 300 rightfunction tempClass = new rightfunction(); 301 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 302 _Srightparen_18748595140.clone(); 303 tempClass._stringlength1 = (stringlength) _stringlength1.clone(); 304 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 305 tempClass._charactervalueexpression3 = (charactervalueexpression) 306 _charactervalueexpression3.clone(); 307 tempClass._Sleftparen6538802414 = (Sleftparen653880241) 308 _Sleftparen6538802414.clone(); 309 tempClass._SRESERVEDWORD12065439225 = (SRESERVEDWORD1206543922) 310 _SRESERVEDWORD12065439225.clone(); 311 return tempClass; 312 } 313 314 public ByteComparison getByteComparison(Object object) throws DException { 315 ByteComparison byteComparison=new ByteComparison(false, new int[] {Datatype.CHARACTER}); 316 byteComparison.setSize(getColumnSize(object)); 317 return byteComparison; 318 } 319 320 343 344 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 345 _Reference[] ref = super.checkSemantic(parent); 346 if(ref!=null) { 347 return ref; 348 } 349 int type = _charactervalueexpression3.getByteComparison(parent).getDataTypes()[0]; 350 switch (type) { 351 case -1: 352 case BYTE: 353 case TINYINT: 354 case INTEGER: 355 case INT: 356 case REAL: 357 case DOUBLE: 358 case FLOAT: 359 case DOUBLEPRECISION: 360 case LONG: 361 case BIGINT: 362 case SHORT: 363 case SMALLINT: 364 case BIGDECIMAL: 365 case DEC: 366 case DECIMAL: 367 case NUMERIC: 368 case CHARACTER: 369 case VARCHAR: 370 case CHAR: 371 case CHARACTERVARYING: 372 return ref; 373 default: 374 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 375 } 376 377 } 378 379 public int getColumnSize(Object object) throws DException { 380 ColumnDetails[] columnDetails = getChildColumnDetails(); 381 if (columnDetails[0].getQuestion()) { 382 return DatabaseProperties.maxCharLiteralLength; 383 } 384 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 385 columnDetails[0].getSize() != -5) { 386 return columnDetails[0].getSize(); 387 } 388 else { 389 FieldBase field = (FieldBase) _charactervalueexpression3.run(object); 390 field.setDatatype(columnDetails[0].getDatatype()); 391 return field.getLength(); 392 } 393 } 394 395 396 } 397 | Popular Tags |