--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.AccessPathImpl\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.sql.compile.AccessPath;\r
+import org.apache.derby.iapi.sql.compile.CostEstimate;\r
+import org.apache.derby.iapi.sql.compile.JoinStrategy;\r
+import org.apache.derby.iapi.sql.compile.Optimizer;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+class AccessPathImpl implements AccessPath\r
+{\r
+ ConglomerateDescriptor cd = null;\r
+ private CostEstimate costEstimate = null;\r
+ boolean coveringIndexScan = false;\r
+ boolean nonMatchingIndexScan = false;\r
+ JoinStrategy joinStrategy = null;\r
+ int lockMode;\r
+ Optimizer optimizer;\r
+ private String accessPathName = "";\r
+\r
+ AccessPathImpl(Optimizer optimizer)\r
+ {\r
+ this.optimizer = optimizer;\r
+ }\r
+\r
+ /** @see AccessPath#setConglomerateDescriptor */\r
+ public void setConglomerateDescriptor(ConglomerateDescriptor cd)\r
+ {\r
+ this.cd = cd;\r
+ }\r
+\r
+ /** @see AccessPath#getConglomerateDescriptor */\r
+ public ConglomerateDescriptor getConglomerateDescriptor()\r
+ {\r
+ return cd;\r
+ }\r
+\r
+ /** @see AccessPath#setCostEstimate */\r
+ public void setCostEstimate(CostEstimate costEstimate)\r
+ {\r
+ /*\r
+ ** CostEstimates are mutable, so keep the best cost estimate in\r
+ ** a copy.\r
+ */\r
+ if (this.costEstimate == null)\r
+ {\r
+ if (costEstimate != null)\r
+ {\r
+ this.costEstimate = costEstimate.cloneMe();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (costEstimate == null)\r
+ this.costEstimate = null;\r
+ else\r
+ this.costEstimate.setCost(costEstimate);\r
+ }\r
+ }\r
+\r
+ /** @see AccessPath#getCostEstimate */\r
+ public CostEstimate getCostEstimate()\r
+ {\r
+ return costEstimate;\r
+ }\r
+\r
+ /** @see AccessPath#setCoveringIndexScan */\r
+ public void setCoveringIndexScan(boolean coveringIndexScan)\r
+ {\r
+ this.coveringIndexScan = coveringIndexScan;\r
+ }\r
+\r
+ /** @see AccessPath#getCoveringIndexScan */\r
+ public boolean getCoveringIndexScan()\r
+ {\r
+ return coveringIndexScan;\r
+ }\r
+\r
+ /** @see AccessPath#setNonMatchingIndexScan */\r
+ public void setNonMatchingIndexScan(boolean nonMatchingIndexScan)\r
+ {\r
+ this.nonMatchingIndexScan = nonMatchingIndexScan;\r
+ }\r
+\r
+ /** @see AccessPath#getNonMatchingIndexScan */\r
+ public boolean getNonMatchingIndexScan()\r
+ {\r
+ return nonMatchingIndexScan;\r
+ }\r
+\r
+ /** @see AccessPath#setJoinStrategy */\r
+ public void setJoinStrategy(JoinStrategy joinStrategy)\r
+ {\r
+ this.joinStrategy = joinStrategy;\r
+ }\r
+\r
+ /** @see AccessPath#getJoinStrategy */\r
+ public JoinStrategy getJoinStrategy()\r
+ {\r
+ return joinStrategy;\r
+ }\r
+\r
+ /** @see AccessPath#setLockMode */\r
+ public void setLockMode(int lockMode)\r
+ {\r
+ this.lockMode = lockMode;\r
+ }\r
+\r
+ /** @see AccessPath#getLockMode */\r
+ public int getLockMode()\r
+ {\r
+ return lockMode;\r
+ }\r
+\r
+ /** @see AccessPath#copy */\r
+ public void copy(AccessPath copyFrom)\r
+ {\r
+ setConglomerateDescriptor(copyFrom.getConglomerateDescriptor());\r
+ setCostEstimate(copyFrom.getCostEstimate());\r
+ setCoveringIndexScan(copyFrom.getCoveringIndexScan());\r
+ setNonMatchingIndexScan(copyFrom.getNonMatchingIndexScan());\r
+ setJoinStrategy(copyFrom.getJoinStrategy());\r
+ setLockMode(copyFrom.getLockMode());\r
+ }\r
+\r
+ /** @see AccessPath#getOptimizer */\r
+ public Optimizer getOptimizer()\r
+ {\r
+ return optimizer;\r
+ }\r
+\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ return "cd == " + cd +\r
+ ", costEstimate == " + costEstimate +\r
+ ", coveringIndexScan == " + coveringIndexScan +\r
+ ", nonMatchingIndexScan == " + nonMatchingIndexScan +\r
+ ", joinStrategy == " + joinStrategy +\r
+ ", lockMode == " + lockMode +\r
+ ", optimizer level == " + optimizer.getLevel();\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+ }\r
+ \r
+ /** @see AccessPath#initializeAccessPathName */\r
+ public void initializeAccessPathName(DataDictionary dd, TableDescriptor td)\r
+ throws StandardException\r
+ {\r
+ if (cd == null)\r
+ return;\r
+\r
+ if (cd.isConstraint())\r
+ {\r
+ ConstraintDescriptor constraintDesc = \r
+ dd.getConstraintDescriptor(td, cd.getUUID());\r
+ if (constraintDesc == null)\r
+ {\r
+ throw StandardException.newException(\r
+ SQLState.LANG_OBJECT_NOT_FOUND,\r
+ "CONSTRAINT on TABLE",\r
+ td.getName());\r
+ }\r
+ accessPathName = constraintDesc.getConstraintName();\r
+ } \r
+ else if (cd.isIndex())\r
+ {\r
+ accessPathName = cd.getConglomerateName();\r
+ } \r
+ else \r
+ {\r
+ accessPathName = "";\r
+ } \r
+ }\r
+}\r