Search in sources :

Example 41 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class SYSFILESRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSFILES row
 *
 * @return	Row suitable for inserting into SYSFILES
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    String id_S = null;
    String schemaId_S = null;
    String SQLname = null;
    long generationId = 0;
    ExecRow row;
    if (td != null) {
        FileInfoDescriptor descriptor = (FileInfoDescriptor) td;
        id_S = descriptor.getUUID().toString();
        schemaId_S = descriptor.getSchemaDescriptor().getUUID().toString();
        SQLname = descriptor.getName();
        generationId = descriptor.getGenerationId();
    }
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSFILES_COLUMN_COUNT);
    /* 1st column is ID (UUID - char(36)) */
    row.setColumn(ID_COL_NUM, new SQLChar(id_S));
    /* 2nd column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SCHEMA_ID_COL_NUM, new SQLChar(schemaId_S));
    /* 3rd column is NAME (varchar(30)) */
    row.setColumn(NAME_COL_NUM, new SQLVarchar(SQLname));
    /* 4th column is GENERATIONID (long) */
    row.setColumn(GENERATION_ID_COL_NUM, new SQLLongint(generationId));
    return row;
}
Also used : FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar)

Example 42 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class TemporaryRowHolderImpl method insertToPositionIndex.

/**
 * Maintain an index that will allow us to read  from the
 * temporary heap in the order we inserted.
 * @param position - the number of the row we are inserting into heap
 * @param rl the row to Location in the temporary heap
 * @exception StandardException on error
 */
private void insertToPositionIndex(int position, RowLocation rl) throws StandardException {
    if (!positionIndexCreated) {
        TransactionController tc = activation.getTransactionController();
        int numKeys = 2;
        position_sqllong = new SQLLongint();
        positionIndexRow = new DataValueDescriptor[numKeys];
        positionIndexRow[0] = position_sqllong;
        positionIndexRow[1] = rl;
        Properties props = makeIndexProperties(positionIndexRow, CID);
        positionIndexConglomId = tc.createConglomerate("BTREE", positionIndexRow, null, // no collation needed for index on row locations.
        null, props, (TransactionController.IS_TEMPORARY | TransactionController.IS_KEPT));
        positionIndex_cc = tc.openConglomerate(positionIndexConglomId, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
        positionIndexCreated = true;
    }
    position_sqllong.setValue(position);
    positionIndexRow[0] = position_sqllong;
    positionIndexRow[1] = rl;
    // insert the row location to position index
    positionIndex_cc.insert(positionIndexRow);
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) TransactionController(org.apache.derby.iapi.store.access.TransactionController) Properties(java.util.Properties) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 43 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class DataDictionaryImpl method setAutoincrementValue.

/**
 * sets a new value in SYSCOLUMNS for a particular
 * autoincrement column.
 *
 * @param tc		 Transaction Controller to use.
 * @param columnName Name of the column.
 * @param aiValue	 Value to write to SYSCOLUMNS.
 * @param incrementNeeded whether to increment the value passed in by the
 * user (aiValue) or not before writing it to SYSCOLUMNS.
 */
public void setAutoincrementValue(TransactionController tc, UUID tableUUID, String columnName, long aiValue, boolean incrementNeeded) throws StandardException {
    TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM];
    ExecIndexRow keyRow = null;
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(2);
    keyRow.setColumn(1, getIDValueAsCHAR(tableUUID));
    keyRow.setColumn(2, new SQLChar(columnName));
    SYSCOLUMNSRowFactory rf = (SYSCOLUMNSRowFactory) ti.getCatalogRowFactory();
    ExecRow row = rf.makeEmptyRow();
    boolean[] bArray = new boolean[2];
    for (int index = 0; index < 2; index++) {
        bArray[index] = false;
    }
    int[] colsToUpdate = new int[1];
    colsToUpdate[0] = SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTVALUE;
    if (incrementNeeded) {
        ExecRow readRow = ti.getRow(tc, keyRow, SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID);
        NumberDataValue increment = (NumberDataValue) readRow.getColumn(SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTINC);
        aiValue += increment.getLong();
    }
    row.setColumn(SYSCOLUMNSRowFactory.SYSCOLUMNS_AUTOINCREMENTVALUE, new SQLLongint(aiValue));
    ti.updateRow(keyRow, row, SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, bArray, colsToUpdate, tc);
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLChar(org.apache.derby.iapi.types.SQLChar) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) NumberDataValue(org.apache.derby.iapi.types.NumberDataValue) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 44 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class DataDictionaryImpl method getConglomerateDescriptors.

/**
 * Get an array of conglomerate descriptors for the given conglomerate
 * number.  If it is a heap conglomerate or an index conglomerate not
 * shared by a duplicate index, the size of the return array is 1.
 *
 * @param conglomerateNumber	The number for the conglomerate
 *				we're interested in
 *
 * @return	An array of ConglomerateDescriptors that share the requested
 *		conglomerate. Returns size 0 array if no such conglomerate.
 *
 * @exception StandardException		Thrown on failure
 */
