1 package com.daffodilwoods.daffodildb.server.sql99.expression.stringvalueexpression; 2 3 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 7 import com.daffodilwoods.daffodildb.server.sql99.token.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 9 import com.daffodilwoods.daffodildb.utils.*; 10 import com.daffodilwoods.daffodildb.utils.field.*; 11 import com.daffodilwoods.database.resource.*; 12 import java.util.ArrayList ; 13 import java.util.Arrays ; 14 import com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.numericvaluefunction; 15 import com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.AbstractNumericValueFunction; 16 17 public class differencefunction extends AbstractNumericValueFunction implements numericvaluefunction { 18 public Srightparen_1874859514 _Srightparen_18748595140; 19 public charactervalueexpression _charactervalueexpression1; 20 public Scomma94843605 _Scomma948436052; 21 public charactervalueexpression _charactervalueexpression3; 22 public Sleftparen653880241 _Sleftparen6538802414; 23 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442555; 24 25 int type1 = -1, type2 = -1; 26 27 28 public Object run(Object object) throws com.daffodilwoods.database.resource. 29 DException { 30 31 FieldBase result1 = (FieldBase) _charactervalueexpression1.run(object); 32 if (result1.isNull()) { 33 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, INTEGER); 34 } 35 FieldBase result2 = (FieldBase) _charactervalueexpression3.run(object); 36 if (result2.isNull()) { 37 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, INTEGER); 38 } 39 return getResult(getDataType(result1), getDataType(result2), 40 result1.getObject(), result2.getObject()); 41 } 42 43 public ColumnDetails[] getChildColumnDetails() throws DException { 44 45 return columnDetails; 46 47 } 48 49 public ParameterInfo[] getParameterInfo() throws DException { 50 51 ArrayList list =new ArrayList (); 52 ParameterInfo[] param1 = _charactervalueexpression3.getParameterInfo(); 53 for (int i = 0; i < param1.length; i++) { 54 if (param1[i].getQuestionMark() ) { 55 param1[i].setDataType(Datatypes.CHARACTER); 56 param1[i].setName("DIFFERENCE Arg1"); 57 list.addAll(Arrays.asList(param1)); 58 } 59 } 60 ParameterInfo[] param2 = _charactervalueexpression1.getParameterInfo(); 61 for (int i = 0; i < param2.length; i++) { 62 if (param2[i].getQuestionMark()) { 63 param2[i].setDataType(Datatypes.CHARACTER); 64 param2[i].setName("DIFFERENCE Arg2"); 65 list.addAll(Arrays.asList(param2)); 66 } 67 } 68 ParameterInfo[] param = new ParameterInfo[list.size()]; 69 list.toArray(param); 70 for (int i = 0; i < param.length; i++) { 71 if(param[i].getQuestionMark()) 72 return param; 73 } 74 return getThisParameterInfo(); 75 76 } 77 78 protected ParameterInfo[] getThisParameterInfo() throws DException { 79 80 ParameterInfo parameterInfo = new ParameterInfo(); 81 parameterInfo.setName(toString()); 82 parameterInfo.setDataType(Datatypes.INTEGER); 83 return new ParameterInfo[] { 84 parameterInfo}; 85 86 } 87 88 89 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 90 DException { 91 92 String nameOfColumn = ""; 93 for (int i = 0; i < columnDetails.length; ++i) { 94 nameOfColumn += columnDetails[i].getColumn(); 95 } 96 return nameOfColumn; 97 98 } 99 100 private Object getResult(int type1, int type2, Object result1, Object result2) throws 101 DException { 102 103 switch (type1) { 104 case CHARACTER: 105 case VARCHAR: 106 case CHAR: 107 case CHARACTERVARYING: 108 String string1 = (String ) result1; 109 switch (type2) { 110 case CHARACTER: 111 case VARCHAR: 112 case CHAR: 113 case CHARACTERVARYING: 114 String string2 = (String ) result2; 115 return new FieldLiteral(new Integer (Soundex.difference(string1, string2)), Datatype.INTEGER); 116 } 117 } 118 throw new DException("DSE419", new Object [] {"DIFFERENCE"}); 119 120 } 121 122 public AbstractRowValueExpression[] getChilds() { 123 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 124 (AbstractRowValueExpression) (_charactervalueexpression3), 125 (AbstractRowValueExpression) (_charactervalueexpression1)}; 126 return childs; 127 128 } 129 130 public String getType() throws DException { 131 return (String ) _SNONRESERVEDWORD1364442555.run(null); 132 } 133 134 public String toString() { 135 StringBuffer sb = new StringBuffer (); 136 sb.append(" "); 137 sb.append(_SNONRESERVEDWORD1364442555); 138 sb.append(" "); 139 sb.append(_Sleftparen6538802414); 140 sb.append(" "); 141 sb.append(_charactervalueexpression3); 142 sb.append(" "); 143 sb.append(_Scomma948436052); 144 sb.append(" "); 145 sb.append(_charactervalueexpression1); 146 sb.append(" "); 147 sb.append(_Srightparen_18748595140); 148 return sb.toString(); 149 } 150 151 public Object clone() throws CloneNotSupportedException { 152 differencefunction tempClass = new differencefunction(); 153 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 154 _Srightparen_18748595140.clone(); 155 tempClass._charactervalueexpression1 = (charactervalueexpression) 156 _charactervalueexpression1.clone(); 157 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 158 tempClass._charactervalueexpression3 = (charactervalueexpression) 159 _charactervalueexpression3.clone(); 160 tempClass._Sleftparen6538802414 = (Sleftparen653880241) 161 _Sleftparen6538802414.clone(); 162 tempClass._SNONRESERVEDWORD1364442555 = (SNONRESERVEDWORD136444255) 163 _SNONRESERVEDWORD1364442555.clone(); 164 return tempClass; 165 } 166 167 public ByteComparison getByteComparison(Object object) throws DException { 168 ByteComparison byteComparison = new ByteComparison(false, new int[] {INTEGER}); 169 byteComparison.setSize(getColumnSize(object)); 170 return byteComparison; 171 } 172 173 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 174 _Reference[] ref = super.checkSemantic(parent); 175 if(ref!=null) { 176 return ref; 177 } 178 int type1 = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 179 int type2 = _charactervalueexpression3.getByteComparison(parent).getDataTypes()[0]; 180 switch (type1) { 181 case -1: 182 case CHARACTER: 183 case VARCHAR: 184 case CHAR: 185 case CHARACTERVARYING: 186 switch (type2) { 187 case -1: 188 case CHARACTER: 189 case VARCHAR: 190 case CHAR: 191 case CHARACTERVARYING: 192 return ref; 193 default: 194 throw new DException("DSE419", new Object [] {StaticClass.getDataTypeName(type2), "DIFFERENCE"}); 195 } 196 } 197 throw new DException("DSE419", new Object [] {StaticClass.getDataTypeName(type1), "DIFFERENCE"}); 198 } 199 public int getColumnSize(Object object) throws DException { 200 return Datatypes.INTSIZE; 201 } 202 203 204 public ColumnDetails[] getColumnDetails() throws DException { 205 initializeChildren(); 206 int len = childs.length; 207 column = new ColumnDetails(); 208 String type = getType(); StringBuffer str = new StringBuffer (); str.append(type); 211 str.append("("); 212 ColumnDetails[][] cds = new ColumnDetails[len][]; 213 String [] namesOfColumn = new String [len]; 214 for (int i = 0; i < childs.length; i++) { 215 cds[i] = childs[i].getColumnDetails(); 216 namesOfColumn[i] = getNameOfColumn(cds[i]); 217 this.columnDetails = StaticClass.mergeColumnDetails(this.columnDetails, cds[i]); 218 str.append(namesOfColumn[i]); 219 str.append(","); 220 } 221 str.deleteCharAt(str.length() - 1); 222 str.append(")"); 223 224 column.setFunctionType(type); 225 column.setType(SCALARFUNCTION); 226 column.setColumnName(new String [] {str.toString()}); 227 column.setObject(this); 228 return new ColumnDetails[] {column}; 229 } 230 231 232 } 233 | Popular Tags |