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;
}
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);
}
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);
}
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()]);
}
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();
}
}
}
Aggregations