1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.sql.compile.AccessPath; 27 import org.apache.derby.iapi.sql.compile.CostEstimate; 28 import org.apache.derby.iapi.sql.compile.JoinStrategy; 29 import org.apache.derby.iapi.sql.compile.Optimizer; 30 31 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 32 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 33 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 34 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor; 35 import org.apache.derby.iapi.error.StandardException; 36 import org.apache.derby.iapi.reference.SQLState; 37 38 class AccessPathImpl implements AccessPath 39 { 40 ConglomerateDescriptor cd = null; 41 private CostEstimate costEstimate = null; 42 boolean coveringIndexScan = false; 43 boolean nonMatchingIndexScan = false; 44 JoinStrategy joinStrategy = null; 45 int lockMode; 46 Optimizer optimizer; 47 private String accessPathName = ""; 48 49 AccessPathImpl(Optimizer optimizer) 50 { 51 this.optimizer = optimizer; 52 } 53 54 55 public void setConglomerateDescriptor(ConglomerateDescriptor cd) 56 { 57 this.cd = cd; 58 } 59 60 61 public ConglomerateDescriptor getConglomerateDescriptor() 62 { 63 return cd; 64 } 65 66 67 public void setCostEstimate(CostEstimate costEstimate) 68 { 69 73 if (this.costEstimate == null) 74 { 75 if (costEstimate != null) 76 { 77 this.costEstimate = costEstimate.cloneMe(); 78 } 79 } 80 else 81 { 82 if (costEstimate == null) 83 this.costEstimate = null; 84 else 85 this.costEstimate.setCost(costEstimate); 86 } 87 } 88 89 90 public CostEstimate getCostEstimate() 91 { 92 return costEstimate; 93 } 94 95 96 public void setCoveringIndexScan(boolean coveringIndexScan) 97 { 98 this.coveringIndexScan = coveringIndexScan; 99 } 100 101 102 public boolean getCoveringIndexScan() 103 { 104 return coveringIndexScan; 105 } 106 107 108 public void setNonMatchingIndexScan(boolean nonMatchingIndexScan) 109 { 110 this.nonMatchingIndexScan = nonMatchingIndexScan; 111 } 112 113 114 public boolean getNonMatchingIndexScan() 115 { 116 return nonMatchingIndexScan; 117 } 118 119 120 public void setJoinStrategy(JoinStrategy joinStrategy) 121 { 122 this.joinStrategy = joinStrategy; 123 } 124 125 126 public JoinStrategy getJoinStrategy() 127 { 128 return joinStrategy; 129 } 130 131 132 public void setLockMode(int lockMode) 133 { 134 this.lockMode = lockMode; 135 } 136 137 138 public int getLockMode() 139 { 140 return lockMode; 141 } 142 143 144 public void copy(AccessPath copyFrom) 145 { 146 setConglomerateDescriptor(copyFrom.getConglomerateDescriptor()); 147 setCostEstimate(copyFrom.getCostEstimate()); 148 setCoveringIndexScan(copyFrom.getCoveringIndexScan()); 149 setNonMatchingIndexScan(copyFrom.getNonMatchingIndexScan()); 150 setJoinStrategy(copyFrom.getJoinStrategy()); 151 setLockMode(copyFrom.getLockMode()); 152 } 153 154 155 public Optimizer getOptimizer() 156 { 157 return optimizer; 158 } 159 160 public String toString() 161 { 162 if (SanityManager.DEBUG) 163 { 164 return "cd == " + cd + 165 ", costEstimate == " + costEstimate + 166 ", coveringIndexScan == " + coveringIndexScan + 167 ", nonMatchingIndexScan == " + nonMatchingIndexScan + 168 ", joinStrategy == " + joinStrategy + 169 ", lockMode == " + lockMode + 170 ", optimizer level == " + optimizer.getLevel(); 171 } 172 else 173 { 174 return ""; 175 } 176 } 177 178 179 public void initializeAccessPathName(DataDictionary dd, TableDescriptor td) 180 throws StandardException 181 { 182 if (cd == null) 183 return; 184 185 if (cd.isConstraint()) 186 { 187 ConstraintDescriptor constraintDesc = 188 dd.getConstraintDescriptor(td, cd.getUUID()); 189 if (constraintDesc == null) 190 { 191 throw StandardException.newException( 192 SQLState.LANG_OBJECT_NOT_FOUND, 193 "CONSTRAINT on TABLE", 194 td.getName()); 195 } 196 accessPathName = constraintDesc.getConstraintName(); 197 } 198 else if (cd.isIndex()) 199 { 200 accessPathName = cd.getConglomerateName(); 201 } 202 else 203 { 204 accessPathName = ""; 205 } 206 } 207 } 208 | Popular Tags |