Search in sources :

Example 16 with ContainerKey

use of org.apache.derby.iapi.store.raw.ContainerKey in project derby by apache.

the class Heap method create.

/* Private/Protected methods of This class: */
/**
 * Create a heap conglomerate.
 * <p>
 * Create a heap conglomerate.  This method is called from the heap factory
 * to create a new instance of a heap.
 * <p>
 *
 * @exception  StandardException  Standard exception policy.
 */
protected void create(Transaction rawtran, int segmentId, long input_containerid, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, Properties properties, int conglom_format_id, int tmpFlag) throws StandardException {
    // care of in fileContainer.java: createInfoFromProp().
    if (properties != null) {
        String value = properties.getProperty(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER);
        int minimumRecordSize = (value == null) ? RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT : Integer.parseInt(value);
        if (minimumRecordSize < RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT) {
            properties.put(RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, Integer.toString(RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT));
        }
    }
    // Create a container for the heap with default page size.
    long containerid = rawtran.addContainer(segmentId, input_containerid, ContainerHandle.MODE_DEFAULT, properties, tmpFlag);
    // Make sure the container was actually created.
    if (containerid < 0) {
        throw StandardException.newException(SQLState.HEAP_CANT_CREATE_CONTAINER);
    }
    // Keep track of what segment the container's in.
    id = new ContainerKey(segmentId, containerid);
    // Heap requires a template representing every column in the table.
    if ((template == null) || (template.length == 0)) {
        throw StandardException.newException(SQLState.HEAP_COULD_NOT_CREATE_CONGLOMERATE);
    }
    // get format id's from each column in template and store it in the
    // conglomerate state.
    this.format_ids = ConglomerateUtil.createFormatIds(template);
    // copy the format id of the conglomerate.
    this.conglom_format_id = conglom_format_id;
    // get collation ids from input collation ids, store it in the
    // conglom state.
    collation_ids = ConglomerateUtil.createCollationIds(format_ids.length, collationIds);
    hasCollatedTypes = hasCollatedColumns(collation_ids);
    // need to open the container and insert the row.  Since we are
    // creating it no need to bother with locking since no one can get
    // to it until after we have created it and returned it's id.
    ContainerHandle container = null;
    Page page = null;
    try {
        container = rawtran.openContainer(id, (LockingPolicy) null, ContainerHandle.MODE_FORUPDATE | (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));
        // row in slot 0 of heap page 1 which is just a single column with
        // the heap entry.
        DataValueDescriptor[] control_row = new DataValueDescriptor[1];
        control_row[0] = this;
        page = container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);
        page.insertAtSlot(Page.FIRST_SLOT_NUMBER, control_row, (FormatableBitSet) null, (LogicalUndo) null, Page.INSERT_OVERFLOW, AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
        page.unlatch();
        page = null;
        // Don't include the control row in the estimated row count.
        container.setEstimatedRowCount(0, /* unused flag */
        0);
    } finally {
        if (container != null)
            container.close();
        if (page != null)
            page.unlatch();
    }
}
Also used : Page(org.apache.derby.iapi.store.raw.Page) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ContainerKey(org.apache.derby.iapi.store.raw.ContainerKey) LockingPolicy(org.apache.derby.iapi.store.raw.LockingPolicy) ContainerHandle(org.apache.derby.iapi.store.raw.ContainerHandle)

Aggregations

ContainerKey (org.apache.derby.iapi.store.raw.ContainerKey)16 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)4 LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)3 Page (org.apache.derby.iapi.store.raw.Page)3 StreamContainerHandle (org.apache.derby.iapi.store.raw.StreamContainerHandle)3 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 RawStoreFactory (org.apache.derby.iapi.store.raw.RawStoreFactory)1 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)1 Transaction (org.apache.derby.iapi.store.raw.Transaction)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1