Search in sources :

Example 16 with LockingPolicy

use of org.apache.derby.iapi.store.raw.LockingPolicy 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

LockingPolicy (org.apache.derby.iapi.store.raw.LockingPolicy)16 ContainerHandle (org.apache.derby.iapi.store.raw.ContainerHandle)6 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)6 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)6 Page (org.apache.derby.iapi.store.raw.Page)4 ContainerKey (org.apache.derby.iapi.store.raw.ContainerKey)3 CompatibilitySpace (org.apache.derby.iapi.services.locks.CompatibilitySpace)2 PageKey (org.apache.derby.iapi.store.raw.PageKey)2 RecordHandle (org.apache.derby.iapi.store.raw.RecordHandle)2 StreamContainerHandle (org.apache.derby.iapi.store.raw.StreamContainerHandle)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 Serviceable (org.apache.derby.iapi.services.daemon.Serviceable)1 Conglomerate (org.apache.derby.iapi.store.access.conglomerate.Conglomerate)1 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)1 ControlRow (org.apache.derby.impl.store.access.btree.ControlRow)1 BasePage (org.apache.derby.impl.store.raw.data.BasePage)1 StorageFile (org.apache.derby.io.StorageFile)1 StandardException (org.apache.derby.shared.common.error.StandardException)1