001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.AccessPathImpl
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.sql.compile.AccessPath;
027: import org.apache.derby.iapi.sql.compile.CostEstimate;
028: import org.apache.derby.iapi.sql.compile.JoinStrategy;
029: import org.apache.derby.iapi.sql.compile.Optimizer;
030:
031: import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
032: import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
033: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
034: import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
035: import org.apache.derby.iapi.error.StandardException;
036: import org.apache.derby.iapi.reference.SQLState;
037:
038: class AccessPathImpl implements AccessPath {
039: ConglomerateDescriptor cd = null;
040: private CostEstimate costEstimate = null;
041: boolean coveringIndexScan = false;
042: boolean nonMatchingIndexScan = false;
043: JoinStrategy joinStrategy = null;
044: int lockMode;
045: Optimizer optimizer;
046: private String accessPathName = "";
047:
048: AccessPathImpl(Optimizer optimizer) {
049: this .optimizer = optimizer;
050: }
051:
052: /** @see AccessPath#setConglomerateDescriptor */
053: public void setConglomerateDescriptor(ConglomerateDescriptor cd) {
054: this .cd = cd;
055: }
056:
057: /** @see AccessPath#getConglomerateDescriptor */
058: public ConglomerateDescriptor getConglomerateDescriptor() {
059: return cd;
060: }
061:
062: /** @see AccessPath#setCostEstimate */
063: public void setCostEstimate(CostEstimate costEstimate) {
064: /*
065: ** CostEstimates are mutable, so keep the best cost estimate in
066: ** a copy.
067: */
068: if (this .costEstimate == null) {
069: if (costEstimate != null) {
070: this .costEstimate = costEstimate.cloneMe();
071: }
072: } else {
073: if (costEstimate == null)
074: this .costEstimate = null;
075: else
076: this .costEstimate.setCost(costEstimate);
077: }
078: }
079:
080: /** @see AccessPath#getCostEstimate */
081: public CostEstimate getCostEstimate() {
082: return costEstimate;
083: }
084:
085: /** @see AccessPath#setCoveringIndexScan */
086: public void setCoveringIndexScan(boolean coveringIndexScan) {
087: this .coveringIndexScan = coveringIndexScan;
088: }
089:
090: /** @see AccessPath#getCoveringIndexScan */
091: public boolean getCoveringIndexScan() {
092: return coveringIndexScan;
093: }
094:
095: /** @see AccessPath#setNonMatchingIndexScan */
096: public void setNonMatchingIndexScan(boolean nonMatchingIndexScan) {
097: this .nonMatchingIndexScan = nonMatchingIndexScan;
098: }
099:
100: /** @see AccessPath#getNonMatchingIndexScan */
101: public boolean getNonMatchingIndexScan() {
102: return nonMatchingIndexScan;
103: }
104:
105: /** @see AccessPath#setJoinStrategy */
106: public void setJoinStrategy(JoinStrategy joinStrategy) {
107: this .joinStrategy = joinStrategy;
108: }
109:
110: /** @see AccessPath#getJoinStrategy */
111: public JoinStrategy getJoinStrategy() {
112: return joinStrategy;
113: }
114:
115: /** @see AccessPath#setLockMode */
116: public void setLockMode(int lockMode) {
117: this .lockMode = lockMode;
118: }
119:
120: /** @see AccessPath#getLockMode */
121: public int getLockMode() {
122: return lockMode;
123: }
124:
125: /** @see AccessPath#copy */
126: public void copy(AccessPath copyFrom) {
127: setConglomerateDescriptor(copyFrom.getConglomerateDescriptor());
128: setCostEstimate(copyFrom.getCostEstimate());
129: setCoveringIndexScan(copyFrom.getCoveringIndexScan());
130: setNonMatchingIndexScan(copyFrom.getNonMatchingIndexScan());
131: setJoinStrategy(copyFrom.getJoinStrategy());
132: setLockMode(copyFrom.getLockMode());
133: }
134:
135: /** @see AccessPath#getOptimizer */
136: public Optimizer getOptimizer() {
137: return optimizer;
138: }
139:
140: public String toString() {
141: if (SanityManager.DEBUG) {
142: return "cd == " + cd + ", costEstimate == " + costEstimate
143: + ", coveringIndexScan == " + coveringIndexScan
144: + ", nonMatchingIndexScan == "
145: + nonMatchingIndexScan + ", joinStrategy == "
146: + joinStrategy + ", lockMode == " + lockMode
147: + ", optimizer level == " + optimizer.getLevel();
148: } else {
149: return "";
150: }
151: }
152:
153: /** @see AccessPath#initializeAccessPathName */
154: public void initializeAccessPathName(DataDictionary dd,
155: TableDescriptor td) throws StandardException {
156: if (cd == null)
157: return;
158:
159: if (cd.isConstraint()) {
160: ConstraintDescriptor constraintDesc = dd
161: .getConstraintDescriptor(td, cd.getUUID());
162: if (constraintDesc == null) {
163: throw StandardException.newException(
164: SQLState.LANG_OBJECT_NOT_FOUND,
165: "CONSTRAINT on TABLE", td.getName());
166: }
167: accessPathName = constraintDesc.getConstraintName();
168: } else if (cd.isIndex()) {
169: accessPathName = cd.getConglomerateName();
170: } else {
171: accessPathName = "";
172: }
173: }
174: }
|