| 1 package com.daffodilwoods.daffodildb.server.sql99.expression.stringvalueexpression; 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 import java.util.ArrayList ; 13 import java.util.Arrays ; 14 import in.co.daffodil.db.jdbc.DatabaseProperties; 15 16 public class leftfunction extends AbstractStringValueExpression implements charactervaluefunction { 17 public Srightparen_1874859514 _Srightparen_18748595140; 18 public stringlength _stringlength1; 19 public Scomma94843605 _Scomma948436052; 20 public charactervalueexpression _charactervalueexpression3; 21 public Sleftparen653880241 _Sleftparen6538802414; 22 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439225; 23 24 25 public Object run(Object object) throws com.daffodilwoods.database.resource. 26 DException { 27 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 45 ArrayList list=new ArrayList (); 46 ParameterInfo[] param1 = _charactervalueexpression3.getParameterInfo(); 47 for (int i = 0; i < param1.length; i++) { 48 if (param1[i].getQuestionMark()) { 49 param1[i].setDataType(Datatypes.CHARACTER); 50 param1[i].setName("LEFT Arg1"); 51 list.addAll(Arrays.asList(param1)); 52 } 53 } 54 ParameterInfo[] param2 = _stringlength1.getParameterInfo(); 55 for (int i = 0; i < param2.length; i++) { 56 if (param2[i].getQuestionMark()) { 57 param2[i].setDataType(Datatypes.INTEGER); 58 param2[i].setName("LEFT Arg2"); 59 list.addAll(Arrays.asList(param2)); 60 } 61 } 62 ParameterInfo[] param3 = new ParameterInfo[list.size()]; 63 list.toArray(param3); 64 for (int i = 0; i < param3.length; i++) { 65 if (param3[i].getQuestionMark()) 66 return param3; 67 } 68 return getThisParameterInfo(); 69 } 70 71 protected ParameterInfo[] getThisParameterInfo() throws DException { 72 ParameterInfo parameterInfo = new ParameterInfo(); 73 parameterInfo.setName(toString()); 74 parameterInfo.setDataType(Datatypes.CHARACTER); 75 return new ParameterInfo[] { 76 parameterInfo}; 77 } 78 79 80 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 81 DException { 82 String nameOfColumn = ""; 83 for (int i = 0; i < columnDetails.length; ++i) { 84 nameOfColumn += columnDetails[i].getColumn(); 85 } 86 return nameOfColumn; 87 } 88 89 140 141 private Object getResult(FieldBase result, int value) throws 142 DException { 143 int type = getDataType(result); 144 145 Object object = result.getObject(); 146 switch (type) { 147 case BYTE: 148 case TINYINT: 149 case INTEGER: 150 case INT: 151 case REAL: 152 case DOUBLE: 153 case FLOAT: 154 case DOUBLEPRECISION: 155 case LONG: 156 case BIGINT: 157 case SHORT: 158 case SMALLINT: 159 case BIGDECIMAL: 160 case DEC: 161 case DECIMAL: 162 case NUMERIC: 163 Number operand = (Number ) object; 164 return left(operand.toString(), value); 165 case CHARACTER: 166 case VARCHAR: 167 case CHAR: 168 case CHARACTERVARYING: 169 String string = (String ) object; 170 return left(string, value); 171 default: 172 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 173 } 174 } 175 176 208 209 private FieldStringLiteral left(String string, int count) throws DException { 210 if (!qualifyForOperation(string)) { 211 return new FieldStringLiteral(string, Datatype.CHARACTER); 212 } 213 if (count < 0) { 214 throw new DException("DSE1160", null); 215 } 216 if (count > string.length()) { 217 return new FieldStringLiteral(string, Datatype.CHARACTER); } 219 return new FieldStringLiteral(string.substring(0, count), Datatype.CHARACTER); 220 } 221 222 private boolean qualifyForOperation(String string) throws DException { 223 if (string == null || string.length() == 0) { 224 return false; 225 } 226 return true; 227 } 228 229 private Integer getCount(FieldBase result) throws DException { 230 231 Object object = result.getObject(); 232 int type = getDataType(result); 233 switch (type) { 234 case BYTE: 235 case TINYINT: 236 case INTEGER: 237 case INT: 238 case REAL: 239 case DOUBLE: 240 case FLOAT: 241 case DOUBLEPRECISION: 242 case LONG: 243 case BIGINT: 244 case SHORT: 245 case SMALLINT: 246 case BIGDECIMAL: 247 case DEC: 248 case DECIMAL: 249 case NUMERIC: 250 Number operand = (Number ) object; 251 return new Integer (operand.intValue()); 252 case CHARACTER: 253 case VARCHAR: 254 case CHAR: 255 case CHARACTERVARYING: 256 String string = (String ) object; 257 Double d = null; 258 try { 259 d = new Double (string); 260 } catch (Exception e) { 261 throw new DException("DSE4104", null); 262 } 263 return new Integer (d.intValue()); 264 default: 265 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "COUNT"}); 266 } 267 268 } 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 leftfunction tempClass = new leftfunction(); 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 int columnSize = getColumnSize(object); 317 byteComparison.setSize(columnSize); 318 return byteComparison; 319 } 320 321 344 345 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 346 _Reference[] ref = super.checkSemantic(parent); 347 if(ref!=null) { 348 return ref; 349 } 350 int type = _charactervalueexpression3.getByteComparison(parent).getDataTypes()[0]; 351 switch (type) { 352 case -1: 353 case BYTE: 354 case TINYINT: 355 case INTEGER: 356 case INT: 357 case REAL: 358 case DOUBLE: 359 case FLOAT: 360 case DOUBLEPRECISION: 361 case LONG: 362 case BIGINT: 363 case SHORT: 364 case SMALLINT: 365 case BIGDECIMAL: 366 case DEC: 367 case DECIMAL: 368 case NUMERIC: 369 case CHARACTER: 370 case VARCHAR: 371 case CHAR: 372 case CHARACTERVARYING: 373 return ref; 374 default: 375 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 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 |