1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.table; 2 3 import com.daffodilwoods.daffodildb.server.serversystem.*; 4 import com.daffodilwoods.daffodildb.server.sql99.common.*; 5 import com.daffodilwoods.daffodildb.server.sql99.dql.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*; 8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 9 import com.daffodilwoods.database.resource.*; 10 import com.daffodilwoods.database.sqlinitiator.*; 11 12 24 25 public abstract class OrderTablePlanAbstract extends PlanExceptionAbstract implements TableExpressionConstants { 26 27 39 40 public void merge(_JoinRelation joinRelations) throws DException { 41 TableDetails[] tableDetails = joinRelations.getTableDetails(); 42 int mappingPosition1 = getTablePosition(tableDetails[0]); 43 _TablePlan tablePlan1 = childPlans[mappingPosition1]; 44 int mappingPosition2 = getTablePosition(tableDetails[1]); 45 _TablePlan tablePlan2 = childPlans[mappingPosition2]; 46 int[] tablePositions = new int[] {mappingPosition1, mappingPosition2}; 47 changeTablePlans(tablePlan1, tablePlan2, joinRelations, tableDetails, tablePositions); 48 } 49 50 60 61 private void changeTablePlans(_TablePlan tablePlan1, _TablePlan tablePlan2, _JoinRelation joinRelation, TableDetails[] tableDetails, int[] mappingPositions) throws DException { 62 int index1 = getIndex(tableDetails[0]); 63 int index2 = getIndex(tableDetails[1]); 64 if (index1 > index2) { 65 int temp = index1; 66 index1 = index2; 67 index2 = temp; 68 } 69 if (index2 - index1 == 0) { 70 tablePlan1.merge(joinRelation); 71 } else 72 if ( (index2 - index1) > 1) { prepareTableMergeAndUpdateTablePlans(tablePlan1, joinRelation.getCondition(), index1, index2); 74 } else { prepareTwoTableJoinPlanAndUpdateTablePlans(tablePlan1, joinRelation.getCondition(), index1, index2); 76 } 77 } 78 79 86 87 private int getTablePosition(TableDetails tableDetails) throws DException { 88 int length = childPlans.length; 89 for (int i = 0; i < length; i++) { 90 if (childPlans[i].ifExists(tableDetails)) { 91 return i; 92 } 93 } 94 throw new DException("DSE3526", new Object [] {tableDetails.getNameOfTable()}); 95 } 96 97 109 110 private void prepareTableMergeAndUpdateTablePlans(_TablePlan orderSequencePlan, booleanvalueexpression bve, int index1, int index2) throws DException { 111 _TablePlan[] tp = childPlans; 112 int len = tp.length; 113 TemporaryMerge tempMerge = new TemporaryMerge(); 114 for (int i = index1; i <= index2; i++) { 115 tempMerge.addTablePlan(tp[i]); 116 } 117 tempMerge.addCondition(bve); 118 _TablePlan[] newTp = new _TablePlan[tp.length - (index2 - index1)]; 119 System.arraycopy(tp, 0, newTp, 0, index1); 120 newTp[index1] = tempMerge; 121 System.arraycopy(tp, index2 + 1, newTp, index1 + 1, tp.length - index2 - 1); 122 setPlans(newTp); 123 } 124 125 136 137 private void prepareTwoTableJoinPlanAndUpdateTablePlans(_TablePlan orderSequencePlan, booleanvalueexpression bve, int index1, int index2) throws DException { 138 _TablePlan[] tp = childPlans; 139 int len = tp.length; 140 TwoTableJoinPlan ttJp = new TwoTableJoinPlan(tp[index1], tp[index2], bve); 141 _TablePlan[] newTp = new _TablePlan[tp.length - 1]; 142 System.arraycopy(tp, 0, newTp, 0, index1); 143 newTp[index1] = ttJp; 144 System.arraycopy(tp, index1 + 1, newTp, index1 + 1, index2 - index1 - 1); 145 System.arraycopy(tp, index2 + 1, newTp, index2, newTp.length - index2); 146 setPlans(newTp); 147 } 148 149 155 156 public int getIndex(TableDetails tableDetails) throws DException { 157 for (int i = 0; i < childPlans.length; i++) { 158 if (childPlans[i].ifExists(tableDetails)) { 159 return i; 160 } 161 } 162 throw new DException("DSE3526", new Object [] {tableDetails.getNameOfTable()}); 163 } 164 165 169 170 private void setPlans(_TablePlan childPlans0[]) { 171 childPlans = childPlans0; 172 } 173 174 181 182 public void setJoinConditionOfChild(int index, _JoinRelation joinRelation) throws DException { 183 int type = childPlans[index].getType(); 184 if (type != TableExpressionConstants.SINGLETABLEPLAN) { 185 childPlans[index].merge(joinRelation); 186 } else { 187 ( (_SingleTablePlan) childPlans[index]).setCondition(joinRelation.getCondition()); 188 } 189 } 190 191 196 197 public _TablePlan[] getTablePlans() throws DException { 198 return this.childPlans; 199 } 200 201 208 209 public _TablePlan joinMissingLink() throws DException { 210 for (int i = 0; i < childPlans.length; i++) { 211 childPlans[i] = childPlans[i].joinMissingLink(); 212 } 213 return childPlans.length == 1 ? childPlans[0] : new NestedLoopJoinPlan(childPlans, remainingCondition); 214 } 215 216 223 224 public boolean containsOrderSequencePlan() throws DException { 225 return true; 226 } 227 228 233 234 public _TablePlan[] getChildTablePlans() throws DException { 235 return childPlans; 236 } 237 238 241 242 public _Iterator execute(_ServerSession session) throws DException { 243 244 throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); 245 } 246 247 public _Iterator execute(_ServerSession session, booleanvalueexpression condition) throws DException { 248 249 throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); 250 } 251 252 public _Iterator executeWithoutOrder(_ServerSession session) throws DException { 253 254 throw new java.lang.UnsupportedOperationException ("Method executeWithoutOrder() not yet implemented."); 255 } 256 257 public _Iterator executeWithOutOrder(_ServerSession session, booleanvalueexpression condition) throws DException { 258 259 throw new java.lang.UnsupportedOperationException ("Method executeWithOutOrder() not yet implemented."); 260 } 261 262 public double getCost(_ServerSession session, booleanvalueexpression condition) throws DException { 263 264 throw new java.lang.UnsupportedOperationException ("Method getCost() not yet implemented."); 265 } 266 267 public _Order getOrder() throws DException { 268 throw new java.lang.UnsupportedOperationException ("Method getOrder() not yet implemented." + getClass()); 269 } 270 271 } 272 | Popular Tags |