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 replacefunction extends AbstractStringValueExpression implements charactervaluefunction { 18 public Srightparen_1874859514 _Srightparen_18748595140; 19 public charactervalueexpression _charactervalueexpression1; 20 public Scomma94843605 _Scomma948436052; 21 public charactervalueexpression _charactervalueexpression3; 22 public Scomma94843605 _Scomma948436054; 23 public charactervalueexpression _charactervalueexpression5; 24 public Sleftparen653880241 _Sleftparen6538802416; 25 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442557; 26 27 28 public Object run(Object object) throws com.daffodilwoods.database.resource. 29 DException { 30 FieldBase result1 = (FieldBase) _charactervalueexpression5.run(object); 31 if (result1.isNull()) { 32 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 33 } 34 FieldBase result2 = (FieldBase) _charactervalueexpression3.run(object); 35 if (result2.isNull()) { 36 return result1; 37 } 38 FieldBase result3 = (FieldBase) _charactervalueexpression1.run(object); 39 if (result3.isNull()) { 40 return getResult(result1, result2, "", Datatype.CHARACTER); 41 } 42 return getResult(result1, result2, result3.getObject(), getDataType(result3)); 43 } 44 45 public ColumnDetails[] getChildColumnDetails() throws DException { 46 return columnDetails; 47 } 48 49 public ParameterInfo[] getParameterInfo() throws DException { 50 ArrayList list =new ArrayList (); 51 ParameterInfo[] param1 = _charactervalueexpression5.getParameterInfo(); 52 for (int i = 0; i < param1.length; i++) { 53 if (param1[i].getQuestionMark()) { 54 param1[i].setDataType(Datatypes.CHARACTER); 55 param1[i].setName("REPLACE Arg1"); 56 list.addAll(Arrays.asList(param1)); 57 } 58 } 59 ParameterInfo[] param2 = _charactervalueexpression3.getParameterInfo(); 60 for (int i = 0; i < param2.length; i++) { 61 if (param2[i].getQuestionMark()) { 62 param2[i].setDataType(Datatypes.CHARACTER); 63 param2[i].setName("REPLACE Arg2"); 64 list.addAll(Arrays.asList(param2)); 65 } 66 } 67 ParameterInfo[] param3 = _charactervalueexpression1.getParameterInfo(); 68 for (int i = 0; i <param3.length; i++) { 69 if (param3[i].getQuestionMark()) { 70 param3[i].setDataType(Datatypes.CHARACTER); 71 param3[i].setName("REPLACE Arg3"); 72 list.addAll(Arrays.asList(param3)); 73 } 74 } 75 76 ParameterInfo[] param4 = new ParameterInfo[list.size()]; 77 list.toArray(param4); 78 for (int i = 0; i < param4.length; i++) { 79 if(param4[i].getQuestionMark()){ 80 return param4; 81 } 82 } 83 return getThisParameterInfo(); 84 } 85 86 protected ParameterInfo[] getThisParameterInfo() throws DException { 87 ParameterInfo parameterInfo = new ParameterInfo(); 88 parameterInfo.setName(toString()); 89 parameterInfo.setDataType(Datatypes.CHARACTER); 90 return new ParameterInfo[] { 91 parameterInfo}; 92 } 93 94 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 95 DException { 96 String nameOfColumn = ""; 97 for (int i = 0; i < columnDetails.length; ++i) { 98 nameOfColumn += columnDetails[i].getColumn(); 99 } 100 return nameOfColumn; 101 } 102 103 123 124 private Object getResult(FieldBase object1, FieldBase object2, 125 Object result3, int type3) throws DException { 126 int type1 = getDataType(object1); 127 int type2 = getDataType(object2); 128 129 switch (type1) { 130 case DATE: 131 throw new DException("DSE4108", new Object [] {"date", "replace"}); 132 case TIME: 133 throw new DException("DSE4108", new Object [] {"time", "replace"}); 134 case TIMESTAMP: 135 throw new DException("DSE4108", new Object [] {"timestamp", "replace"}); 136 default: 137 switch (type2) { 138 case DATE: 139 throw new DException("DSE4108", new Object [] {"date", "replace"}); 140 case TIME: 141 throw new DException("DSE4108", new Object [] {"time", "replace"}); 142 case TIMESTAMP: 143 throw new DException("DSE4108", new Object [] {"timestamp", "replace"}); 144 default: 145 switch (type3) { 146 case DATE: 147 throw new DException("DSE4108", new Object [] {"date", "replace"}); 148 case TIME: 149 throw new DException("DSE4108", new Object [] {"time", "replace"}); 150 case TIMESTAMP: 151 throw new DException("DSE4108", new Object [] {"timestamp", "replace"}); 152 default: 153 return new FieldStringLiteral( 154 replace(object1.getObject().toString(), object2.getObject().toString(), 155 result3.toString()), Datatype.CHARACTER); 156 } 157 } 158 } 159 } 160 161 private String replace(String string1, String string2, String string3) throws 162 DException { 163 if (!qualifyForOperation(string1) || !qualifyForOperation(string2)) { 164 return string1; 165 } 166 int len3 = string3.length(); 167 int len2 = string2.length(); 168 int fromIndex = 0; 169 while (true) { 170 int index = string1.indexOf(string2, fromIndex); 171 if (index == -1) { 172 break; 173 } 174 String tempString = string1.substring(0, index) + string3 + 175 string1.substring(index + len2); 176 string1 = tempString; 177 fromIndex += len3; 178 } 179 180 return string1; 181 } 182 183 private boolean qualifyForOperation(String string) throws DException { 184 if (string == null || string.length() == 0) { 185 return false; 186 } 187 return true; 188 } 189 190 public AbstractRowValueExpression[] getChilds() { 191 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 192 (AbstractRowValueExpression) (_charactervalueexpression5), 193 (AbstractRowValueExpression) (_charactervalueexpression3), 194 (AbstractRowValueExpression) (_charactervalueexpression1)}; 195 return childs; 196 197 } 198 199 public String getType() throws DException { 200 return (String ) _SNONRESERVEDWORD1364442557.run(null); 201 } 202 203 public String toString() { 204 StringBuffer sb = new StringBuffer (); 205 sb.append(" "); 206 sb.append(_SNONRESERVEDWORD1364442557); 207 sb.append(" "); 208 sb.append(_Sleftparen6538802416); 209 sb.append(" "); 210 sb.append(_charactervalueexpression5); 211 sb.append(" "); 212 sb.append(_Scomma948436054); 213 sb.append(" "); 214 sb.append(_charactervalueexpression3); 215 sb.append(" "); 216 sb.append(_Scomma948436052); 217 sb.append(" "); 218 sb.append(_charactervalueexpression1); 219 sb.append(" "); 220 sb.append(_Srightparen_18748595140); 221 return sb.toString(); 222 } 223 224 public Object clone() throws CloneNotSupportedException { 225 replacefunction tempClass = new replacefunction(); 226 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 227 _Srightparen_18748595140.clone(); 228 tempClass._charactervalueexpression1 = (charactervalueexpression) 229 _charactervalueexpression1.clone(); 230 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 231 tempClass._charactervalueexpression3 = (charactervalueexpression) 232 _charactervalueexpression3.clone(); 233 tempClass._Scomma948436054 = (Scomma94843605) _Scomma948436054.clone(); 234 tempClass._charactervalueexpression5 = (charactervalueexpression) 235 _charactervalueexpression5.clone(); 236 tempClass._Sleftparen6538802416 = (Sleftparen653880241) 237 _Sleftparen6538802416.clone(); 238 tempClass._SNONRESERVEDWORD1364442557 = (SNONRESERVEDWORD136444255) 239 _SNONRESERVEDWORD1364442557.clone(); 240 return tempClass; 241 } 242 243 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 244 _Reference[] ref = super.checkSemantic(parent); 245 if(ref!=null) { 246 return ref; 247 } 248 int type1 = _charactervalueexpression5.getByteComparison(parent).getDataTypes()[0]; 249 int type2 = _charactervalueexpression3.getByteComparison(parent).getDataTypes()[0]; 250 int type3 = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 251 252 switch (type1) { 253 case DATE: 254 throw new DException("DSE4108", new Object [] {"date", "replace"}); 255 case TIME: 256 throw new DException("DSE4108", new Object [] {"time", "replace"}); 257 case TIMESTAMP: 258 throw new DException("DSE4108", new Object [] {"timestamp", "replace"}); 259 case -1: 260 default: 261 switch (type2) { 262 case DATE: 263 throw new DException("DSE4108", new Object [] {"date", "replace"}); 264 case TIME: 265 throw new DException("DSE4108", new Object [] {"time", "replace"}); 266 case TIMESTAMP: 267 throw new DException("DSE4108", new Object [] {"timestamp", 268 "replace"}); 269 case -1: 270 default: 271 switch (type3) { 272 case DATE: 273 throw new DException("DSE4108", new Object [] {"date", "replace"}); 274 case TIME: 275 throw new DException("DSE4108", new Object [] {"time", "replace"}); 276 case TIMESTAMP: 277 throw new DException("DSE4108", new Object [] {"timestamp", 278 "replace"}); 279 case -1: 280 default: 281 return ref; 282 } 283 } 284 } 285 286 } 287 288 public int getColumnSize(Object object) throws DException{ 289 ColumnDetails[] columnDetails = getChildColumnDetails(); 290 if (columnDetails[0].getQuestion()) { 291 return DatabaseProperties.maxCharLiteralLength; 292 } 293 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 294 columnDetails[0].getSize() != -5) { 295 return columnDetails[0].getSize(); 296 } 297 else { 298 FieldBase field = (FieldBase) _charactervalueexpression5.run(object); 299 field.setDatatype(columnDetails[0].getDatatype()); 300 return field.getLength(); 301 } 302 } 303 304 314 315 } 316 | Popular Tags |