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 com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.numericvaluefunction; 14 15 public class lengthfunction extends AbstractStringValueExpression implements numericvaluefunction { 16 17 public Srightparen_1874859514 _Srightparen_18748595140; 18 public charactervalueexpression _charactervalueexpression1; 19 public Sleftparen653880241 _Sleftparen6538802412; 20 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442553; 21 22 public Object run(Object object) throws com.daffodilwoods.database.resource. 23 DException { 24 FieldBase result = (FieldBase) _charactervalueexpression1.run(object); 25 if (result.isNull()) { 26 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, Datatype.INTEGER); 27 } 28 return getResult(getDataType(result) 29 , result.getObject()); 30 } 31 32 public ColumnDetails[] getChildColumnDetails() throws DException { 33 return columnDetails; 34 } 35 36 public ParameterInfo[] getParameterInfo() throws DException { 37 ParameterInfo[] param = _charactervalueexpression1.getParameterInfo(); 38 for (int i = 0; i < param.length; i++) { 39 if (param[i].getQuestionMark()) { 40 param[i].setDataType(Datatypes.CHARACTER); 41 param[i].setName("LENGTH Arg"); 42 return param; 43 } 44 } 45 return getThisParameterInfo(); 46 } 47 48 protected ParameterInfo[] getThisParameterInfo() throws DException { 49 ParameterInfo parameterInfo = new ParameterInfo(); 50 parameterInfo.setName(toString()); 51 parameterInfo.setDataType(Datatypes.INTEGER); 52 return new ParameterInfo[] { 53 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 SHORT: 91 case SMALLINT: 92 case INTEGER: 93 case INT: 94 case REAL: 95 case DOUBLE: 96 case FLOAT: 97 case DOUBLEPRECISION: 98 case LONG: 99 case BIGINT: 100 case BIGDECIMAL: 101 case DEC: 102 case DECIMAL: 103 case NUMERIC: 104 Number operand = (Number ) object; 105 return new FieldLiteral(new Integer (operand.toString().length()), Datatype.INTEGER); 106 case CHARACTER: 107 case VARCHAR: 108 case CHAR: 109 case CHARACTERVARYING: 110 String string = (String ) object; 111 return new FieldLiteral(new Integer (string.length()), Datatype.INTEGER); 112 default: 113 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 114 } 115 } 116 117 146 147 public AbstractRowValueExpression[] getChilds() { 148 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 149 (AbstractRowValueExpression) (_charactervalueexpression1)}; 150 return childs; 151 152 } 153 154 public String getType() throws DException { 155 return (String ) _SNONRESERVEDWORD1364442553.run(null); 156 } 157 158 public String toString() { 159 StringBuffer sb = new StringBuffer (); 160 sb.append(" "); 161 sb.append(_SNONRESERVEDWORD1364442553); 162 sb.append(" "); 163 sb.append(_Sleftparen6538802412); 164 sb.append(" "); 165 sb.append(_charactervalueexpression1); 166 sb.append(" "); 167 sb.append(_Srightparen_18748595140); 168 return sb.toString(); 169 } 170 171 public Object clone() throws CloneNotSupportedException { 172 lengthfunction tempClass = new lengthfunction(); 173 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 174 _Srightparen_18748595140.clone(); 175 tempClass._charactervalueexpression1 = (charactervalueexpression) 176 _charactervalueexpression1.clone(); 177 tempClass._Sleftparen6538802412 = (Sleftparen653880241) 178 _Sleftparen6538802412.clone(); 179 tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) 180 _SNONRESERVEDWORD1364442553.clone(); 181 return tempClass; 182 } 183 184 public ByteComparison getByteComparison(Object object) throws DException { 185 return new ByteComparison(false, new int[] {INTEGER}); 186 } 187 188 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 189 _Reference[] ref = super.checkSemantic(parent); 190 if(ref!=null) { 191 return ref; 192 } 193 int type = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 194 switch (type) { 195 case -1: 196 case BYTE: 197 case TINYINT: 198 case SHORT: 199 case SMALLINT: 200 case INTEGER: 201 case INT: 202 case REAL: 203 case DOUBLE: 204 case FLOAT: 205 case DOUBLEPRECISION: 206 case LONG: 207 case BIGINT: 208 case BIGDECIMAL: 209 case DEC: 210 case DECIMAL: 211 case NUMERIC: 212 case CHARACTER: 213 case VARCHAR: 214 case CHAR: 215 case CHARACTERVARYING: 216 return ref; 217 default: 218 throw new DException("DSE514", new Object [] {StaticClass.getDataTypeName(type)}); 219 } 220 221 } 222 223 public int getColumnSize(Object object) throws DException { 224 return Datatypes.INTSIZE; 225 } 226 227 } 228 | Popular Tags |