KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.TDCacheable
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 import org.apache.derby.iapi.services.cache.CacheManager;
26
27 import org.apache.derby.iapi.services.monitor.Monitor;
28
29 import org.apache.derby.iapi.services.sanity.SanityManager;
30
31 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
32
33 import org.apache.derby.iapi.error.StandardException;
34
35 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
36
37 /**
38  * This class implements a Cacheable for a DataDictionary cache of
39  * table descriptors. It is an abstract class - there is more than
40  * one cache of table descriptors per data dictionary, and this class
41  * provides the implementation that's common to all of them. The lookup
42  * key for the cache (the "identity" of the cache item) is provided by
43  * the subclass.
44  *
45  * Another design alternative was to make the table descriptors themselves
46  * the cacheable objects. This was rejected because: we would have only
47  * one way of caching table descriptors, and we need at least two (by UUID
48  * and by name); the contents of a table descriptor would have to be
49  * split out into a separate class, so it could be used as the createParameter
50  * to the createIdentity() method; the releasing of the Cacheable would
51  * have to be done when at the end of compilation by traversing the tree -
52  * by creating a separate Cacheable object, we can release the object within
53  * the getTableDescriptor() method after getting the table descriptor out
54  * of it.
55  */

56 abstract class TDCacheable implements Cacheable
57 {
58     protected TableDescriptor td;
59     protected final DataDictionaryImpl dd;
60
61     TDCacheable(DataDictionaryImpl dd) {
62         this.dd = dd;
63     }
64
65     /* Cacheable interface */
66
67     /** @see Cacheable#clean */
68     public void clean(boolean forRemove)
69     {
70         return;
71     }
72
73     /** @see Cacheable#isDirty */
74     public boolean isDirty()
75     {
76         return false;
77     }
78
79     /**
80      * Get the table descriptor that is associated with this Cacheable
81      */

82     public TableDescriptor getTableDescriptor()
83     {
84         return td;
85     }
86
87     /**
88      * Check the consistency of the table descriptor held by this TDCacheable
89      * versus an uncached table descriptor.
90      *
91      * @param uncachedTD The uncached descriptor to compare to
92      * @param identity The identity of the table descriptor
93      * @param reportInconsistent A HeaderPrintWriter to send complaints to
94      *
95      * @return true if the descriptors are the same, false if they're different
96      *
97      * @exception StandardException Thrown on error
98      */

99     protected boolean checkConsistency(TableDescriptor uncachedTD,
100                                         Object JavaDoc identity,
101                                         HeaderPrintWriter reportInconsistent)
102             throws StandardException
103     {
104         boolean retval = true;
105
106         if (SanityManager.DEBUG)
107         {
108             if (uncachedTD == null)
109             {
110                 reportInconsistent.println(
111                     "Inconsistent NameTDCacheable: identity = " + identity +
112                     ", uncached table descriptor not found.");
113                 retval = false;
114             }
115             else
116             {
117                 if (
118                     (uncachedTD.getHeapConglomerateId() !=
119                                         td.getHeapConglomerateId()) ||
120                     ( ! uncachedTD.getUUID().equals(td.getUUID())) ||
121                     ( ! uncachedTD.getSchemaName().equals(td.getSchemaName()))||
122                     ( ! uncachedTD.getName().equals(td.getName())) ||
123                     ( uncachedTD.getTableType() != td.getTableType())
124                 )
125                 {
126                     reportInconsistent.println(
127                         "Inconsistent NameTDCacheable: identity = " + identity +
128                         ", cached TD = " +
129                         td +
130                         ", uncached TD = " +
131                         uncachedTD);
132
133                     retval = false;
134                 }
135             }
136         }
137
138         return retval;
139     }
140 }
141
Popular Tags