--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.store.access.heap.HeapConglomerateFactory\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.store.access.heap;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.services.monitor.ModuleControl;\r
+import org.apache.derby.iapi.services.monitor.ModuleSupportable;\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;\r
+import org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory;\r
+import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;\r
+\r
+import org.apache.derby.iapi.store.access.ColumnOrdering;\r
+\r
+import org.apache.derby.iapi.store.raw.ContainerHandle;\r
+import org.apache.derby.iapi.store.raw.FetchDescriptor;\r
+import org.apache.derby.iapi.store.raw.ContainerKey;\r
+import org.apache.derby.iapi.store.raw.LockingPolicy;\r
+import org.apache.derby.iapi.store.raw.Page;\r
+import org.apache.derby.iapi.store.raw.RawStoreFactory;\r
+import org.apache.derby.iapi.store.raw.RecordHandle;\r
+\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.iapi.services.uuid.UUIDFactory;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import java.util.Properties;\r
+\r
+// For JavaDoc references (i.e. @see)\r
+import org.apache.derby.iapi.store.access.conglomerate.MethodFactory;\r
+\r
+/**\r
+\r
+ The heap conglomerate factory manages heap conglomerates implemented\r
+ on the raw store.\r
+\r
+**/\r
+\r
+public class HeapConglomerateFactory implements ConglomerateFactory, ModuleControl, ModuleSupportable\r
+{\r
+\r
+ private static final String IMPLEMENTATIONID = "heap";\r
+ private static final String FORMATUUIDSTRING = "D2976090-D9F5-11d0-B54D-00A024BF8878";\r
+ private UUID formatUUID;\r
+\r
+ /*\r
+ * Methods of MethodFactory (via ConglomerateFactory)\r
+ */\r
+\r
+ /**\r
+ Return the default properties for this kind of conglomerate.\r
+ @see MethodFactory#defaultProperties\r
+ **/\r
+ public Properties defaultProperties()\r
+ {\r
+ // Heap has no properties.\r
+ return new Properties();\r
+ }\r
+\r
+ /**\r
+ Return whether this access method implements the implementation\r
+ type given in the argument string.\r
+ The heap only has one implementation type, "heap".\r
+\r
+ @see MethodFactory#supportsImplementation\r
+ **/\r
+ public boolean supportsImplementation(String implementationId)\r
+ {\r
+ return implementationId.equals(IMPLEMENTATIONID);\r
+ }\r
+\r
+ /**\r
+ Return the primary implementation type for this access method.\r
+ The heap only has one implementation type, "heap".\r
+\r
+ @see MethodFactory#primaryImplementationType\r
+ **/\r
+ public String primaryImplementationType()\r
+ {\r
+ return IMPLEMENTATIONID;\r
+ }\r
+\r
+ /**\r
+ Return whether this access method supports the format supplied in\r
+ the argument.\r
+ The heap currently only supports one format, HEAPFORMAT1.\r
+\r
+ @see MethodFactory#supportsFormat\r
+ **/\r
+ public boolean supportsFormat(UUID formatid)\r
+ {\r
+ return formatid.equals(formatUUID);\r
+ }\r
+\r
+ /**\r
+ Return the primary format that this access method supports.\r
+ The heap currently only supports one format, HEAPFORMAT1.\r
+\r
+ @see MethodFactory#primaryFormat\r
+ **/\r
+ public UUID primaryFormat()\r
+ {\r
+ return formatUUID;\r
+ }\r
+\r
+ /*\r
+ ** Methods of ConglomerateFactory\r
+ */\r
+\r
+ /**\r
+ * Return the conglomerate factory id.\r
+ * <p>\r
+ * Return a number in the range of 0-15 which identifies this factory.\r
+ * Code which names conglomerates depends on this range currently, but\r
+ * could be easily changed to handle larger ranges. One hex digit seemed\r
+ * reasonable for the number of conglomerate types being currently \r
+ * considered (heap, btree, gist, gist btree, gist rtree, hash, others? ).\r
+ * <p>\r
+ * @see ConglomerateFactory#getConglomerateFactoryId\r
+ *\r
+ * @return an unique identifier used to the factory into the conglomid.\r
+ *\r
+ **/\r
+ public int getConglomerateFactoryId()\r
+ {\r
+ return(ConglomerateFactory.HEAP_FACTORY_ID);\r
+ }\r
+\r
+ /**\r
+ Create the conglomerate and return a conglomerate object for it.\r
+\r
+ @exception StandardException Standard exception policy.\r
+\r
+ @see ConglomerateFactory#createConglomerate\r
+ **/\r
+ public Conglomerate createConglomerate( \r
+ TransactionManager xact_mgr,\r
+ int segment,\r
+ long input_containerid,\r
+ DataValueDescriptor[] template,\r
+ ColumnOrdering[] columnOrder,\r
+ int[] collationIds,\r
+ Properties properties,\r
+ int temporaryFlag)\r
+ throws StandardException\r
+ {\r
+ Heap heap = null;\r
+\r
+\r
+ if (xact_mgr.checkVersion(\r
+ RawStoreFactory.DERBY_STORE_MAJOR_VERSION_10,\r
+ RawStoreFactory.DERBY_STORE_MINOR_VERSION_3,\r
+ null))\r
+ {\r
+ // on disk databases with version higher than 10.2 should use\r
+ // current disk format B2I. This includes new databases or\r
+ // hard upgraded databases.\r
+ heap = new Heap();\r
+ }\r
+ else\r
+ {\r
+ // Old databases that are running in new versions of the software,\r
+ // but are running in soft upgrade mode at release level 10.2\r
+ // and before should use the old B2I version. This version will\r
+ // continue to write metadata that can be read by 10.2 and previous\r
+ // versions.\r
+ heap = new Heap_v10_2();\r
+ }\r
+\r
+ heap.create(\r
+ xact_mgr.getRawStoreXact(), segment, input_containerid, \r
+ template, columnOrder, collationIds, properties, \r
+ heap.getTypeFormatId(), \r
+ temporaryFlag);\r
+\r
+ return heap;\r
+ }\r
+\r
+ /**\r
+ * Return Conglomerate object for conglomerate with container_key.\r
+ * <p>\r
+ * Return the Conglomerate Object. This is implementation specific.\r
+ * Examples of what will be done is using the key to find the file where\r
+ * the conglomerate is located, and then executing implementation specific\r
+ * code to instantiate an object from reading a "special" row from a\r
+ * known location in the file. In the btree case the btree conglomerate\r
+ * is stored as a column in the control row on the root page.\r
+ * <p>\r
+ * This operation is costly so it is likely an implementation using this\r
+ * will cache the conglomerate row in memory so that subsequent accesses\r
+ * need not perform this operation.\r
+ *\r
+ * @param xact_mgr transaction to perform the create in.\r
+ * @param container_key The unique id of the existing conglomerate.\r
+ *\r
+ * @return An instance of the conglomerate.\r
+ *\r
+ * @exception StandardException Standard exception policy.\r
+ **/\r
+ public Conglomerate readConglomerate(\r
+ TransactionManager xact_mgr,\r
+ ContainerKey container_key)\r
+ throws StandardException\r
+ {\r
+ ContainerHandle container = null;\r
+ Page page = null;\r
+ DataValueDescriptor[] control_row = new DataValueDescriptor[1];\r
+\r
+ try\r
+ {\r
+ // open container to read the Heap object out of it's control row.\r
+ container = \r
+ xact_mgr.getRawStoreXact().openContainer(\r
+ container_key, (LockingPolicy) null, 0);\r
+\r
+ if (container == null)\r
+ {\r
+ throw StandardException.newException(\r
+ SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST,\r
+ new Long(container_key.getContainerId()));\r
+ }\r
+\r
+ // row in slot 0 of heap page 1 which is just a single column with\r
+ // the heap entry.\r
+ control_row[0] = new Heap();\r
+\r
+ page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);\r
+\r
+ RecordHandle rh = \r
+ page.fetchFromSlot(\r
+ (RecordHandle) null, 0, control_row, \r
+ (FetchDescriptor) null,\r
+ true);\r
+\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ SanityManager.ASSERT(rh != null);\r
+\r
+ // for now the control row is always the first id assigned on\r
+ // page 1.\r
+ SanityManager.ASSERT(rh.getId() == 6);\r
+ }\r
+ }\r
+ finally\r
+ {\r
+ if (page != null)\r
+ page.unlatch();\r
+\r
+ if (container != null)\r
+ container.close();\r
+ }\r
+\r
+ return((Conglomerate) control_row[0]);\r
+ }\r
+\r
+ /*\r
+ ** Methods of ModuleControl.\r
+ */\r
+\r
+ public boolean canSupport(Properties startParams) {\r
+\r
+ String impl = \r
+ startParams.getProperty("derby.access.Conglomerate.type");\r
+\r
+ if (impl == null)\r
+ return false;\r
+\r
+ return supportsImplementation(impl);\r
+ }\r
+\r
+ public void boot(boolean create, Properties startParams)\r
+ throws StandardException\r
+ {\r
+ // Find the UUID factory.\r
+ UUIDFactory uuidFactory = \r
+ Monitor.getMonitor().getUUIDFactory();\r
+ \r
+ // Make a UUID that identifies this conglomerate's format.\r
+ formatUUID = uuidFactory.recreateUUID(FORMATUUIDSTRING);\r
+ }\r
+\r
+ public void stop()\r
+ {\r
+ }\r
+\r
+ /*\r
+ ** Methods of HeapConglomerateFactory\r
+ */\r
+\r
+ public HeapConglomerateFactory()\r
+ {\r
+ }\r
+}\r
+\r