public ConglomerateDescriptor[] getConglomerateDescriptors(long conglomerateNumber) throws StandardException {
    DataValueDescriptor conglomNumberOrderable = null;
    TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM];
    SYSCONGLOMERATESRowFactory rf = (SYSCONGLOMERATESRowFactory) ti.getCatalogRowFactory();
    conglomNumberOrderable = new SQLLongint(conglomerateNumber);
    ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1);
    scanQualifier[0][0].setQualifier(rf.SYSCONGLOMERATES_CONGLOMERATENUMBER - 1, /* column number */
    conglomNumberOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
    ConglomerateDescriptorList cdl = new ConglomerateDescriptorList();
    getDescriptorViaHeap(null, scanQualifier, ti, null, cdl, ConglomerateDescriptor.class);
    return cdl.toArray(new ConglomerateDescriptor[cdl.size()]);
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 45 with SQLLongint

use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.

the class DataDictionaryImpl method updateCurrentSequenceValue.

/**
 * Set the current value of an ANSI/ISO sequence. This method does not perform
 * any sanity checking but assumes that the caller knows what they are doing. If the
 * old value on disk is not what we expect it to be, then we are in a race with another
 * session. They won and we don't update the value on disk. However, if the old value
 * is null, that is a signal to us that we should update the value on disk anyway.
 *
 * @param tc			Transaction Controller to use.
 * @param rowLocation Row in SYSSEQUENCES to update.
 * @param wait True if we should wait for locks
 * @param oldValue What we expect to find in the CURRENTVALUE column.
 * @param newValue What to stuff into the CURRENTVALUE column.
 *
 * @return Returns true if the value was successfully updated, false if we lost a race with another session.
 *
 * @exception StandardException thrown on failure.
 */
public boolean updateCurrentSequenceValue(TransactionController tc, RowLocation rowLocation, boolean wait, Long oldValue, Long newValue) throws StandardException {
    int columnNum = SYSSEQUENCESRowFactory.SYSSEQUENCES_CURRENT_VALUE;
    FormatableBitSet columnToUpdate = new FormatableBitSet(SYSSEQUENCESRowFactory.SYSSEQUENCES_COLUMN_COUNT);
    TabInfoImpl ti = getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
    ConglomerateController heapCC = null;
    SYSSEQUENCESRowFactory rf = (SYSSEQUENCESRowFactory) ti.getCatalogRowFactory();
    ExecRow row = rf.makeEmptyRow();
    // FormatableBitSet is 0 based.
    // current value.
    columnToUpdate.set(columnNum - 1);
    try {
        /* if wait is true then we need to do a wait while trying to
			   open/fetch from the conglomerate. note we use wait both to
			   open as well as fetch from the conglomerate.
			*/
        heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
        boolean baseRowExists = heapCC.fetch(rowLocation, row.getRowArray(), columnToUpdate, wait);
        // 
        if (!baseRowExists) {
            return false;
        }
        NumberDataValue oldValueOnDisk = (NumberDataValue) row.getColumn(columnNum);
        SQLLongint expectedOldValue;
        if (oldValue == null) {
            expectedOldValue = new SQLLongint();
        } else {
            expectedOldValue = new SQLLongint(oldValue.longValue());
        }
        // only update value if what's on disk is what we expected
        if ((oldValue == null) || (expectedOldValue.compare(oldValueOnDisk) == 0)) {
            SQLLongint newValueOnDisk;
            if (newValue == null) {
                newValueOnDisk = new SQLLongint();
            } else {
                newValueOnDisk = new SQLLongint(newValue.longValue());
            }
            row.setColumn(columnNum, newValueOnDisk);
            heapCC.replace(rowLocation, row.getRowArray(), columnToUpdate);
            return true;
        } else {
            return false;
        }
    } finally {
        if (heapCC != null) {
            heapCC.close();
        }
    }
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) NumberDataValue(org.apache.derby.iapi.types.NumberDataValue) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Aggregations

SQLLongint (org.apache.derby.iapi.types.SQLLongint)50 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)28 RowLocation (org.apache.derby.iapi.types.RowLocation)24 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)21 ScanController (org.apache.derby.iapi.store.access.ScanController)19 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)13 SQLChar (org.apache.derby.iapi.types.SQLChar)10 Properties (java.util.Properties)7 HashSet (java.util.HashSet)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)5 GroupFetchScanController (org.apache.derby.iapi.store.access.GroupFetchScanController)4 StandardException (org.apache.derby.shared.common.error.StandardException)4 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)3 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)3 ContextManager (org.apache.derby.iapi.services.context.ContextManager)2 ContextService (org.apache.derby.iapi.services.context.ContextService)2 BackingStoreHashtable (org.apache.derby.iapi.store.access.BackingStoreHashtable)2 NumberDataValue (org.apache.derby.iapi.types.NumberDataValue)2 UserType (org.apache.derby.iapi.types.UserType)2 Enumeration (java.util.Enumeration)1