use of org.apache.derby.iapi.sql.dictionary.SystemColumn in project derby by apache.
the class DataDictionaryImpl method upgrade_addColumns.
/**
* Upgrade an existing catalog by adding columns.
*
* @param rowFactory Associated with this catalog.
* @param newColumnIDs Array of 1-based column ids.
* @param tc Transaction controller
*
* @exception StandardException Standard Derby error policy
*/
public void upgrade_addColumns(CatalogRowFactory rowFactory, int[] newColumnIDs, TransactionController tc) throws StandardException {
int columnID;
SystemColumn currentColumn;
SystemColumn[] columns = rowFactory.buildColumnList();
ExecRow templateRow = rowFactory.makeEmptyRowForCurrentVersion();
int columnCount = newColumnIDs.length;
SchemaDescriptor sd = getSystemSchemaDescriptor();
TableDescriptor td;
long conglomID;
// table/column descriptor until after we add and populate the new column.
if (rowFactory instanceof SYSTABLESRowFactory) {
td = dataDescriptorGenerator.newTableDescriptor("SYSTABLES", sd, TableDescriptor.BASE_TABLE_TYPE, TableDescriptor.ROW_LOCK_GRANULARITY);
td.setUUID(getUUIDForCoreTable("SYSTABLES", sd.getUUID().toString(), tc));
conglomID = coreInfo[SYSTABLES_CORE_NUM].getHeapConglomerate();
} else if (rowFactory instanceof SYSCOLUMNSRowFactory) {
td = dataDescriptorGenerator.newTableDescriptor("SYSCOLUMNS", sd, TableDescriptor.BASE_TABLE_TYPE, TableDescriptor.ROW_LOCK_GRANULARITY);
td.setUUID(getUUIDForCoreTable("SYSCOLUMNS", sd.getUUID().toString(), tc));
conglomID = coreInfo[SYSCOLUMNS_CORE_NUM].getHeapConglomerate();
} else {
td = getTableDescriptor(rowFactory.getCatalogName(), sd, tc);
conglomID = td.getHeapConglomerateId();
}
widenConglomerate(templateRow, newColumnIDs, conglomID, tc);
ColumnDescriptor[] cdArray = new ColumnDescriptor[columnCount];
for (int ix = 0; ix < columnCount; ix++) {
columnID = newColumnIDs[ix];
// from 1 to 0 based
currentColumn = columns[columnID - 1];
cdArray[ix] = makeColumnDescriptor(currentColumn, columnID, td);
}
addDescriptorArray(cdArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc);
}
use of org.apache.derby.iapi.sql.dictionary.SystemColumn in project derby by apache.
the class DataDictionaryImpl method addSystemTableToDictionary.
/**
* Add the required entries to the data dictionary for a System table.
*/
private void addSystemTableToDictionary(TabInfoImpl ti, SchemaDescriptor sd, TransactionController tc, DataDescriptorGenerator ddg) throws StandardException {
CatalogRowFactory crf = ti.getCatalogRowFactory();
String name = ti.getTableName();
long conglomId = ti.getHeapConglomerate();
SystemColumn[] columnList = crf.buildColumnList();
UUID heapUUID = crf.getCanonicalHeapUUID();
String heapName = crf.getCanonicalHeapName();
TableDescriptor td;
UUID toid;
int columnCount;
SystemColumn column;
// add table to the data dictionary
columnCount = columnList.length;
td = ddg.newTableDescriptor(name, sd, TableDescriptor.SYSTEM_TABLE_TYPE, TableDescriptor.ROW_LOCK_GRANULARITY);
td.setUUID(crf.getCanonicalTableUUID());
addDescriptor(td, sd, SYSTABLES_CATALOG_NUM, false, tc);
toid = td.getUUID();
/* Add the conglomerate for the heap */
ConglomerateDescriptor cgd = ddg.newConglomerateDescriptor(conglomId, heapName, false, null, false, heapUUID, toid, sd.getUUID());
addDescriptor(cgd, sd, SYSCONGLOMERATES_CATALOG_NUM, false, tc);
/* Create the columns */
ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnCount];
for (int columnNumber = 0; columnNumber < columnCount; columnNumber++) {
column = columnList[columnNumber];
if (SanityManager.DEBUG) {
if (column == null) {
SanityManager.THROWASSERT("column " + columnNumber + " for table " + ti.getTableName() + " is null");
}
}
cdlArray[columnNumber] = makeColumnDescriptor(column, columnNumber + 1, td);
}
addDescriptorArray(cdlArray, td, SYSCOLUMNS_CATALOG_NUM, false, tc);
// now add the columns to the cdl of the table.
ColumnDescriptorList cdl = td.getColumnDescriptorList();
for (int i = 0; i < columnCount; i++) cdl.add(cdlArray[i]);
}
use of org.apache.derby.iapi.sql.dictionary.SystemColumn in project derby by apache.
the class DataDictionaryImpl method upgradeFixSystemColumnDefinition.
/**
* Upgrade an existing system catalog column's definition
* by setting it to the value it would have in a newly
* created database. This is only used to for a couple
* of columns that had incorrectly nullability. Other
* uses (e.g. changing column type) might require more work.
*
* @param columnNumber The column to change
* @param tc Transaction controller
*
* @exception StandardException Standard Derby error policy
*/
public void upgradeFixSystemColumnDefinition(CatalogRowFactory rowFactory, int columnNumber, TransactionController tc) throws StandardException {
SystemColumn theColumn;
SystemColumn[] columns = rowFactory.buildColumnList();
SchemaDescriptor sd = getSystemSchemaDescriptor();
TableDescriptor td = getTableDescriptor(rowFactory.getCatalogName(), sd, tc);
// from 1 to 0 based
theColumn = columns[columnNumber - 1];
ColumnDescriptor cd = makeColumnDescriptor(theColumn, columnNumber, td);
String columnName = cd.getColumnName();
int[] columnNameColArray = new int[1];
columnNameColArray[0] = SYSCOLUMNSRowFactory.SYSCOLUMNS_COLUMNDATATYPE;
updateColumnDescriptor(cd, td.getUUID(), columnName, columnNameColArray, tc);
}
Aggregations