KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > heap > HeapConglomerateFactory


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.heap.HeapConglomerateFactory
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.heap;
23
24 import org.apache.derby.iapi.reference.SQLState;
25
26 import org.apache.derby.iapi.services.io.FormatableBitSet;
27
28 import org.apache.derby.iapi.services.monitor.ModuleControl;
29 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
30 import org.apache.derby.iapi.services.monitor.Monitor;
31 import org.apache.derby.iapi.services.sanity.SanityManager;
32 import org.apache.derby.iapi.services.io.FormatIdUtil;
33 import org.apache.derby.iapi.error.StandardException;
34
35 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
36 import org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory;
37 import org.apache.derby.iapi.store.access.conglomerate.MethodFactory;
38 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
39
40 import org.apache.derby.iapi.store.access.AccessFactory;
41 import org.apache.derby.iapi.store.access.ColumnOrdering;
42 import org.apache.derby.iapi.store.access.ConglomerateController;
43 import org.apache.derby.iapi.store.access.Qualifier;
44
45 import org.apache.derby.iapi.store.raw.ContainerHandle;
46 import org.apache.derby.iapi.store.raw.FetchDescriptor;
47 import org.apache.derby.iapi.store.raw.ContainerKey;
48 import org.apache.derby.iapi.store.raw.LockingPolicy;
49 import org.apache.derby.iapi.store.raw.Page;
50 import org.apache.derby.iapi.store.raw.RecordHandle;
51 import org.apache.derby.iapi.store.raw.Transaction;
52
53 import org.apache.derby.iapi.types.DataValueDescriptor;
54
55 import org.apache.derby.iapi.services.uuid.UUIDFactory;
56
57 import org.apache.derby.catalog.UUID;
58
59 import java.util.Properties JavaDoc;
60
61 /**
62
63   The heap conglomerate factory manages heap conglomerates implemented
64   on the raw store.
65
66 **/

