1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 stringvalueexpression; 3 4 import java.math.*; 5 6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 7 import com.daffodilwoods.daffodildb.server.serversystem.*; 8 import com.daffodilwoods.daffodildb.server.sql99.common.*; 9 import com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 11 import com.daffodilwoods.daffodildb.server.sql99.token.*; 12 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 13 import com.daffodilwoods.daffodildb.utils.*; 14 import com.daffodilwoods.daffodildb.utils.field.*; 15 import com.daffodilwoods.database.resource.*; 16 import java.util.ArrayList ; 17 import java.util.Arrays ; 18 import in.co.daffodil.db.jdbc.DatabaseProperties; 19 20 public class repeatfunction extends AbstractStringValueExpression implements charactervaluefunction { 21 public Srightparen_1874859514 _Srightparen_18748595140; 22 public numericvalueexpression _numericvalueexpression1; 23 public Scomma94843605 _Scomma948436052; 24 public charactervalueexpression _charactervalueexpression3; 25 public Sleftparen653880241 _Sleftparen6538802414; 26 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442555; 27 28 29 public Object run(Object object) throws com.daffodilwoods.database.resource. 30 DException { 31 FieldBase result1 = (FieldBase) _charactervalueexpression3.run(object); 32 FieldBase result2 = (FieldBase) _numericvalueexpression1.run(object); 33 if (result1.isNull() || result2.isNull()) { 34 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 35 } 36 return getResult(result1, result2); 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("REPEAT Arg1"); 51 list.addAll(Arrays.asList(param1)); 52 } 53 } 54 ParameterInfo[] param2 = _numericvalueexpression1.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("REPEAT Arg2"); 59 list.addAll(Arrays.asList(param2)); 60 } 61 } 62 63 ParameterInfo[] param3 = new ParameterInfo[list.size()]; 64 list.toArray(param3); 65 for (int i = 0; i <param3.length; i++) { 66 if(param3[i].getQuestionMark()) 67 return param3; 68 } 69 return getThisParameterInfo(); 70 } 71 72 protected ParameterInfo[] getThisParameterInfo() throws DException { 73 ParameterInfo parameterInfo = new ParameterInfo(); 74 parameterInfo.setName(toString()); 75 parameterInfo.setDataType(Datatypes.CHARACTER); 76 return new ParameterInfo[] {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 109 110 private Object getResult(FieldBase result, FieldBase countFB) throws 111 DException { 112 Object object = result.getObject(); 113 int type1 = getDataType(result); 114 switch (type1) { 115 case CHARACTER: 116 case VARCHAR: 117 case CHAR: 118 case CHARACTERVARYING: 119 Object count = countFB.getObject(); 120 int type2 = getDataType(countFB); 121 switch (type2) { 122 case BYTE: 123 case TINYINT: 124 case SHORT: 125 case SMALLINT: 126 case INTEGER: 127 case INT: 128 case LONG: 129 case BIGINT: 130 return repeat( (String ) object, ( (Number ) count).longValue()); 131 case REAL: 132 case DOUBLE: 133 case FLOAT: 134 case DOUBLEPRECISION: 135 case BIGDECIMAL: 136 case DEC: 137 case DECIMAL: 138 case NUMERIC: 139 return repeat(object, (Number ) count); 140 case CHARACTER: 141 case VARCHAR: 142 case CHAR: 143 case CHARACTERVARYING: 144 String string = (String ) object; 145 Double d = null; 146 try { 147 d = new Double (string); 148 } catch (Exception e) { 149 throw new DException("DSE4104", new Object [] {"character", "int"}); 150 } 151 return repeat(object, d); 152 default: 153 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type2), "repeat"}); 154 } 155 default: 156 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type1), "repeat"}); 157 } 158 } 159 160 private Object repeat(Object object, Number count) throws DException { 161 if ( (new BigDecimal(count + "")).compareTo(new BigDecimal(0)) < 0) { 162 throw new DException("DSE8114", null); 163 } 164 if ( (new BigDecimal(count + "")).compareTo(new BigDecimal("" + Long.MAX_VALUE)) > 0) { 165 throw new DException("DSE8113", new Object [] {"repeat"}); 166 } 167 return repeat( (String ) object, count.longValue()); 168 } 169 170 181 182 private Object repeat(String string, long count) throws DException { 183 if (count < 0) { 184 throw new DException("DSE8114", new Object [] {"repeat"}); 185 } 186 StringBuffer tempString = new StringBuffer (string); 187 while (count-- > 1) { 188 if(tempString.length()<=4192) { 189 tempString.append(string); 190 } else { 191 throw new DException("DSE8170", null); 192 } 193 } 194 return new FieldStringLiteral(tempString.toString(), Datatype.CHARACTER); 195 } 196 197 206 207 284 285 public AbstractRowValueExpression[] getChilds() { 286 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 287 (AbstractRowValueExpression) (_charactervalueexpression3), 288 (AbstractRowValueExpression) (_numericvalueexpression1)}; 289 return childs; 290 291 } 292 293 public String getType() throws DException { 294 return (String ) _SNONRESERVEDWORD1364442555.run(null); 295 } 296 297 public String toString() { 298 StringBuffer sb = new StringBuffer (); 299 sb.append(" "); 300 sb.append(_SNONRESERVEDWORD1364442555); 301 sb.append(" "); 302 sb.append(_Sleftparen6538802414); 303 sb.append(" "); 304 sb.append(_charactervalueexpression3); 305 sb.append(" "); 306 sb.append(_Scomma948436052); 307 sb.append(" "); 308 sb.append(_numericvalueexpression1); 309 sb.append(" "); 310 sb.append(_Srightparen_18748595140); 311 return sb.toString(); 312 } 313 314 public Object clone() throws CloneNotSupportedException { 315 repeatfunction tempClass = new repeatfunction(); 316 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 317 _Srightparen_18748595140.clone(); 318 tempClass._numericvalueexpression1 = (numericvalueexpression) 319 _numericvalueexpression1.clone(); 320 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 321 tempClass._charactervalueexpression3 = (charactervalueexpression) 322 _charactervalueexpression3.clone(); 323 tempClass._Sleftparen6538802414 = (Sleftparen653880241) 324 _Sleftparen6538802414.clone(); 325 tempClass._SNONRESERVEDWORD1364442555 = (SNONRESERVEDWORD136444255) 326 _SNONRESERVEDWORD1364442555.clone(); 327 return tempClass; 328 } 329 330 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 331 _Reference[] ref = super.checkSemantic(parent); 332 if(ref!=null) { 333 return ref; 334 } 335 int type = _charactervalueexpression3.getByteComparison(parent).getDataTypes()[0]; 336 switch (type) { 337 case -1: 338 case CHARACTER: 339 case VARCHAR: 340 case CHAR: 341 case CHARACTERVARYING: 342 return ref; 343 default: 344 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "repeat"}); 345 } 346 347 } 348 349 public int getColumnSize(Object object) throws DException { 350 ColumnDetails[] columnDetails = getChildColumnDetails(); 351 if (columnDetails[0].getQuestion()) { 352 return DatabaseProperties.maxCharLiteralLength; 353 } 354 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 355 columnDetails[0].getSize() != -5) { 356 return columnDetails[0].getSize(); 357 } 358 else { 359 FieldBase field = (FieldBase) _charactervalueexpression3.run(object); 360 field.setDatatype(columnDetails[0].getDatatype()); 361 return field.getLength(); 362 } 363 364 } 365 366 367 368 } 369 | Popular Tags |