KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > catalog > NameTDCacheable


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.NameTDCacheable
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.catalog;
23
24 import org.apache.derby.iapi.services.cache.Cacheable;
25
26 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
27 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
28
29 import org.apache.derby.iapi.error.StandardException;
30
31 import org.apache.derby.iapi.services.sanity.SanityManager;
32
33 /**
34  * This class implements a Cacheable for a DataDictionary cache of
35  * table descriptors, with the lookup key being the name of the table.
36  *
37  * Assumes client passes in a string that includes the schema name.
38  */

39 class NameTDCacheable extends TDCacheable
40 {
41     private TableKey identity;
42
43     NameTDCacheable(DataDictionaryImpl dd) {
44         super(dd);
45     }
46
47
48     /* Cacheable interface */
49
50     /** @see Cacheable#clearIdentity */
51     public void clearIdentity()
52     {
53         identity = null;
54         td = null;
55     }
56
57     /** @see Cacheable#getIdentity */
58     public Object JavaDoc getIdentity()
59     {
60         return identity;
61     }
62
63     /** @see Cacheable#createIdentity */
64     public Cacheable createIdentity(Object JavaDoc key, Object JavaDoc createParameter)
65     {
66         if (SanityManager.DEBUG)
67         {
68             if (!(key instanceof TableKey))
69             {
70                 SanityManager.THROWASSERT("Key for a NameTDCacheElement is a " +
71                     key.getClass().getName() +
72                     " instead of a TableKey");
73             }
74
75             if (!(createParameter instanceof TableDescriptor))
76             {
77                 SanityManager.THROWASSERT("Create parameter for a NameTDCacheElement is a " +
78                     createParameter.getClass().getName() +
79                     "instead of a TableDescriptorImpl");
80             }
81         }
82
83         identity = (TableKey)key;
84         td = (TableDescriptor) createParameter;
85
86         if (td != null)
87             return this;
88         else
89             return null;
90     }
91
92     /**
93      * @see Cacheable#setIdentity
94      *
95      * @exception StandardException Thrown on error
96      */

97     public Cacheable setIdentity(Object JavaDoc key) throws StandardException
98     {
99         if (SanityManager.DEBUG)
100         {
101             if (!(key instanceof TableKey))
102             {
103                 SanityManager.THROWASSERT("Key for a NameTDCacheElement is a " +
104                     key.getClass().getName() +
105                     " instead of a TableKey");
106             }
107         }
108
109         ;
110         td = dd.getUncachedTableDescriptor(identity = (TableKey)key);
111
112         if (td != null)
113         {
114             // add table descriptor to the oidTdcache in the Datadictionary.
115
// no fear of deadlocks because this is called outside the
116
// synchronize block in the cache code.
117
dd.addTableDescriptorToOtherCache(td, this);
118             return this;
119         }
120         else
121             return null;
122     }
123
124     /**
125       @exception StandardException Thrown on error
126       */

127     // If this code is required it should be moved into a D_ class. - djd
128

129 /*
130     public boolean isConsistent(HeaderPrintWriter reportInconsistent)
131         throws StandardException
132     {
133         boolean retval = true;
134
135         if (SanityManager.DEBUG)
136         {
137             TableDescriptor uncachedTD;
138
139             try
140             {
141                 uncachedTD = dd.getUncachedTableDescriptor(identity);
142             }
143             catch (StandardException se)
144             {
145                 reportInconsistent.println("Unexpected exception " + se +
146                   " while getting cached table descriptor in NameTDCacheable.");
147                 uncachedTD = null;
148             }
149
150             retval = checkConsistency(uncachedTD, identity, reportInconsistent);
151         }
152
153         return retval;
154     }
155     */

156 }
157
Popular Tags