67
68 public class HeapConglomerateFactory implements ConglomerateFactory, ModuleControl, ModuleSupportable
69 {
70
71     // RESOLVE (mikem) (STO062)
72
// The heap implementation id should be "heap table".
73
private static final String JavaDoc IMPLEMENTATIONID = "heap";
74     private static final String JavaDoc FORMATUUIDSTRING = "D2976090-D9F5-11d0-B54D-00A024BF8878";
75     private UUID formatUUID;
76
77     /*
78      * Methods of MethodFactory (via ConglomerateFactory)
79      */

80
81     /**
82     Return the default properties for this kind of conglomerate.
83     @see MethodFactory#defaultProperties
84     **/

85     public Properties JavaDoc defaultProperties()
86     {
87         // Heap has no properties.
88
return new Properties JavaDoc();
89     }
90
91     /**
92     Return whether this access method implements the implementation
93     type given in the argument string.
94     The heap only has one implementation type, "heap".
95
96     @see MethodFactory#supportsImplementation
97     **/

98     public boolean supportsImplementation(String JavaDoc implementationId)
99     {
100         return implementationId.equals(IMPLEMENTATIONID);
101     }
102
103     /**
104     Return the primary implementation type for this access method.
105     The heap only has one implementation type, "heap".
106
107     @see MethodFactory#primaryImplementationType
108     **/

109     public String JavaDoc primaryImplementationType()
110     {
111         return IMPLEMENTATIONID;
112     }
113
114     /**
115     Return whether this access method supports the format supplied in
116     the argument.
117     The heap currently only supports one format, HEAPFORMAT1.
118
119     @see MethodFactory#supportsFormat
120     **/

121     public boolean supportsFormat(UUID formatid)
122     {
123         return formatid.equals(formatUUID);
124     }
125
126     /**
127     Return the primary format that this access method supports.
128     The heap currently only supports one format, HEAPFORMAT1.
129
130     @see MethodFactory#primaryFormat
131     **/

132     public UUID primaryFormat()
133     {
134         return formatUUID;
135     }
136
137     /*
138     ** Methods of ConglomerateFactory
139     */

140
141     /**
142      * Return the conglomerate factory id.
143      * <p>
144      * Return a number in the range of 0-15 which identifies this factory.
145      * Code which names conglomerates depends on this range currently, but
146      * could be easily changed to handle larger ranges. One hex digit seemed
147      * reasonable for the number of conglomerate types being currently
148      * considered (heap, btree, gist, gist btree, gist rtree, hash, others? ).
149      * <p>
150      * @see ConglomerateFactory#getConglomerateFactoryId
151      *
152      * @return an unique identifier used to the factory into the conglomid.
153      *
154      **/

155     public int getConglomerateFactoryId()
156     {
157         return(ConglomerateFactory.HEAP_FACTORY_ID);
158     }
159
160     /**
161     Create the conglomerate and return a conglomerate object for it.
162
163     @exception StandardException Standard exception policy.
164
165     @see ConglomerateFactory#createConglomerate
166     **/

167     public Conglomerate createConglomerate(
168     TransactionManager xact_mgr,
169     int segment,
170     long input_containerid,
171     DataValueDescriptor[] template,
172     ColumnOrdering[] columnOrder, //only meant for BTree type congloms
173
Properties JavaDoc properties,
174     int temporaryFlag)
175         throws StandardException
176     {
177         //parent.register(heap);
178
Heap heap = new Heap();
179         heap.create(
180             xact_mgr.getRawStoreXact(), segment, input_containerid,
181             template, properties, temporaryFlag);
182
183         return heap;
184     }
185
186     /**
187      * Return Conglomerate object for conglomerate with container_key.
188      * <p>
189      * Return the Conglomerate Object. This is implementation specific.
190      * Examples of what will be done is using the key to find the file where
191      * the conglomerate is located, and then executing implementation specific
192      * code to instantiate an object from reading a "special" row from a
193      * known location in the file. In the btree case the btree conglomerate
194      * is stored as a column in the control row on the root page.
195      * <p>
196      * This operation is costly so it is likely an implementation using this
197      * will cache the conglomerate row in memory so that subsequent accesses
198      * need not perform this operation.
199      *
200      * @param xact_mgr transaction to perform the create in.
201      * @param container_key The unique id of the existing conglomerate.
202      *
203      * @return An instance of the conglomerate.
204      *
205      * @exception StandardException Standard exception policy.
206      **/

207     public Conglomerate readConglomerate(
208     TransactionManager xact_mgr,
209     ContainerKey container_key)
210         throws StandardException
211     {
212         ContainerHandle container = null;
213         Page page = null;
214         DataValueDescriptor[] control_row = new DataValueDescriptor[1];
215
216         try
217         {
218             // open container to read the Heap object out of it's control row.
219
container =
220                 xact_mgr.getRawStoreXact().openContainer(
221                     container_key, (LockingPolicy) null, 0);
222
223             if (container == null)
224             {
225                 throw StandardException.newException(
226                     SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST,
227                     new Long JavaDoc(container_key.getContainerId()));
228             }
229
230             // row in slot 0 of heap page 1 which is just a single column with
231
// the heap entry.
232
control_row[0] = new Heap();
233
234             page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
235
236             RecordHandle rh =
237                 page.fetchFromSlot(
238                    (RecordHandle) null, 0, control_row,
239                    (FetchDescriptor) null,
240                    true);
241
242             if (SanityManager.DEBUG)
243             {
244                 SanityManager.ASSERT(rh != null);
245
246                 // for now the control row is always the first id assigned on
247
// page 1.
248
SanityManager.ASSERT(rh.getId() == 6);
249             }
250         }
251         finally
252         {
253             if (page != null)
254                 page.unlatch();
255
256             if (container != null)
257                 container.close();
258         }
259
260         return((Conglomerate) control_row[0]);
261     }
262
263     /*
264     ** Methods of ModuleControl.
265     */

266
267     public boolean canSupport(Properties JavaDoc startParams) {
268
269         String JavaDoc impl =
270             startParams.getProperty("derby.access.Conglomerate.type");
271
272         if (impl == null)
273             return false;
274
275         return supportsImplementation(impl);
276     }
277
278     public void boot(boolean create, Properties JavaDoc startParams)
279         throws StandardException
280     {
281         // Find the UUID factory.
282
UUIDFactory uuidFactory =
283             Monitor.getMonitor().getUUIDFactory();
284         
285         // Make a UUID that identifies this conglomerate's format.
286
formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
287     }
288
289     public void stop()
290     {
291     }
292
293     /*
294     ** Methods of HeapConglomerateFactory
295     */

296
297     public HeapConglomerateFactory()
298     {
299     }
300 }
301
302
Popular Tags