KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > AccessPathImpl


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.AccessPathImpl
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

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 JavaDoc accessPathName = "";
48
49     AccessPathImpl(Optimizer optimizer)
50     {
51         this.optimizer = optimizer;
52     }
53
54     /** @see AccessPath#setConglomerateDescriptor */
55     public void setConglomerateDescriptor(ConglomerateDescriptor cd)
56     {
57         this.cd = cd;
58     }
59
60     /** @see AccessPath#getConglomerateDescriptor */
61     public ConglomerateDescriptor getConglomerateDescriptor()
62     {
63         return cd;
64     }
65
66     /** @see AccessPath#setCostEstimate */
67     public void setCostEstimate(CostEstimate costEstimate)
68     {
69         /*
70         ** CostEstimates are mutable, so keep the best cost estimate in
71         ** a copy.
72         */

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     /** @see AccessPath#getCostEstimate */
90     public CostEstimate getCostEstimate()
91     {
92         return costEstimate;
93     }
94
95     /** @see AccessPath#setCoveringIndexScan */
96     public void setCoveringIndexScan(boolean coveringIndexScan)
97     {
98         this.coveringIndexScan = coveringIndexScan;
99     }
100
101     /** @see AccessPath#getCoveringIndexScan */
102     public boolean getCoveringIndexScan()
103     {
104         return coveringIndexScan;
105     }
106
107     /** @see AccessPath#setNonMatchingIndexScan */
108     public void setNonMatchingIndexScan(boolean nonMatchingIndexScan)
109     {
110         this.nonMatchingIndexScan = nonMatchingIndexScan;
111     }
112
113     /** @see AccessPath#getNonMatchingIndexScan */
114     public boolean getNonMatchingIndexScan()
115     {
116         return nonMatchingIndexScan;
117     }
118
119     /** @see AccessPath#setJoinStrategy */
120     public void setJoinStrategy(JoinStrategy joinStrategy)
121     {
122         this.joinStrategy = joinStrategy;
123     }
124
125     /** @see AccessPath#getJoinStrategy */
126     public JoinStrategy getJoinStrategy()
127     {
128         return joinStrategy;
129     }
130
131     /** @see AccessPath#setLockMode */
132     public void setLockMode(int lockMode)
133     {
134         this.lockMode = lockMode;
135     }
136
137     /** @see AccessPath#getLockMode */
138     public int getLockMode()
139     {
140         return lockMode;
141     }
142
143     /** @see AccessPath#copy */
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     /** @see AccessPath#getOptimizer */
155     public Optimizer getOptimizer()
156     {
157         return optimizer;
158     }
159
160     public String JavaDoc 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     /** @see AccessPath#initializeAccessPathName */
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