Search in sources :

Example 6 with TableDescriptor

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);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 7 with TableDescriptor

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() + ")");
            }
        }
    }
}
Also used : ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 8 with TableDescriptor

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());
}
Also used : TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 9 with TableDescriptor

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);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ConglomerateDescriptorList(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList) ArrayList(java.util.ArrayList) TriggerDescriptorList(org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList) List(java.util.List) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) LinkedList(java.util.LinkedList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 10 with TableDescriptor

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);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) SystemColumn(org.apache.derby.iapi.sql.dictionary.SystemColumn) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Aggregations

TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)80 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)27 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)23 UUID (org.apache.derby.catalog.UUID)22 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)20 TransactionController (org.apache.derby.iapi.store.access.TransactionController)20 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)19 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)11 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 StandardException (org.apache.derby.shared.common.error.StandardException)9 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)7 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)7 ArrayList (java.util.ArrayList)6 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 ViewDescriptor (org.apache.derby.iapi.sql.dictionary.ViewDescriptor)6