Search in sources :

Example 16 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class MergeNode method sourceIsBase_or_VTI.

/**
 * Return true if the source table is a base table, view, or table function
 */
private boolean sourceIsBase_or_VTI() throws StandardException {
    if (_sourceTable instanceof FromVTI) {
        return true;
    }
    if (!(_sourceTable instanceof FromBaseTable)) {
        return false;
    }
    FromBaseTable fbt = (FromBaseTable) _sourceTable;
    TableDescriptor desc = fbt.getTableDescriptor();
    if (desc == null) {
        return false;
    }
    switch(desc.getTableType()) {
        case TableDescriptor.BASE_TABLE_TYPE:
        case TableDescriptor.SYSTEM_TABLE_TYPE:
        case TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE:
            return true;
        default:
            return false;
    }
}
Also used : TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 17 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class MatchingClauseNode method bindInsertValues.

/**
 *  Bind the values in the INSERT list
 */
private void bindInsertValues(FromList fullFromList, FromTable targetTable) throws StandardException {
    TableDescriptor td = targetTable.getTableDescriptor();
    // construct a full insert column list if insert columns weren't specified
    if (_insertColumns == null) {
        _insertColumns = buildFullColumnList(td);
    }
    if (_insertColumns.size() != _insertValues.size()) {
        throw StandardException.newException(SQLState.LANG_DB2_INVALID_COLS_SPECIFIED);
    }
    // forbid illegal values for identity columns
    for (int i = 0; i < _insertValues.size(); i++) {
        ResultColumn rc = _insertValues.elementAt(i);
        String columnName = _insertColumns.elementAt(i).getName();
        ValueNode expr = rc.getExpression();
        ColumnDescriptor cd = td.getColumnDescriptor(columnName);
        // the InsertNode
        if (cd == null) {
            continue;
        }
        // DEFAULT is the only value allowed for a GENERATED ALWAYS AS IDENTITY column
        if (cd.isAutoincAlways() && !(expr instanceof DefaultNode)) {
            throw StandardException.newException(SQLState.LANG_AI_CANNOT_MODIFY_AI, columnName);
        }
        // NULL is illegal as the value for any identity column
        if (cd.isAutoincrement() && (expr instanceof UntypedNullConstantNode)) {
            throw StandardException.newException(SQLState.LANG_NULL_INTO_NON_NULL, columnName);
        }
    }
    // needed to make the SelectNode bind
    _insertValues.replaceOrForbidDefaults(targetTable.getTableDescriptor(), _insertColumns, true);
    bindExpressions(_insertValues, fullFromList);
}
Also used : ResultColumnDescriptor(org.apache.derby.iapi.sql.ResultColumnDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 18 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class SelectNode method isUpdatableCursor.

/**
 *		Determine if this select is updatable or not, for a cursor.
 */
@Override
boolean isUpdatableCursor(DataDictionary dd) throws StandardException {
    TableDescriptor targetTableDescriptor;
    if (isDistinct) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select has distinct");
        return false;
    }
    if ((selectAggregates == null) || (selectAggregates.size() > 0)) {
        return false;
    }
    if (groupByList != null || havingClause != null) {
        return false;
    }
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(fromList != null, "select must have from tables");
    if (fromList.size() != 1) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select has more than one from table");
        return false;
    }
    targetTable = (FromTable) (fromList.elementAt(0));
    if (targetTable instanceof FromVTI) {
        return ((FromVTI) targetTable).isUpdatableCursor();
    }
    if (!(targetTable instanceof FromBaseTable)) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select has non base table as target table");
        return false;
    }
    if (!targetTable.columnsAreUpdatable()) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select has no updatable result columns");
        return false;
    }
    /* Get the TableDescriptor and verify that it is not for a
 		 * view or a system table.  
 		 * NOTE: We need to use the base table name for the table.
 		 *		 Simplest way to get it is from a FromBaseTable.  We
 		 *		 know that targetTable is a FromBaseTable because of check
 		 *		 just above us.
		 * NOTE: We also need to use the base table's schema name; otherwise
		 *		we will think it is the default schema Beetle 4417
 		 */
    targetTableDescriptor = getTableDescriptor(((FromBaseTable) targetTable).getBaseTableName(), getSchemaDescriptor(((FromBaseTable) targetTable).getTableNameField().getSchemaName()));
    if (targetTableDescriptor.getTableType() == TableDescriptor.SYSTEM_TABLE_TYPE) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select is on system table");
        return false;
    }
    if (targetTableDescriptor.getTableType() == TableDescriptor.VIEW_TYPE) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select is on view");
        return false;
    }
    if ((getSelectSubquerys() != null) && (getSelectSubquerys().size() != 0)) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select has subquery in SELECT list");
        return false;
    }
    if ((getWhereSubquerys() != null) && (getWhereSubquerys().size() != 0)) {
        if (SanityManager.DEBUG)
            SanityManager.DEBUG("DumpUpdateCheck", "cursor select has subquery in WHERE clause");
        return false;
    }
    return true;
}
Also used : TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 19 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class RenameNode method bindStatement.

