KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.OIDTDCacheable
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.TableDescriptor;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import org.apache.derby.iapi.services.sanity.SanityManager;
31
32 import org.apache.derby.catalog.UUID;
33
34 /**
35  * This class implements a Cacheable for a DataDictionary cache of
36  * table descriptors, with the lookup key being the UUID of the table.
37  */

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

94     public Cacheable setIdentity(Object JavaDoc key) throws StandardException
95     {
96         if (SanityManager.DEBUG)
97         {
98             if (!(key instanceof UUID))
99             {
100                 SanityManager.THROWASSERT("Key for an OIDTDCacheElement is a " +
101                     key.getClass().getName() +
102                     " instead of an UUID");
103             }
104         }
105
106         identity = ((UUID) key).cloneMe();
107         td = dd.getUncachedTableDescriptor(identity);
108
109         if (td != null)
110         {
111             // Add cache entry to the nameTdCache in the DataDictionary.
112
dd.addTableDescriptorToOtherCache(td, this);
113             return this;
114         }
115         else
116             return null;
117     }
118
119     /**
120       @exception StandardException Thrown on error
121       */

122     // If this code is required it should be moved into a D_ class. - djd
123
/*
124     public boolean isConsistent(HeaderPrintWriter reportInconsistent)
125         throws StandardException
126     {
127         boolean retval = true;
128
129         if (SanityManager.DEBUG)
130         {
131             TableDescriptor uncachedTD;
132
133             try
134             {
135                 uncachedTD = dd.getUncachedTableDescriptor(identity);
136             }
137             catch (StandardException se)
138             {
139                 reportInconsistent.println("Unexpected exception " + se +
140                   " while getting cached table descriptor in OIDTDCacheable.");
141                 uncachedTD = null;
142             }
143
144             retval = checkConsistency(uncachedTD, identity, reportInconsistent);
145         }
146
147         return retval;
148     }
149     */

150 }
151
Popular Tags