KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.HashNodeList
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.error.StandardException;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import java.util.Hashtable JavaDoc;
29 import java.util.Enumeration JavaDoc;
30
31
32 /**
33  * HashNodeList is the root class for all hashlists of query tree nodes.
34  * It implements the QueryTree interface that is part of the Language
35  * protocols
36  *
37  * @author Rick Hillegas
38  */

39
40
41 public abstract class HashNodeList extends QueryTreeNode
42 {
43     private Hashtable JavaDoc hashtable = new Hashtable JavaDoc();
44
45     /////////////////////////////////////////////////////////////////
46
//
47
// HASHTABLE FORWARDS
48
//
49
/////////////////////////////////////////////////////////////////
50

51     /**
52       * Add an element to this hash list.
53       *
54       * @param key hash key for new value
55       * @param value new item to add to list
56       *
57       */

58     public void add( Object JavaDoc key, Object JavaDoc value )
59     {
60         hashtable.put( key, value );
61     }
62
63
64     /**
65       * Returns the size of the list.
66       *
67       * @return size of the list
68       */

69     public int size() { return hashtable.size(); }
70
71     /**
72       * Get an iterator to walk this hash list
73       *
74       * @return an Enumeration for walking this hash list
75       */

76     public Enumeration JavaDoc elements()
77     {
78         return hashtable.elements();
79     }
80
81
82     /**
83       * Gets an element by key
84       *
85       * @param key hash key to lookup
86       *
87       * @return the element associated with the hash key
88       * null if no element with that key exists
89       *
90       */

91     public Object JavaDoc get( Object JavaDoc key )
92     {
93         return hashtable.get( key );
94     }
95
96
97     /////////////////////////////////////////////////////////////////
98
//
99
// OBJECT SUPPORT
100
//
101
/////////////////////////////////////////////////////////////////
102

103     /**
104      * Convert this object to a String. See comments in QueryTreeNode.java
105      * for how this should be done for tree printing.
106      *
107      * @return This object as a String
108      */

109
110     public String JavaDoc toString()
111     {
112         if (SanityManager.DEBUG)
113         {
114             Enumeration JavaDoc iterator;
115             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("");
116             Object JavaDoc item;
117
118             for (iterator = elements(); iterator.hasMoreElements() == true; )
119             {
120                 item = iterator.nextElement();
121                 buffer.append(item.toString());
122                 buffer.append("\n");
123             }
124
125             return buffer.toString();
126         }
127         else
128         {
129             return "";
130         }
131     }
132
133     /////////////////////////////////////////////////////////////////
134
//
135
// QUERY TREE NODE METHODS
136
//
137
/////////////////////////////////////////////////////////////////
138

139     /**
140      * Get the optimizer's cost estimate for an optimized QueryTree.
141      * For non-optimizable statements (for example, CREATE TABLE),
142      * return null. For optimizable statements, this method will be
143      * over-ridden in the statement's root node (DMLStatementNode in
144      * all cases we know about so far).
145      *
146      * @return null
147      */

148     // public CostEstimate getCostEstimate()
149
// {
150
// return null;
151
// }
152

153     /**
154      * Returns whether or not this Statement requires a set/clear savepoint
155      * around its execution. The following statement "types" do not require them:
156      * Cursor - unnecessary and won't work in a read only environment
157      * Xact - savepoint will get blown away underneath us during commit/rollback
158      *
159      * @return boolean Whether or not this Statement requires a set/clear savepoint
160      */

161     public boolean needsSavepoint()
162     {
163         if (SanityManager.DEBUG)
164         {
165             SanityManager.ASSERT(false,
166                 "needsSavepoint() not expected to be called.");
167         }
168         return false;
169     }
170 }
171
Popular Tags