1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 stringvalueexpression; 3 4 import com.daffodilwoods.daffodildb.server.sql99.common.*; 5 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 6 import com.daffodilwoods.daffodildb.server.sql99.token.*; 7 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 8 import com.daffodilwoods.daffodildb.utils.*; 9 import com.daffodilwoods.daffodildb.utils.field.*; 10 import com.daffodilwoods.database.resource.*; 11 import java.util.ArrayList ; 12 import java.util.Arrays ; 13 import in.co.daffodil.db.jdbc.DatabaseProperties; 14 import com.daffodilwoods.daffodildb.server.serversystem._ServerSession; 15 16 public class concatfunction extends AbstractStringValueExpression implements charactervaluefunction { 17 public Srightparen_1874859514 _Srightparen_18748595140; 18 public charactervalueexpression _charactervalueexpression1; 19 public Scomma94843605 _Scomma948436052; 20 public charactervalueexpression _charactervalueexpression3; 21 public Sleftparen653880241 _Sleftparen6538802414; 22 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442555; 23 24 25 public Object run(Object object) throws com.daffodilwoods.database.resource. 26 DException { 27 FieldBase result1 = (FieldBase) _charactervalueexpression3.run(object); 28 FieldBase result2 = (FieldBase) _charactervalueexpression1.run(object); 29 if (result1.isNull() && result2.isNull()) { 30 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, Datatypes.CHARACTER); 31 } 32 return result1.isNull() ? new FieldStringLiteral(result2.getObject().toString(), Datatypes.CHARACTER) 33 : result2.isNull() ? new FieldStringLiteral(result1.getObject().toString(), Datatypes.CHARACTER) : 34 new FieldStringLiteral(new StringBuffer (result1.getObject().toString()).append(result2.getObject().toString()).toString(), Datatypes.CHARACTER); 35 } 36 37 public ColumnDetails[] getChildColumnDetails() throws DException { 38 return columnDetails; 39 } 40 41 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 42 DException { 43 String nameOfColumn = ""; 44 for (int i = 0; i < columnDetails.length; ++i) { 45 nameOfColumn += columnDetails[i].getColumn(); 46 } 47 return nameOfColumn; 48 } 49 50 public ParameterInfo[] getParameterInfo() throws DException { 51 ArrayList list =new ArrayList (); 52 ParameterInfo[] param1 = _charactervalueexpression3.getParameterInfo(); 53 for (int i = 0; i < param1.length; i++) { 54 if (param1[i].getQuestionMark()){ 55 param1[i].setDataType(Datatypes.CHARACTER); 56 param1[i].setName("CONCAT Arg1"); 57 list.addAll(Arrays.asList(param1)); 58 } 59 } 60 ParameterInfo[] param2 = _charactervalueexpression1.getParameterInfo(); 61 for (int i = 0; i < param2.length; i++) { 62 if (param2[i].getQuestionMark()) { 63 param2[i].setDataType(Datatypes.CHARACTER); 64 param2[i].setName("CONCAT Arg2"); 65 list.addAll(Arrays.asList(param2)); 66 } 67 } 68 ParameterInfo[] param =new ParameterInfo[list.size()]; 69 list.toArray(param); 70 for (int i = 0; i < param.length; i++) { 71 if(param[i].getQuestionMark()) 72 return param; 73 } 74 return getThisParameterInfo(); 75 76 } 77 78 protected ParameterInfo[] getThisParameterInfo() throws DException { 79 ParameterInfo parameterInfo = new ParameterInfo(); 80 parameterInfo.setName(toString()); 81 parameterInfo.setDataType(columnDetails[0].getDatatype()); 82 return new ParameterInfo[] { 83 parameterInfo}; 84 } 85 86 399 400 public AbstractRowValueExpression[] getChilds() { 401 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 402 (AbstractRowValueExpression) (_charactervalueexpression3), 403 (AbstractRowValueExpression) (_charactervalueexpression1)}; 404 return childs; 405 } 406 407 public String getType() throws DException { 408 return (String ) _SNONRESERVEDWORD1364442555.run(null); 409 } 410 411 public String toString() { 412 StringBuffer sb = new StringBuffer (); 413 sb.append(" "); 414 sb.append(_SNONRESERVEDWORD1364442555); 415 sb.append(" "); 416 sb.append(_Sleftparen6538802414); 417 sb.append(" "); 418 sb.append(_charactervalueexpression3); 419 sb.append(" "); 420 sb.append(_Scomma948436052); 421 sb.append(" "); 422 sb.append(_charactervalueexpression1); 423 sb.append(" "); 424 sb.append(_Srightparen_18748595140); 425 return sb.toString(); 426 } 427 428 public Object clone() throws CloneNotSupportedException { 429 concatfunction tempClass = new concatfunction(); 430 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 431 _Srightparen_18748595140.clone(); 432 tempClass._charactervalueexpression1 = (charactervalueexpression) 433 _charactervalueexpression1.clone(); 434 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 435 tempClass._charactervalueexpression3 = (charactervalueexpression) 436 _charactervalueexpression3.clone(); 437 tempClass._Sleftparen6538802414 = (Sleftparen653880241) 438 _Sleftparen6538802414.clone(); 439 tempClass._SNONRESERVEDWORD1364442555 = (SNONRESERVEDWORD136444255) 440 _SNONRESERVEDWORD1364442555.clone(); 441 return tempClass; 442 } 443 444 public ByteComparison getByteComparison(Object object) throws DException { 445 ByteComparison byteComparison =new ByteComparison(false, new int[] {Datatypes.CHARACTER}); 446 int columnSize=getColumnSize(object); 447 byteComparison.setSize(columnSize); 448 return byteComparison; 449 } 450 451 public int getColumnSize(Object object) throws DException { 452 ColumnDetails[] columnDetails = getChildColumnDetails(); 453 int size=0; 454 if(columnDetails[0].getQuestion()||columnDetails[1].getQuestion()){ 455 return DatabaseProperties.maxCharLiteralLength; 456 } 457 if(columnDetails[0].getType()!=TypeConstants.CONSTANT||columnDetails[0].getSize()!=-5){ 458 size+=columnDetails[0].getSize(); 459 } else { 460 FieldBase field1 = (FieldBase) _charactervalueexpression3.run(object); 461 field1.setDatatype(columnDetails[0].getDatatype()); 462 size+=field1.getLength(); 463 } 464 465 if(columnDetails[1].getType()!=TypeConstants.CONSTANT||columnDetails[1].getSize()!=-5){ 466 size+=columnDetails[1].getSize(); 467 } else { 468 FieldBase field2 = (FieldBase) _charactervalueexpression1.run(object); 469 field2.setDatatype(columnDetails[1].getDatatype()); 470 size+=field2.getLength(); 471 } 472 return size; 473 } 474 475 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 476 _Reference[] ref = super.checkSemantic(parent); 477 if(ref!=null) { 478 return ref; 479 } 480 int type1 = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 481 int type2 = _charactervalueexpression3.getByteComparison(parent).getDataTypes()[0]; 482 switch (type1) { 483 case -1: 484 case CHARACTER: 485 case VARCHAR: 486 case CHAR: 487 case CHARACTERVARYING: 488 switch (type2) { 489 case -1: 490 case CHARACTER: 491 case VARCHAR: 492 case CHAR: 493 case CHARACTERVARYING: 494 return ref; 495 default: 496 throw new DException("DSE419", new Object [] {StaticClass.getDataTypeName(type2), "CONCAT"}); 497 } 498 } 499 throw new DException("DSE419", new Object [] {StaticClass.getDataTypeName(type1), "CONCAT"}); 500 } 501 502 503 504 675 } 676 | Popular Tags |