KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > CacheableConglomerate


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.CacheableConglomerate
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.store.access;
23
24 import java.util.Properties JavaDoc;
25 import org.apache.derby.iapi.services.cache.Cacheable;
26 import org.apache.derby.iapi.services.cache.CacheManager;
27 import org.apache.derby.iapi.services.sanity.SanityManager;
28 import org.apache.derby.iapi.error.StandardException;
29 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
30
31 /**
32 The CacheableConglomerate implements a single item in the cache used by
33 the Conglomerate directory to cache Conglomerates. It is simply a wrapper
34 object for the conglomid and Conglomerate object that is read from the
35 Conglomerate Conglomerate. It is a wrapper rather than extending
36 the conglomerate implementations because we want to cache all conglomerate
37 implementatations: (ie. Heap, B2I, ...).
38
39 References to the Conglomerate objects cached by this wrapper will be handed
40 out to callers. When this this object goes out of cache callers may still
41 have references to the Conglomerate objects, which we are counting on java
42 to garbage collect. The Conglomerate Objects never change after they are
43 created.
44
45 **/

46
47 class CacheableConglomerate implements Cacheable
48 {
49     private Long JavaDoc conglomid;
50     private Conglomerate conglom;
51
52     /* Constructor */
53     CacheableConglomerate()
54     {
55     }
56
57     /*
58     ** protected Methods of CacheableConglomerate:
59     */

60     protected Conglomerate getConglom()
61     {
62         return(this.conglom);
63     }
64
65     /*
66     ** Methods of Cacheable:
67     */

68
69     /**
70         Set the identity of the object to represent an item that already exists,
71         e.g. an existing container.
72         The object will be in the No Identity state,
73         ie. it will have just been created or clearIdentity() was just called.
74         <BR>
75         The object must copy the information out of key, not just store a reference to key.
76         After this call the expression getIdentity().equals(key) must return true.
77         <BR>
78         If the class of the object needs to change (e.g. to support a different format)
79         then the object should create a new object, call its initParameter() with the parameters
80         the original object was called with, set its identity and return a reference to it. The cache
81         manager will discard the reference to the old object.
82         <BR>
83         If an exception is thrown the object must be left in the no-identity state.
84
85         <BR> MT - single thread required - Method must only be called be cache manager
86         and the cache manager will guarantee only one thread can be calling it.
87
88         @return an object reference if the object can take on the identity, null otherwise.
89
90         @exception StandardException Standard Cloudscape Policy
91
92         @see CacheManager#find
93
94     */

95     public Cacheable setIdentity(Object JavaDoc key) throws StandardException
96     {
97         if (SanityManager.DEBUG) {
98             SanityManager.THROWASSERT("not supported.");
99         }
100
101         return(null);
102     }
103
104     /**
105      * Create a new item and set the identity of the object to represent it.
106      * The object will be in the No Identity state,
107      * ie. it will have just been created or clearIdentity() was just called.
108      * <BR>
109      * The object must copy the information out of key, not just store a
110      * reference to key. After this call the expression
111      * getIdentity().equals(key) must return true.
112      * <BR>
113      * If the class of the object needs to change (e.g. to support a different
114      * format) then the object should create a new object, call its
115      * initParameter() with the parameters the original object was called with,
116      * set its identity and return a reference to it. The cache manager will
117      * discard the reference to the old object.
118      * <BR>
119      * If an exception is thrown the object must be left in the no-identity
120      * state.
121      * <BR> MT - single thread required - Method must only be called be cache
122      * manager and the cache manager will guarantee only one thread can be
123      * calling it.
124      *
125      * @return an object reference if the object can take on the identity,
126      * null otherwise.
127      *
128      * @exception StandardException If forCreate is true and the object cannot
129      * be created.
130      *
131      * @see CacheManager#create
132      **/

133     public Cacheable createIdentity(Object JavaDoc key, Object JavaDoc createParameter)
134         throws StandardException
135     {
136         if (SanityManager.DEBUG)
137         {
138             SanityManager.ASSERT(
139                 key instanceof Long JavaDoc, "key is not instanceof Long");
140             SanityManager.ASSERT(
141                 createParameter instanceof Conglomerate,
142                 "createParameter is not instanceof Conglomerate");
143         }
144
145         this.conglomid = (Long JavaDoc) key;
146         this.conglom = ((Conglomerate) createParameter);
147
148         return(this);
149     }
150
151     /**
152         Put the object into the No Identity state.
153
154         <BR> MT - single thread required - Method must only be called be cache manager
155         and the cache manager will guarantee only one thread can be calling it.
156
157     */

158     public void clearIdentity()
159     {
160         this.conglomid = null;
161         this.conglom = null;
162     }
163
164     /**
165         Get the identity of this object.
166
167         <BR> MT - thread safe.
168
169     */

170     public Object JavaDoc getIdentity()
171     {
172         return(this.conglomid);
173     }
174
175
176     /**
177         Returns true of the object is dirty. Will only be called when the object is unkept.
178
179         <BR> MT - thread safe
180
181     */

182     public boolean isDirty()
183     {
184         return(false);
185     }
186
187     /**
188         Clean the object.
189         It is up to the object to ensure synchronization of the isDirty()
190         and clean() method calls.
191         <BR>
192         If forRemove is true then the
193         object is being removed due to an explict remove request, in this case
194         the cache manager will have called this method regardless of the
195         state of the isDirty()
196
197         <BR>
198         If an exception is thrown the object must be left in the clean state.
199
200         <BR> MT - thread safe - Can be called at any time by the cache manager, it is the
201         responsibility of the object implementing Cacheable to ensure any users of the
202         object do not conflict with the clean call.
203
204         @exception StandardException Standard Cloudscape error policy.
205
206     */

207     public void clean(boolean forRemove) throws StandardException
208     {
209     }
210 }
211
Popular Tags