use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.
the class DataDictionaryImpl method getTableDescriptorIndex2Scan.
/**
* Scan systables_index2 (tableid) for a match.
*
* @return TableDescriptor The matching descriptor, if any.
*
* @exception StandardException Thrown on failure
*/
private TableDescriptor getTableDescriptorIndex2Scan(String tableUUID) throws StandardException {
DataValueDescriptor tableIDOrderable;
TableDescriptor td;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
/* Use tableIDOrderable in both start and stop position for scan.
*/
tableIDOrderable = new SQLChar(tableUUID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(1);
keyRow.setColumn(1, tableIDOrderable);
td = getDescriptorViaIndex(SYSTABLESRowFactory.SYSTABLES_INDEX2_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, TableDescriptor.class, false);
return finishTableDescriptor(td);
}
use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.
the class DataDictionaryImpl method faultInTabInfo.
/**
* Finishes building a TabInfoImpl if it hasn't already been faulted in.
* NOP if TabInfoImpl has already been faulted in.
*
* @param ti TabInfoImpl to fault in.
*
* @exception StandardException Thrown on error
*/
private void faultInTabInfo(TabInfoImpl ti) throws StandardException {
int numIndexes;
/* Most of the time, the noncoreInfo will be complete.
* It's okay to do an unsynchronized check and return
* if it is complete, since it never becomes "un-complete".
* If we change the code, for some reason, to allow
* it to become "un-complete" after being complete,
* then we will have to do a synchronized check here
* as well.
*/
if (ti.isComplete()) {
return;
}
/* The completing of the noncoreInfo entry must be synchronized.
* NOTE: We are assuming that we will not access a different
* noncoreInfo in the course of completing of this noncoreInfo,
* otherwise a deadlock could occur.
*/
synchronized (ti) {
/* Now that we can run, the 1st thing that we must do
* is to verify that we still need to complete the
* object. (We may have been blocked on another user
* doing the same.)
*/
if (ti.isComplete()) {
return;
}
TableDescriptor td = getTableDescriptor(ti.getTableName(), getSystemSchemaDescriptor(), null);
// exception.
if (td == null) {
return;
}
ConglomerateDescriptor cd = null;
ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
/* Init the heap conglomerate here */
for (int index = 0; index < cds.length; index++) {
cd = cds[index];
if (!cd.isIndex()) {
ti.setHeapConglomerate(cd.getConglomerateNumber());
break;
}
}
if (SanityManager.DEBUG) {
if (cd == null) {
SanityManager.THROWASSERT("No heap conglomerate found for " + ti.getTableName());
}
}
/* Initialize the index conglomerates */
numIndexes = ti.getCatalogRowFactory().getNumIndexes();
if (numIndexes == 0) {
return;
}
/* For each index, we get its id from the CDL */
ConglomerateDescriptor icd = null;
int indexCount = 0;
for (int index = 0; index < cds.length; index++) {
icd = cds[index];
if (icd.isIndex()) {
ti.setIndexConglomerate(icd);
indexCount++;
}
continue;
}
if (SanityManager.DEBUG) {
if (indexCount != ti.getCatalogRowFactory().getNumIndexes()) {
SanityManager.THROWASSERT("Number of indexes found (" + indexCount + ") does not match the number expected (" + ti.getCatalogRowFactory().getNumIndexes() + ")");
}
}
}
}
use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.
the class DataDictionaryImpl method getTableDescriptor.
/**
* Get the descriptor for the table with the given UUID.
*
* NOTE: I'm assuming that the object store will define an UUID for
* persistent objects. I'm also assuming that UUIDs are unique across
* schemas, and that the object store will be able to do efficient
* lookups across schemas (i.e. that no schema descriptor parameter
* is needed).
*
* @param tableID The UUID of the table to get the descriptor for
*
* @return The descriptor for the table, null if the table does
* not exist.
*
* @exception StandardException Thrown on failure
*/
public TableDescriptor getTableDescriptor(UUID tableID) throws StandardException {
OIDTDCacheable cacheEntry;
TableDescriptor retval = null;
/* Only use the cache if we're in compile-only mode */
if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE) {
cacheEntry = (OIDTDCacheable) OIDTdCache.find(tableID);
if (cacheEntry != null) {
retval = cacheEntry.getTableDescriptor();
// bind in previous command might have set refernced cols
retval.setReferencedColumnMap(null);
OIDTdCache.release(cacheEntry);
}
return retval;
}
return getTableDescriptorIndex2Scan(tableID.toString());
}
use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.
the class DataDictionaryImpl method getTableDescriptorIndex1Scan.
/**
* Scan systables_index1 (tablename, schemaid) for a match.
*
* @return TableDescriptor The matching descriptor, if any.
*
* @exception StandardException Thrown on failure
*/
private TableDescriptor getTableDescriptorIndex1Scan(String tableName, String schemaUUID) throws StandardException {
DataValueDescriptor schemaIDOrderable;
DataValueDescriptor tableNameOrderable;
TableDescriptor td;
TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
/* Use tableNameOrderable and schemaIdOrderable in both start
* and stop position for scan.
*/
tableNameOrderable = new SQLVarchar(tableName);
schemaIDOrderable = new SQLChar(schemaUUID);
/* Set up the start/stop position for the scan */
ExecIndexRow keyRow = exFactory.getIndexableRow(2);
keyRow.setColumn(1, tableNameOrderable);
keyRow.setColumn(2, schemaIDOrderable);
td = getDescriptorViaIndex(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, TableDescriptor.class, false);
return finishTableDescriptor(td);
}
use of org.apache.derby.iapi.sql.dictionary.TableDescriptor 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