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 in.co.daffodil.db.jdbc.DatabaseProperties; 14 15 public class ltrimfunction extends AbstractStringValueExpression implements charactervaluefunction { 16 17 public Srightparen_1874859514 _Srightparen_18748595140; 18 public charactervalueexpression _charactervalueexpression1; 19 public Sleftparen653880241 _Sleftparen6538802412; 20 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442553; 21 22 23 24 public Object run(Object object) throws com.daffodilwoods.database.resource. 25 DException { 26 FieldBase result = (FieldBase) _charactervalueexpression1.run(object); 27 if (result.isNull()) { 28 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 29 } 30 return getResult(result); 31 } 32 33 public ColumnDetails[] getChildColumnDetails() throws DException { 34 return columnDetails; 35 } 36 37 public ParameterInfo[] getParameterInfo() throws DException { 38 ParameterInfo[] param = _charactervalueexpression1.getParameterInfo(); 39 for (int i = 0; i < param.length; i++) { 40 if (param[i].getQuestionMark()) { 41 param[i].setDataType(Datatypes.CHARACTER); 42 param[i].setName("LTRIM Arg1"); 43 return param; 44 } 45 } 46 return getThisParameterInfo(); 47 } 48 49 protected ParameterInfo[] getThisParameterInfo() throws DException { 50 ParameterInfo parameterInfo = new ParameterInfo(); 51 parameterInfo.setName(toString()); 52 parameterInfo.setDataType(Datatypes.CHARACTER); 53 return new ParameterInfo[] {parameterInfo}; 54 } 55 56 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 57 DException { 58 String nameOfColumn = ""; 59 for (int i = 0; i < columnDetails.length; ++i) { 60 nameOfColumn += columnDetails[i].getColumn(); 61 } 62 return nameOfColumn; 63 } 64 65 114 115 private Object getResult(FieldBase result) throws DException { 116 Object object = result.getObject(); 117 int type = getDataType(result); 118 switch (type) { 119 case BYTE: 120 case TINYINT: 121 case INTEGER: 122 case INT: 123 case REAL: 124 case DOUBLE: 125 case FLOAT: 126 case DOUBLEPRECISION: 127 case LONG: 128 case BIGINT: 129 case SHORT: 130 case SMALLINT: 131 case BIGDECIMAL: 132 case DEC: 133 case DECIMAL: 134 case NUMERIC: 135 Number operand = (Number ) object; 136 return ltrim(operand.toString()); 137 case CHARACTER: 138 case VARCHAR: 139 case CHAR: 140 case CHARACTERVARYING: 141 String string = (String ) object; 142 return ltrim(string); 143 default: 144 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 145 } 146 } 147 148 179 180 private Object ltrim(String string) throws DException { 181 int len = string.length(); 182 int st = 0; 183 while ( (st < len) && (string.charAt(st) <= ' ')) { 184 st++; 185 } 186 return new FieldStringLiteral(string.substring(st), Datatype.CHARACTER); 187 } 188 189 public AbstractRowValueExpression[] getChilds() { 190 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 191 (AbstractRowValueExpression) (_charactervalueexpression1)}; 192 return childs; 193 194 } 195 196 public String getType() throws DException { 197 return (String ) _SNONRESERVEDWORD1364442553.run(null); 198 } 199 200 public String toString() { 201 StringBuffer sb = new StringBuffer (); 202 sb.append(" "); 203 sb.append(_SNONRESERVEDWORD1364442553); 204 sb.append(" "); 205 sb.append(_Sleftparen6538802412); 206 sb.append(" "); 207 sb.append(_charactervalueexpression1); 208 sb.append(" "); 209 sb.append(_Srightparen_18748595140); 210 return sb.toString(); 211 } 212 213 public Object clone() throws CloneNotSupportedException { 214 ltrimfunction tempClass = new ltrimfunction(); 215 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 216 _Srightparen_18748595140.clone(); 217 tempClass._charactervalueexpression1 = (charactervalueexpression) 218 _charactervalueexpression1.clone(); 219 tempClass._Sleftparen6538802412 = (Sleftparen653880241) 220 _Sleftparen6538802412.clone(); 221 tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) 222 _SNONRESERVEDWORD1364442553.clone(); 223 return tempClass; 224 } 225 226 public ByteComparison getByteComparison(Object object) throws DException { 227 ByteComparison byteComparison=new ByteComparison(false, new int[] {CHARACTER}); 228 int columnSize=getColumnSize(object); 229 byteComparison.setSize(columnSize); 230 return byteComparison; 231 } 232 233 256 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 257 _Reference[] ref = super.checkSemantic(parent); 258 if(ref!=null) { 259 return ref; 260 } 261 int type = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 262 switch (type) { 263 case -1: 264 case BYTE: 265 case TINYINT: 266 case INTEGER: 267 case INT: 268 case REAL: 269 case DOUBLE: 270 case FLOAT: 271 case DOUBLEPRECISION: 272 case LONG: 273 case BIGINT: 274 case SHORT: 275 case SMALLINT: 276 case BIGDECIMAL: 277 case DEC: 278 case DECIMAL: 279 case NUMERIC: 280 case CHARACTER: 281 case VARCHAR: 282 case CHAR: 283 case CHARACTERVARYING: 284 return ref; 285 default: 286 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 287 } 288 289 } 290 291 public int getColumnSize(Object object) throws DException { 292 ColumnDetails[] columnDetails = getChildColumnDetails(); 293 if (columnDetails[0].getQuestion()) { 294 return DatabaseProperties.maxCharLiteralLength; 295 } 296 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 297 columnDetails[0].getSize() != -5) { 298 return columnDetails[0].getSize(); 299 } 300 else { 301 FieldBase field = (FieldBase) _charactervalueexpression1.run(object); 302 field.setDatatype(columnDetails[0].getDatatype()); 303 return field.getLength(); 304 } 305 306 } 307 308 309 } 310 | Popular Tags |