001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.heap.HeapConglomerateFactory
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.access.heap;
023:
024: import org.apache.derby.iapi.reference.SQLState;
025:
026: import org.apache.derby.iapi.services.io.FormatableBitSet;
027:
028: import org.apache.derby.iapi.services.monitor.ModuleControl;
029: import org.apache.derby.iapi.services.monitor.ModuleSupportable;
030: import org.apache.derby.iapi.services.monitor.Monitor;
031: import org.apache.derby.iapi.services.sanity.SanityManager;
032: import org.apache.derby.iapi.services.io.FormatIdUtil;
033: import org.apache.derby.iapi.error.StandardException;
034:
035: import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
036: import org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory;
037: import org.apache.derby.iapi.store.access.conglomerate.MethodFactory;
038: import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
039:
040: import org.apache.derby.iapi.store.access.AccessFactory;
041: import org.apache.derby.iapi.store.access.ColumnOrdering;
042: import org.apache.derby.iapi.store.access.ConglomerateController;
043: import org.apache.derby.iapi.store.access.Qualifier;
044:
045: import org.apache.derby.iapi.store.raw.ContainerHandle;
046: import org.apache.derby.iapi.store.raw.FetchDescriptor;
047: import org.apache.derby.iapi.store.raw.ContainerKey;
048: import org.apache.derby.iapi.store.raw.LockingPolicy;
049: import org.apache.derby.iapi.store.raw.Page;
050: import org.apache.derby.iapi.store.raw.RecordHandle;
051: import org.apache.derby.iapi.store.raw.Transaction;
052:
053: import org.apache.derby.iapi.types.DataValueDescriptor;
054:
055: import org.apache.derby.iapi.services.uuid.UUIDFactory;
056:
057: import org.apache.derby.catalog.UUID;
058:
059: import java.util.Properties;
060:
061: /**
062:
063: The heap conglomerate factory manages heap conglomerates implemented
064: on the raw store.
065:
066: **/
067:
068: public class HeapConglomerateFactory implements ConglomerateFactory,
069: ModuleControl, ModuleSupportable {
070:
071: // RESOLVE (mikem) (STO062)
072: // The heap implementation id should be "heap table".
073: private static final String IMPLEMENTATIONID = "heap";
074: private static final String FORMATUUIDSTRING = "D2976090-D9F5-11d0-B54D-00A024BF8878";
075: private UUID formatUUID;
076:
077: /*
078: * Methods of MethodFactory (via ConglomerateFactory)
079: */
080:
081: /**
082: Return the default properties for this kind of conglomerate.
083: @see MethodFactory#defaultProperties
084: **/
085: public Properties defaultProperties() {
086: // Heap has no properties.
087: return new Properties();
088: }
089:
090: /**
091: Return whether this access method implements the implementation
092: type given in the argument string.
093: The heap only has one implementation type, "heap".
094:
095: @see MethodFactory#supportsImplementation
096: **/
097: public boolean supportsImplementation(String implementationId) {
098: return implementationId.equals(IMPLEMENTATIONID);
099: }
100:
101: /**
102: Return the primary implementation type for this access method.
103: The heap only has one implementation type, "heap".
104:
105: @see MethodFactory#primaryImplementationType
106: **/
107: public String primaryImplementationType() {
108: return IMPLEMENTATIONID;
109: }
110:
111: /**
112: Return whether this access method supports the format supplied in
113: the argument.
114: The heap currently only supports one format, HEAPFORMAT1.
115:
116: @see MethodFactory#supportsFormat
117: **/
118: public boolean supportsFormat(UUID formatid) {
119: return formatid.equals(formatUUID);
120: }
121:
122: /**
123: Return the primary format that this access method supports.
124: The heap currently only supports one format, HEAPFORMAT1.
125:
126: @see MethodFactory#primaryFormat
127: **/
128: public UUID primaryFormat() {
129: return formatUUID;
130: }
131:
132: /*
133: ** Methods of ConglomerateFactory
134: */
135:
136: /**
137: * Return the conglomerate factory id.
138: * <p>
139: * Return a number in the range of 0-15 which identifies this factory.
140: * Code which names conglomerates depends on this range currently, but
141: * could be easily changed to handle larger ranges. One hex digit seemed
142: * reasonable for the number of conglomerate types being currently
143: * considered (heap, btree, gist, gist btree, gist rtree, hash, others? ).
144: * <p>
145: * @see ConglomerateFactory#getConglomerateFactoryId
146: *
147: * @return an unique identifier used to the factory into the conglomid.
148: *
149: **/
150: public int getConglomerateFactoryId() {
151: return (ConglomerateFactory.HEAP_FACTORY_ID);
152: }
153:
154: /**
155: Create the conglomerate and return a conglomerate object for it.
156:
157: @exception StandardException Standard exception policy.
158:
159: @see ConglomerateFactory#createConglomerate
160: **/
161: public Conglomerate createConglomerate(TransactionManager xact_mgr,
162: int segment, long input_containerid,
163: DataValueDescriptor[] template,
164: ColumnOrdering[] columnOrder, //only meant for BTree type congloms
165: Properties properties, int temporaryFlag)
166: throws StandardException {
167: //parent.register(heap);
168: Heap heap = new Heap();
169: heap.create(xact_mgr.getRawStoreXact(), segment,
170: input_containerid, template, properties, temporaryFlag);
171:
172: return heap;
173: }
174:
175: /**
176: * Return Conglomerate object for conglomerate with container_key.
177: * <p>
178: * Return the Conglomerate Object. This is implementation specific.
179: * Examples of what will be done is using the key to find the file where
180: * the conglomerate is located, and then executing implementation specific
181: * code to instantiate an object from reading a "special" row from a
182: * known location in the file. In the btree case the btree conglomerate
183: * is stored as a column in the control row on the root page.
184: * <p>
185: * This operation is costly so it is likely an implementation using this
186: * will cache the conglomerate row in memory so that subsequent accesses
187: * need not perform this operation.
188: *
189: * @param xact_mgr transaction to perform the create in.
190: * @param container_key The unique id of the existing conglomerate.
191: *
192: * @return An instance of the conglomerate.
193: *
194: * @exception StandardException Standard exception policy.
195: **/
196: public Conglomerate readConglomerate(TransactionManager xact_mgr,
197: ContainerKey container_key) throws StandardException {
198: ContainerHandle container = null;
199: Page page = null;
200: DataValueDescriptor[] control_row = new DataValueDescriptor[1];
201:
202: try {
203: // open container to read the Heap object out of it's control row.
204: container = xact_mgr.getRawStoreXact().openContainer(
205: container_key, (LockingPolicy) null, 0);
206:
207: if (container == null) {
208: throw StandardException.newException(
209: SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST,
210: new Long(container_key.getContainerId()));
211: }
212:
213: // row in slot 0 of heap page 1 which is just a single column with
214: // the heap entry.
215: control_row[0] = new Heap();
216:
217: page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
218:
219: RecordHandle rh = page.fetchFromSlot((RecordHandle) null,
220: 0, control_row, (FetchDescriptor) null, true);
221:
222: if (SanityManager.DEBUG) {
223: SanityManager.ASSERT(rh != null);
224:
225: // for now the control row is always the first id assigned on
226: // page 1.
227: SanityManager.ASSERT(rh.getId() == 6);
228: }
229: } finally {
230: if (page != null)
231: page.unlatch();
232:
233: if (container != null)
234: container.close();
235: }
236:
237: return ((Conglomerate) control_row[0]);
238: }
239:
240: /*
241: ** Methods of ModuleControl.
242: */
243:
244: public boolean canSupport(Properties startParams) {
245:
246: String impl = startParams
247: .getProperty("derby.access.Conglomerate.type");
248:
249: if (impl == null)
250: return false;
251:
252: return supportsImplementation(impl);
253: }
254:
255: public void boot(boolean create, Properties startParams)
256: throws StandardException {
257: // Find the UUID factory.
258: UUIDFactory uuidFactory = Monitor.getMonitor().getUUIDFactory();
259:
260: // Make a UUID that identifies this conglomerate's format.
261: formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);
262: }
263:
264: public void stop() {
265: }
266:
267: /*
268: ** Methods of HeapConglomerateFactory
269: */
270:
271: public HeapConglomerateFactory() {
272: }
273: }
|