1 package com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.serversystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.common.*; 7 import com.daffodilwoods.daffodildb.server.sql99.expression.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 9 import com.daffodilwoods.daffodildb.utils.field.*; 10 import com.daffodilwoods.database.resource.*; 11 import com.daffodilwoods.database.utility.*; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.queryexpression; 13 14 public abstract class AbstractRowValueExpression implements RowValueExpressionSuper, Datatypes { 15 16 protected ColumnDetails[] columnDetails; 17 protected AbstractRowValueExpression[] childs; 18 19 public abstract AbstractRowValueExpression[] getChilds(); 20 21 public void setDefaultValues(_VariableValueOperations variableValueOperations) throws DException { 22 initializeChildren(); 23 for (int i = 0; i < childs.length; i++) { 24 childs[i].setDefaultValues(variableValueOperations); 25 } 26 } 27 28 public boolean checkForSubQuery() throws DException { 29 initializeChildren(); 30 for (int i = 0; i < childs.length; i++) { 31 if (childs[i].checkForSubQuery()) { 32 return true; 33 } 34 } 35 return false; 36 } 37 38 public _Reference[] getReferences(TableDetails[] tableDetails) throws DException { 39 initializeChildren(); 40 _Reference[][] refs = new _Reference[childs.length][]; 41 int length = 0; 42 for (int i = 0; i < childs.length; i++) { 43 refs[i] = childs[i] == null ? null : childs[i].getReferences(tableDetails); 44 length += refs[i] == null ? 0 : refs[i].length; 45 } 46 _Reference[] references = new _Reference[length]; 47 int index = 0; 48 for (int i = 0; i < childs.length; i++) { 49 _Reference[] ref = refs[i]; 50 if (ref == null) { 51 continue; 52 } 53 for (int j = 0; j < ref.length; j++) { 54 references[index++] = ref[j]; 55 } 56 } 57 if (index == 0) { 58 return null; 59 } 60 return references; 61 } 62 63 64 public ColumnDetails[] getColumnDetails() throws DException { 65 initializeChildren(); 66 if (columnDetails != null) { 67 return columnDetails; 68 } 69 ColumnDetails[][] details = new ColumnDetails[childs.length][]; 70 int length = 0; 71 for (int i = 0; i < childs.length; i++) { 72 details[i] = childs[i] == null ? new ColumnDetails[0] : childs[i].getColumnDetails(); 73 length += details[i].length; 74 } 75 columnDetails = new ColumnDetails[length]; 76 int index = 0; 77 for (int i = 0; i < details.length; i++) { 78 ColumnDetails[] cds = (ColumnDetails[]) details[i]; 79 for (int j = 0; j < cds.length; j++) { 80 columnDetails[index++] = cds[j]; 81 } 82 } 83 return columnDetails; 84 } 85 86 public ParameterInfo[] getParameterInfo() throws DException { 87 initializeChildren(); 88 if (!checkForVariableColumn()) { 89 return getThisParameterInfo(); 90 } 91 Object [][] parms = new Object [childs.length][]; 92 int length = 0; 93 for (int i = 0; i < childs.length; i++) { 94 parms[i] = childs[i] == null ? null : childs[i].getParameterInfo(); 95 length += parms[i] == null ? 0 : parms[i].length; 96 } 97 ParameterInfo[] parameterInfo = new ParameterInfo[length]; 98 int index = 0; 99 for (int i = 0; i < childs.length; i++) { 100 ParameterInfo[] par = GeneralPurposeStaticClass.changeIntoParameterInfo(parms[i]); 101 for (int j = 0; j < par.length; j++) { 102 parameterInfo[index++] = par[j]; 103 } 104 } 105 return parameterInfo; 106 } 107 108 109 110 119 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 120 initializeChildren(); _Reference[][] refs = new _Reference[childs.length][]; 122 int length = 0; 123 for (int i = 0; i < childs.length; i++) { 124 refs[i] = childs[i] == null ? null : childs[i].checkSemantic(parent); 125 length += refs[i] == null ? 0 : refs[i].length; 126 } 127 _Reference[] references = new _Reference[length]; 128 int index = 0; 129 for (int i = 0; i < childs.length; i++) { 130 _Reference[] ref = refs[i]; 131 if (ref == null) { 132 continue; 133 } 134 for (int j = 0; j < ref.length; j++) { 135 references[index++] = ref[j]; 136 } 137 } 138 return references; 139 } 140 141 142 public Object [] getParameters(Object object) throws DException { 143 initializeChildren(); 144 Object [][] parms = new Object [childs.length][]; 145 int length = 0; 146 for (int i = 0; i < childs.length; i++) { 147 148 parms[i] = childs[i] == null ? null : childs[i].getParameters(object); 149 length += parms[i] == null ? 0 : parms[i].length; 150 } 151 Object [] parameters = new Object [length]; 152 int index = 0; 153 for (int i = 0; i < childs.length; i++) { 154 Object [] par = parms[i]; 155 if (par == null) { 156 continue; 157 } 158 for (int j = 0; j < par.length; j++) { 159 parameters[index++] = par[j]; 160 } 161 } 162 return parameters; 163 } 164 165 public int getCardinality() throws DException { 166 initializeChildren(); 167 if (childs.length == 0) { 168 throw new DException("DSE4127", new Object [] {getClass().getName()}); 169 } 170 int cardinality = childs[0].getCardinality(); 171 boolean isQuestionMark = cardinality == -1; 172 for (int i = 1; i < childs.length; i++) { 173 if (childs[i] == null) { 174 continue; 175 } 176 int newCardinality = childs[i].getCardinality(); 177 if (newCardinality == -1) { 178 isQuestionMark = true; 179 continue; 180 } 181 if (cardinality != -1 && cardinality != newCardinality) { 182 for (int k = 0; k < childs.length; k++) { 183 } 184 throw new DException("DSE214", null); 185 } 186 cardinality = newCardinality; 187 } 188 return isQuestionMark ? -1 : cardinality; 189 } 190 191 public void getColumnsIncluded(ArrayList aList) throws DException { 192 initializeChildren(); 193 for (int i = 0; i < childs.length; i++) { 194 ( (AbstractRowValueExpression) childs[i]).getColumnsIncluded(aList); 195 } 196 } 197 198 public void getTablesIncluded(ArrayList aList) throws DException { 199 initializeChildren(); 200 for (int i = 0; i < childs.length; i++) { 201 ( (AbstractRowValueExpression) childs[i]).getTablesIncluded(aList); 202 } 203 } 204 205 208 protected void initializeChildren() { 209 if (childs == null) { 210 childs = getChilds(); 211 } 212 } 213 214 public Object clone() throws CloneNotSupportedException { 215 throw new CloneNotSupportedException (); 216 } 217 218 private boolean checkForVariableColumn() throws DException { 219 for (int i = 0; i < columnDetails.length; ++i) { 220 if (columnDetails[i].getColumn().equals("?")) { 221 return true; 222 } 223 } 224 return false; 225 } 226 227 protected ParameterInfo[] getThisParameterInfo() throws DException { 228 throw new UnsupportedOperationException (" Implementation provided in exteending class..."); 229 } 230 231 public ByteComparison getByteComparison(Object object) throws DException { 232 initializeChildren(); 233 int childsLength = childs.length; 234 int[][] parms = new int[childsLength][]; 235 Object [][] fields = new Object [childsLength][]; 236 int length = 0; 237 boolean byteComparison = true; 238 for (int i = 0; i < childsLength; i++) { 239 if (childs[i] != null) { 240 ByteComparison bc = childs[i].getByteComparison(object); 241 if (!bc.canUseByteComparison()) { 242 byteComparison = false; 243 } 244 parms[i] = bc.getDataTypes(); 245 fields[i] = bc.getField(); 246 length += parms[i].length; 247 } 248 } 249 int[] dataTypes = new int[length]; 250 Object [] f = new Object [length]; 251 int index = 0; 252 for (int i = 0; i < childsLength; i++) { 253 int[] par = parms[i]; 254 Object [] tempField = fields[i]; 255 for (int j = 0; j < par.length; j++) { 256 try { 257 f[index] = tempField[j]; 258 } catch (ArrayIndexOutOfBoundsException ex) { 259 for (int k = 0; k < childs.length; k++) { 260 ByteComparison b = childs[k].getByteComparison(object); 261 } 262 263 throw ex; 264 } 265 dataTypes[index++] = par[j]; 266 } 267 } 268 ByteComparison b = new ByteComparison(byteComparison, dataTypes); 269 b.setField(f); 270 return b; 271 } 272 273 public void releaseResource() throws DException { 274 initializeChildren(); 275 for (int i = 0; i < childs.length; i++) { 276 childs[i].releaseResource(); 277 } 278 } 279 280 protected int getDataTypeForByte(ByteComparison b) throws DException { 281 int dataType1 = b.getDataTypes()[0]; 282 if (dataType1 == -1) { 283 Object field = b.getField()[0]; 284 if (field instanceof FieldBase) { 285 FieldBase f = ( (FieldBase) field); 286 if( f.getDatatype() == -1 ) f.setDatatype( -1); 288 dataType1 = f.getDatatype(); 289 } 290 } 291 return dataType1; 292 } 293 } 294 | Popular Tags |