// We inherit the generate() method from DDLStatementNode.
/**
 * Bind this node.  This means doing any static error checking that
 * can be done before actually renaming the table/column/index.
 *
 * For a table rename: looking up the from table, verifying it exists
 * verifying it's not a system table, verifying it's not view
 * and looking up to table, verifying it doesn't exist.
 *
 * For a column rename: looking up the table, verifying it exists,
 * verifying it's not a system table, verifying it's not view, verifying
 * the from column exists, verifying the to column doesn't exist.
 *
 * For a index rename: looking up the table, verifying it exists,
 * verifying it's not a system table, verifying it's not view, verifying
 * the from index exists, verifying the to index doesn't exist.
 *
 * @exception StandardException		Thrown on error
 */
@Override
public void bindStatement() throws StandardException {
    CompilerContext cc = getCompilerContext();
    DataDictionary dd = getDataDictionary();
    ConglomerateDescriptor cd;
    SchemaDescriptor sd;
    /* in case of rename index, the only thing we get from parser is
		 * current and new index names with no information about the
		 * table it belongs to. This is because index names are unique
		 * within a schema and hence then is no need to qualify an index
		 * name with a table name which we have to do for rename column.
		 * But from the index name, using the data dictionary, you can
		 * find the table it belongs to. Since most of the checking
		 * in bind is done using table descriptor, in the following if
		 * statement, we are trying to get the table information from the
		 * index name so it is available for the rest of he bind code.
		 */
    TableName baseTable;
    if (renamingWhat == StatementType.RENAME_INDEX) {
        sd = getSchemaDescriptor((String) null);
        ConglomerateDescriptor indexDescriptor = dd.getConglomerateDescriptor(oldObjectName, sd, false);
        if (indexDescriptor == null)
            throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND, oldObjectName);
        /* Get the table descriptor */
        td = dd.getTableDescriptor(indexDescriptor.getTableID());
        initAndCheck(makeTableName(td.getSchemaName(), td.getName()));
    } else
        sd = getSchemaDescriptor();
    td = getTableDescriptor();
    // throw an exception if user is attempting a rename on temporary table
    if (td.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        throw StandardException.newException(SQLState.LANG_NOT_ALLOWED_FOR_DECLARED_GLOBAL_TEMP_TABLE);
    }
    switch(this.renamingWhat) {
        case StatementType.RENAME_TABLE:
            /* Verify that new table name does not exist in the database */
            TableDescriptor tabDesc = getTableDescriptor(newObjectName, sd);
            if (tabDesc != null)
                throw descriptorExistsException(tabDesc, sd);
            renameTableBind(dd);
            break;
        case StatementType.RENAME_COLUMN:
            renameColumnBind(dd);
            break;
        case StatementType.RENAME_INDEX:
            ConglomerateDescriptor conglomDesc = dd.getConglomerateDescriptor(newObjectName, sd, false);
            if (conglomDesc != null)
                throw descriptorExistsException(conglomDesc, sd);
            break;
        default:
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("Unexpected rename action in RenameNode");
            break;
    }
    conglomerateNumber = td.getHeapConglomerateId();
    /* Get the base conglomerate descriptor */
    cd = td.getConglomerateDescriptor(conglomerateNumber);
    /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
    cc.createDependency(td);
    cc.createDependency(cd);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 20 with TableDescriptor

use of org.apache.derby.iapi.sql.dictionary.TableDescriptor in project derby by apache.

the class TableNameInfo method getTableName.

public String getTableName(Long conglomId) {
    if (conglomId == null)
        return "?";
    // see if we have already seen this conglomerate
    TableDescriptor td = tableCache.get(conglomId);
    if (td == null) {
        // first time we see this conglomerate, get it from the
        // ddCache
        ConglomerateDescriptor cd = ddCache.get(conglomId);
        if (cd != null) {
            // conglomerateDescriptor is not null, this table is known
            // to the data dictionary
            td = tdCache.get(cd.getTableID());
        }
        if ((cd == null) || (td == null)) {
            String name;
            // the data dictionary
            if (conglomId.longValue() > 20) {
                // table probably dropped!
                name = "*** TRANSIENT_" + conglomId;
            } else {
                // one of the internal tables -- HACK!!
                switch(conglomId.intValue()) {
                    case 0:
                        name = "*** INVALID CONGLOMERATE ***";
                        break;
                    case 1:
                        name = "ConglomerateDirectory";
                        break;
                    case 2:
                        name = "PropertyConglomerate";
                        break;
                    default:
                        name = "*** INTERNAL TABLE " + conglomId;
                        break;
                }
            }
            return name;
        }
        tableCache.put(conglomId, td);
        if ((indexCache != null) && cd.isIndex())
            indexCache.put(conglomId, cd.getConglomerateName());
    }
    return td.getName();
}
Also used : ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) 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