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 rtrimfunction 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 public Object run(Object object) throws com.daffodilwoods.database.resource. 24 DException { 25 FieldBase result = (FieldBase) _charactervalueexpression1.run(object); 26 if (result.isNull()) { 27 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 28 } 29 return getResult(getDataType(result), result.getObject()); 30 } 31 32 public ColumnDetails[] getChildColumnDetails() throws DException { 33 return columnDetails; 34 } 35 36 public ParameterInfo[] getParameterInfo() throws DException { 37 38 ParameterInfo[] param = _charactervalueexpression1.getParameterInfo(); 39 for (int i = 0; i < param.length; i++) { 40 if (param[i].getQuestionMark()) { 41 param[0].setDataType(Datatypes.CHARACTER); 42 param[0].setName("RTRIM Arg"); 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 85 86 private Object getResult(int type, Object object) throws DException { 87 switch (type) { 88 case BYTE: 89 case TINYINT: 90 case INTEGER: 91 case INT: 92 case REAL: 93 case DOUBLE: 94 case FLOAT: 95 case DOUBLEPRECISION: 96 case LONG: 97 case BIGINT: 98 case SHORT: 99 case SMALLINT: 100 case BIGDECIMAL: 101 case DEC: 102 case DECIMAL: 103 case NUMERIC: 104 Number number = (Number ) object; 105 return rtrim(number.toString()); 106 case CHARACTER: 107 case VARCHAR: 108 case CHAR: 109 case CHARACTERVARYING: 110 String string = (String ) object; 111 return rtrim(string); 112 default: 113 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 114 } 115 } 116 117 146 147 private Object rtrim(String string) throws DException { 148 int len = string.length(); 149 while ( (len > 0) && (string.charAt(len - 1) <= ' ')) { 150 len--; 151 } 152 return new FieldStringLiteral(string.substring(0, len), Datatype.CHARACTER); 153 } 154 155 public AbstractRowValueExpression[] getChilds() { 156 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 157 (AbstractRowValueExpression) (_charactervalueexpression1)}; 158 return childs; 159 160 } 161 162 public String getType() throws DException { 163 return (String ) _SNONRESERVEDWORD1364442553.run(null); 164 } 165 166 public String toString() { 167 StringBuffer sb = new StringBuffer (); 168 sb.append(" "); 169 sb.append(_SNONRESERVEDWORD1364442553); 170 sb.append(" "); 171 sb.append(_Sleftparen6538802412); 172 sb.append(" "); 173 sb.append(_charactervalueexpression1); 174 sb.append(" "); 175 sb.append(_Srightparen_18748595140); 176 return sb.toString(); 177 } 178 179 public Object clone() throws CloneNotSupportedException { 180 rtrimfunction tempClass = new rtrimfunction(); 181 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 182 _Srightparen_18748595140.clone(); 183 tempClass._charactervalueexpression1 = (charactervalueexpression) 184 _charactervalueexpression1.clone(); 185 tempClass._Sleftparen6538802412 = (Sleftparen653880241) 186 _Sleftparen6538802412.clone(); 187 tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) 188 _SNONRESERVEDWORD1364442553.clone(); 189 return tempClass; 190 } 191 192 public ByteComparison getByteComparison(Object object) throws DException { 193 ByteComparison byteComparison=new ByteComparison(false, new int[] {Datatype.CHARACTER}); 194 byteComparison.setSize(getColumnSize(object)); 195 return byteComparison; 196 } 197 198 221 222 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 223 _Reference[] ref = super.checkSemantic(parent); 224 if(ref!=null) { 225 return ref; 226 } 227 int type = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 228 switch (type) { 229 case -1: 230 case BYTE: 231 case TINYINT: 232 case INTEGER: 233 case INT: 234 case REAL: 235 case DOUBLE: 236 case FLOAT: 237 case DOUBLEPRECISION: 238 case LONG: 239 case BIGINT: 240 case SHORT: 241 case SMALLINT: 242 case BIGDECIMAL: 243 case DEC: 244 case DECIMAL: 245 case NUMERIC: 246 case CHARACTER: 247 case VARCHAR: 248 case CHAR: 249 case CHARACTERVARYING: 250 return ref; 251 default: 252 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 253 } 254 } 255 256 public int getColumnSize(Object object) throws DException { 257 ColumnDetails[] columnDetails = getChildColumnDetails(); 258 if (columnDetails[0].getQuestion()) { 259 return DatabaseProperties.maxCharLiteralLength; 260 } 261 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 262 columnDetails[0].getSize() != -5) { 263 return columnDetails[0].getSize(); 264 } 265 else { 266 FieldBase field = (FieldBase) _charactervalueexpression1.run(object); 267 field.setDatatype(columnDetails[0].getDatatype()); 268 return field.getLength(); 269 } 270 } 271 272 273 } 274 | Popular Tags |