1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.set; 2 3 import java.text.*; 4 import java.util.*; 5 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*; 11 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 12 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 13 import com.daffodilwoods.daffodildb.utils.*; 14 import com.daffodilwoods.daffodildb.utils.comparator.*; 15 import com.daffodilwoods.daffodildb.utils.parser.*; 16 import com.daffodilwoods.database.resource.*; 17 import com.daffodilwoods.database.sqlinitiator.*; 18 import com.daffodilwoods.database.utility.*; 19 20 31 public abstract class SetOperatorAbstract implements SetOperatorConstants { 32 33 36 37 protected ColumnDetails[] clonedLeftColumnDetails; 38 39 42 43 protected ColumnDetails[] clonedRightColumnDetails; 44 45 48 49 protected int[] appropriateDataTypes; 50 51 54 55 protected int[] appropriateSizes; 56 57 58 64 65 protected ColumnDetails[] clonedLeftOrderColumnDetails; 66 67 70 71 protected ColumnDetails[] clonedRightOrderColumnDetails; 72 73 74 85 86 public abstract ComparatorAndOrder getComparatorAndOrderForNormalOrder(ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession, boolean[] columnOrder) throws DException; 87 88 100 101 public abstract ComparatorAndOrder getComparatorAndOrderForRearrangedOrder(ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession, boolean[] columnOrder) throws DException; 102 103 117 118 public abstract ComparatorAndOrder getComparatorAndOrderForAlreadyAdjustedOrder(_Order order, ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession, boolean[] columnOrder) throws DException; 119 120 133 protected void changeColumnDetails(ColumnDetails conditionColumnDetails[], ColumnDetails[] oldColumn, ColumnDetails[] newColumn) throws DException { 134 int newColDetailsLen = oldColumn.length; 135 ColumnDetails tempColDetails; 136 for (int i = 0; i < conditionColumnDetails.length; i++) { 137 ColumnDetails columnDetail = conditionColumnDetails[i]; 138 String t1 = columnDetail.getQualifiedColumnName(); 139 for (int j = 0; j < newColDetailsLen; j++) { 140 String t2 = oldColumn[j].getQualifiedColumnName(); 141 if (t1.equalsIgnoreCase(t2)) { 142 columnDetail.setTableDetails(newColumn[j].getTable()); columnDetail.setObject(newColumn[j].getObject()); columnDetail.setColumnName(newColumn[j].getType() == TypeConstants.REFERENCE ? newColumn[j].getColumnName() : (String [])new String [] {newColumn[j].getColumn()}); 145 if (columnDetail.getAliasName() != null) { 146 columnDetail.setAliasName(newColumn[j].getAliasName()); 147 } 148 columnDetail.setType(newColumn[j].getType()); 149 columnDetail.setTableAliasArray(newColumn[j].getTableAliasArray()); 150 columnDetail.setDatatype(newColumn[j].getDatatype()); 151 break; 152 } 153 } 154 } 155 } 156 157 185 protected ComparatorAndOrder getAdjustedSelectOrder(_Order order, ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession) throws DException { 186 if (order == null) { 187 return getOrderAccordingToSelectCols(columnDetailsLeft, columnDetailsRight, serverSession); 188 } 189 if (! ( (_OrderWithTableInformation) order).isAdjustedOrder()) { 190 return getRearrangedOrder(order, columnDetailsLeft, columnDetailsRight, serverSession); 191 } 192 193 return getOrderWhenAlreadyAdjusted(order, columnDetailsLeft, columnDetailsRight, serverSession); 194 } 195 196 197 protected ComparatorAndOrder getOrderWhenUnionAllwithOrderby(_Order order, ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession) throws DException { 198 Object [] adjustedIndexesAndOrder = GeneralPurposeStaticClass.getColumnIndexesAndBooleanOrderOfOrderby(order, columnDetailsLeft); 199 int[] indexes = (int[]) adjustedIndexesAndOrder[0]; 200 boolean[] orderSpecifications = (boolean[]) adjustedIndexesAndOrder[1]; 201 ColumnDetails[] adjustedColsRight = GeneralPurposeStaticClass.getColumnDetailsAccToIndexes(indexes, columnDetailsRight); 202 ColumnDetails[] adjustedColsLeft = GeneralPurposeStaticClass.getColumnDetailsAccToIndexes(indexes, columnDetailsLeft); 203 return getComparatorAndOrderForUnionAllWithOrderby(order, adjustedColsLeft, adjustedColsRight, serverSession, orderSpecifications); 204 } 205 206 207 public ComparatorAndOrder getComparatorAndOrderForUnionAllWithOrderby(_Order order, ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession, boolean[] orderSpecifications) throws DException{ 208 _Order derivedOrderLeft = new SelectOrder(columnDetailsLeft,orderSpecifications,true); 209 _Order derivedOrderRight = new SelectOrder(columnDetailsRight, orderSpecifications, true); 210 211 return new ComparatorAndOrder(getComparableComparator(order.getKeyColumnDetails(), columnDetailsRight, orderSpecifications, serverSession), new _Order[] {derivedOrderLeft, derivedOrderRight}); 212 213 214 } 215 216 217 218 228 protected ComparatorAndOrder getOrderAccordingToSelectCols(ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession) throws DException { 229 boolean[] columnOrder = new boolean[columnDetailsLeft.length]; 230 Arrays.fill(columnOrder, true); 231 return getComparatorAndOrderForNormalOrder(columnDetailsLeft, columnDetailsRight, serverSession, columnOrder); 232 } 233 234 252 protected ComparatorAndOrder getRearrangedOrder(_Order order, ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession) throws DException { 253 Object [] indexAndBooleanOrder = GeneralPurposeStaticClass.getColumnIndexesAndBooleanOrderOfAdjustedOrder(order, columnDetailsLeft,false); 254 ColumnDetails[] orderColumns = order.getColumnDetails(); 255 int[] indexes = null; 256 try { 257 indexes = (int[]) indexAndBooleanOrder[0]; 258 } catch (NullPointerException ex) { 259 throw ex; 260 } 261 boolean[] orderSpecifications = (boolean[]) indexAndBooleanOrder[1]; 262 ColumnDetails[] adjustedColumnsLeft = GeneralPurposeStaticClass.getColumnDetailsAccToIndexes(indexes, columnDetailsLeft); 263 ColumnDetails[] adjustedColumnsRight = GeneralPurposeStaticClass.getColumnDetailsAccToIndexes(indexes, columnDetailsRight); 264 return getComparatorAndOrderForRearrangedOrder(adjustedColumnsLeft, adjustedColumnsRight, serverSession, orderSpecifications); 265 } 266 267 280 protected ComparatorAndOrder getOrderWhenAlreadyAdjusted(_Order order, ColumnDetails[] columnDetailsLeft, ColumnDetails[] columnDetailsRight, _ServerSession serverSession) throws DException { 281 Object [] adjustedIndexesAndOrder = GeneralPurposeStaticClass.getColumnIndexesAndBooleanOrderOfAdjustedOrder(order, columnDetailsLeft,false); 282 int[] indexes = (int[]) adjustedIndexesAndOrder[0]; 283 boolean[] orderSpecifications = (boolean[]) adjustedIndexesAndOrder[1]; 284 ColumnDetails[] adjustedCols = GeneralPurposeStaticClass.getColumnDetailsAccToIndexes(indexes, columnDetailsRight); 285 286 287 ColumnDetails[] adjustedLeftCols = GeneralPurposeStaticClass.getColumnDetailsAccToIndexes(indexes,columnDetailsLeft); 288 289 return getComparatorAndOrderForAlreadyAdjustedOrder(order, adjustedLeftCols, adjustedCols, serverSession, orderSpecifications); 290 291 } 292 293 303 public class ComparatorAndOrder { 304 305 310 311 public _Order order[]; 312 313 317 318 public SuperComparator comparator; 319 320 public ComparatorAndOrder(SuperComparator comparator0, _Order[] order0) { 321 order = order0; 322 comparator = comparator0; 323 } 324 325 } 326 327 338 public SuperComparator getComparableComparator(ColumnDetails[] leftColumns, ColumnDetails[] rightColumns, boolean[] orderSpecifications, _ServerSession serverSession) throws DException { 339 int length = leftColumns.length; 340 SuperComparator[] superComparators = new SuperComparator[length]; 341 for (int i = 0; i < length; i++) { 342 try { 343 Collator collator1 = leftColumns[i].getType() == TypeConstants.REFERENCE ? leftColumns[i].getTable() == null ? null : leftColumns[i].getTable().cc.getCollator() : null; 344 collator1 = collator1 == null && rightColumns[i].getType() == TypeConstants.REFERENCE ? rightColumns[i].getTable() == null ? null : rightColumns[i].getTable().cc.getCollator() : collator1; 345 superComparators[i] = leftColumns[i].canUseByteComparison() && rightColumns[i].canUseByteComparison() ? new CPsefsDpnqbsbups(GetByteComparator.getAppropriateComparator(leftColumns[i].getDatatypeForOrder(), rightColumns[i].getDatatypeForOrder(), serverSession, collator1), orderSpecifications[i]) 346 : new CPsefsDpnqbsbups(new CPckfduDpnqbsbups(), orderSpecifications[i]); 347 } catch (NullPointerException ex) { 348 throw ex; 349 } 350 } 351 return new CKpjoDpnqbsbups(superComparators); 352 } 353 354 363 364 public void initializeAppropriateDataTypeAndSize() throws DException { 365 int length = clonedLeftColumnDetails.length; 366 appropriateDataTypes = new int[length]; 367 appropriateSizes = new int[length]; 368 for (int i = 0; i < length; i++) { 369 int dt1 = clonedLeftColumnDetails[i].getDatatype(); 370 int dt2 = clonedRightColumnDetails[i].getDatatype(); 371 appropriateDataTypes[i] = dt1 > dt2 ? dt1 : dt2; 372 int sz1 = clonedLeftColumnDetails[i].getSize(); 373 int sz2 = clonedRightColumnDetails[i].getSize(); 374 appropriateSizes[i] = sz1 > sz2 ? sz1 : sz2; 375 if (clonedRightColumnDetails[i].getType() != TypeConstants.REFERENCE) { clonedLeftColumnDetails[i].setByteComparison(false); 377 } 378 } 379 } 380 381 386 387 public boolean isSimpleQuery(_ServerSession serverSession) throws DException { 388 return false; 389 } 390 391 public boolean isViewOptimizationPossible() throws DException { 392 return false; 393 } 394 395 public _TablePlan[] getTablePlans(_ServerSession session, booleanvalueexpression condition, _Order order, ColumnDetails[] columnDetails, ConditionArray conditionArray) throws DException { 396 throw new UnsupportedOperationException ("Method getTablePlans() not supported"); 397 } 398 399 public _BVEPlan getBveExecutionPlan() throws DException { 400 throw new UnsupportedOperationException ("Method getTablePlans() not supported"); 401 } 402 403 public Object run(Object object) throws DException { 404 throw new UnsupportedOperationException (); 405 } 406 407 public QueryProperty getStrings() throws com.daffodilwoods.database.resource.DException { 408 409 throw new java.lang.UnsupportedOperationException ("Method getStrings() not yet implemented."); 410 } 411 412 public TableDetails[] getViewTableDetails() throws DException { 413 414 throw new java.lang.UnsupportedOperationException ("Method getViewTableDetails() not yet implemented."); 415 } 416 417 public void setTablesForInsertion(ColumnMappingHandler parm1, _VariableValueOperations parm2) throws com.daffodilwoods.database.resource.DException { 418 419 throw new java.lang.UnsupportedOperationException ("Method setTablesForInsertion() not yet implemented."); 420 } 421 422 public TableDetails[] getTablesForBlankInsert() throws com.daffodilwoods.database.resource.DException { 423 424 throw new java.lang.UnsupportedOperationException ("Method getTablesForBlankInsert() not yet implemented."); 425 } 426 427 public void verifyValues(_VariableValueOperations vv) throws DException { 428 throw new java.lang.UnsupportedOperationException ("Method verifyValues() not yet implemented."); 429 } 430 431 public void setFKeyColumnDetails(ColumnDetails[] parm1) throws com.daffodilwoods.database.resource.DException { 432 433 throw new java.lang.UnsupportedOperationException ("Method setFKeyColumnDetails() not yet implemented."); 434 } 435 } 436 | Popular Tags |