Search in sources :

Example 6 with ColumnDescriptor

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

the class DataDictionaryImpl method getColumnDescriptorsScan.

/**
 * Populate the ColumnDescriptorList for the specified TableDescriptor.
 *
 * MT synchronization: it is assumed that the caller has synchronized
 * on the CDL in the given TD.
 *
 * @param uuid				The referencing UUID
 * @param cdl			The column descriptor list
 * @param td				The parent tuple descriptor
 *
 * @exception StandardException		Thrown on failure
 */
private void getColumnDescriptorsScan(UUID uuid, ColumnDescriptorList cdl, TupleDescriptor td) throws StandardException {
    ColumnDescriptor cd;
    ColumnDescriptorList cdlCopy = new ColumnDescriptorList();
    DataValueDescriptor refIDOrderable = null;
    TabInfoImpl ti = coreInfo[SYSCOLUMNS_CORE_NUM];
    /* Use refIDOrderable in both start and stop position for scan. */
    refIDOrderable = getIDValueAsCHAR(uuid);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, refIDOrderable);
    getDescriptorViaIndex(SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, td, cdl, ColumnDescriptor.class, false);
    /* The TableDescriptor's column descriptor list must be ordered by
		 * columnNumber.  (It is probably not ordered correctly at this point due
		 * to the index on syscolumns being on (tableId, columnName).)  The
		 * cheapest way to reorder the list appears to be to copy it (above), and then
		 * walk the copy and put the elements back into the original in the
		 * expected locations.
		 */
    int cdlSize = cdl.size();
    for (int index = 0; index < cdlSize; index++) {
        cdlCopy.add(cdl.get(index));
    }
    for (int index = 0; index < cdlSize; index++) {
        cd = (ColumnDescriptor) cdlCopy.elementAt(index);
        cdl.set(cd.getPosition() - 1, cd);
    }
}
Also used : ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 7 with ColumnDescriptor

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

the class DataDictionaryImpl method getSPSParams.

/**
 * Get all the parameter descriptors for an SPS.
 * Look up the params in SYSCOLUMNS and turn them
 * into parameter descriptors.
 *
 * @param spsd	sps descriptor
 * @param defaults list for storing column defaults
 *
 * @return array of data type descriptors
 *
 * @exception StandardException		Thrown on error
 */
public DataTypeDescriptor[] getSPSParams(SPSDescriptor spsd, List<DataValueDescriptor> defaults) throws StandardException {
    ColumnDescriptorList cdl = new ColumnDescriptorList();
    getColumnDescriptorsScan(spsd.getUUID(), cdl, spsd);
    int cdlSize = cdl.size();
    DataTypeDescriptor[] params = new DataTypeDescriptor[cdlSize];
    for (int index = 0; index < cdlSize; index++) {
        ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
        params[index] = cd.getType();
        if (defaults != null) {
            defaults.add(cd.getDefaultValue());
        }
    }
    return params;
}
Also used : ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 8 with ColumnDescriptor

use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptor 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)

Example 9 with ColumnDescriptor

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

the class SYSCOLUMNSRowFactory method makeRow.

private ExecRow makeRow(TupleDescriptor td, int columnCount) throws StandardException {
    ExecRow row;
    String colName = null;
    String defaultID = null;
    String tabID = null;
    Integer colID = null;
    TypeDescriptor typeDesc = null;
    Object defaultSerializable = null;
    long autoincStart = 0;
    long autoincInc = 0;
    long autoincValue = 0;
    boolean autoincCycle = false;
    // The SYSCOLUMNS table's autoinc related columns change with different
    // values depending on what happened to the autoinc column, ie is the
    // user adding an autoincrement column, or is user changing the existing
    // autoincrement column to change it's increment value or to change it's
    // start value? Following variable is used to keep track of what happened
    // to the autoincrement column.
    long autoinc_create_or_modify_Start_Increment = -1;
    if (td != null) {
        ColumnDescriptor column = (ColumnDescriptor) td;
        /* Lots of info in the column's type descriptor */
        typeDesc = column.getType().getCatalogType();
        tabID = column.getReferencingUUID().toString();
        colName = column.getColumnName();
        colID = column.getPosition();
        autoincStart = column.getAutoincStart();
        autoincInc = column.getAutoincInc();
        autoincValue = column.getAutoincValue();
        autoinc_create_or_modify_Start_Increment = column.getAutoinc_create_or_modify_Start_Increment();
        autoincCycle = column.getAutoincCycle();
        if (column.getDefaultInfo() != null) {
            defaultSerializable = column.getDefaultInfo();
        } else {
            defaultSerializable = column.getDefaultValue();
        }
        if (column.getDefaultUUID() != null) {
            defaultID = column.getDefaultUUID().toString();
        }
    }
    /* Insert info into syscolumns */
    /* RESOLVE - It would be nice to require less knowledge about syscolumns
		 * and have this be more table driven.
		 * RESOLVE - We'd like to store the DataTypeDescriptor in a column.
		 */
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(columnCount);
    /* 1st column is REFERENCEID (UUID - char(36)) */
    row.setColumn(SYSCOLUMNS_REFERENCEID, new SQLChar(tabID));
    /* 2nd column is COLUMNNAME (varchar(128)) */
    row.setColumn(SYSCOLUMNS_COLUMNNAME, new SQLVarchar(colName));
    /* 3rd column is COLUMNNUMBER (int) */
    row.setColumn(SYSCOLUMNS_COLUMNNUMBER, new SQLInteger(colID));
    /* 4th column is COLUMNDATATYPE */
    row.setColumn(SYSCOLUMNS_COLUMNDATATYPE, new UserType(typeDesc));
    /* 5th column is COLUMNDEFAULT */
    row.setColumn(SYSCOLUMNS_COLUMNDEFAULT, new UserType(defaultSerializable));
    /* 6th column is DEFAULTID (UUID - char(36)) */
    row.setColumn(SYSCOLUMNS_COLUMNDEFAULTID, new SQLChar(defaultID));
    if ((autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.CREATE_AUTOINCREMENT) || (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_INC_VALUE) || (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_ALWAYS_VS_DEFAULT)) {
        // user is adding an autoinc column
        // or is changing the increment value of autoinc column
        // or is changing an autoinc column between ALWAYS and DEFAULT.
        // This code also gets run when ALTER TABLE DROP COLUMN
        // is used to drop a column other than the autoinc
        // column, and the autoinc column gets removed from
        // SYSCOLUMNS and immediately re-added with a different
        // column position (to account for the dropped column).
        // In this case, the autoincValue may have a
        // different value than the autoincStart.
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTVALUE, new SQLLongint(autoincValue));
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTSTART, new SQLLongint(autoincStart));
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTINC, new SQLLongint(autoincInc));
        if (row.nColumns() >= 10) {
            // This column is present only if the data dictionary version is
            // 10.14 or higher.
            row.setColumn(SYSCOLUMNS_AUTOINCREMENTINCCYCLE, new SQLBoolean(autoincCycle));
        }
    } else if (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_RESTART_VALUE) {
        // user asked for restart with a new value, so don't change increment by and original start
        // with values in the SYSCOLUMNS table. Just record the RESTART WITH value as the
        // next value to be generated in the SYSCOLUMNS table
        ColumnDescriptor column = (ColumnDescriptor) td;
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTVALUE, new SQLLongint(autoincStart));
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTSTART, new SQLLongint(autoincStart));
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTINC, new SQLLongint(column.getTableDescriptor().getColumnDescriptor(colName).getAutoincInc()));
        if (row.nColumns() >= 10) {
            // This column is present only if the data dictionary version is
            // 10.14 or higher.
            row.setColumn(SYSCOLUMNS_AUTOINCREMENTINCCYCLE, new SQLBoolean(autoincCycle));
        }
    } else if (autoinc_create_or_modify_Start_Increment == ColumnDefinitionNode.MODIFY_AUTOINCREMENT_CYCLE_VALUE) {
        ColumnDescriptor column = (ColumnDescriptor) td;
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTVALUE, new SQLLongint(column.getTableDescriptor().getColumnDescriptor(colName).getAutoincValue()));
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTSTART, new SQLLongint(column.getTableDescriptor().getColumnDescriptor(colName).getAutoincStart()));
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTINC, new SQLLongint(column.getTableDescriptor().getColumnDescriptor(colName).getAutoincInc()));
        if (row.nColumns() >= 10) {
            // This column is present only if the data dictionary version is
            // 10.14 or higher.
            row.setColumn(SYSCOLUMNS_AUTOINCREMENTINCCYCLE, new SQLBoolean(autoincCycle));
        }
    } else {
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTVALUE, new SQLLongint());
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTSTART, new SQLLongint());
        row.setColumn(SYSCOLUMNS_AUTOINCREMENTINC, new SQLLongint());
        if (row.nColumns() >= 10) {
            // This column is present only if the data dictionary version is
            // 10.14 or higher.
            row.setColumn(SYSCOLUMNS_AUTOINCREMENTINCCYCLE, new SQLBoolean(autoincCycle));
        }
    }
    return row;
}
Also used : ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 10 with ColumnDescriptor

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

the class InsertNode method generate.

/**
 * Code generation for insert
 * creates an expression for:
 *   ResultSetFactory.getInsertResultSet(resultSet.generate(ps), generationClausesResult, checkConstrainResult, this )
 *
 * @param acb	The ActivationClassBuilder for the class being built
 * @param mb the method  for the execute() method to be built
 *
 * @exception StandardException		Thrown on error
 */
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
    // If the DML is on the temporary table, generate the code to
    // mark temporary table as modified in the current UOW. After
    // DERBY-827 this must be done in execute() since
    // createResultSet() will only be called once.
    generateCodeForTemporaryTable(acb);
    /* generate the parameters */
    generateParameterValueSet(acb);
    // Base table
    if (targetTableDescriptor != null) {
        /*
			** Generate the insert result set, giving it either the original
			** source or the normalize result set, the constant action,
			** and "this".
			*/
        acb.pushGetResultSetFactoryExpression(mb);
        // arg 1
        if (inMatchingClause()) {
            matchingClause.generateResultSetField(acb, mb);
        } else {
            resultSet.generate(acb, mb);
        }
        // arg 2 generate code to evaluate generation clauses
        generateGenerationClauses(resultColumnList, resultSet.getResultSetNumber(), false, acb, mb);
        // arg 3 generate code to evaluate CHECK CONSTRAINTS
        generateCheckConstraints(checkConstraints, acb, mb);
        // arg 4 row template used by bulk insert
        if (bulkInsert) {
            ColumnDescriptorList cdl = targetTableDescriptor.getColumnDescriptorList();
            ExecRowBuilder builder = new ExecRowBuilder(cdl.size(), false);
            for (int i = 0; i < cdl.size(); i++) {
                ColumnDescriptor cd = cdl.get(i);
                builder.setColumn(i + 1, cd.getType());
            }
            mb.push(acb.addItem(builder));
        } else {
            mb.push(-1);
        }
        // arg 5, 6 table name
        if (targetTableName.getSchemaName() == null) {
            mb.pushNull("java.lang.String");
        } else {
            mb.push(targetTableName.getSchemaName());
        }
        mb.push(targetTableName.getTableName());
        mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getInsertResultSet", ClassName.ResultSet, 6);
    } else {
        /* Generate code for the VTI
			 * NOTE: we need to create a dummy cost estimate for the
			 * targetVTI since we never optimized it.
			 * RESOLVEVTI - we will have to optimize it in order to 
			 * push predicates into the VTI.
			 */
        targetVTI.assignCostEstimate(resultSet.getNewCostEstimate());
        /*
			** Generate the insert VTI result set, giving it either the original
			** source or the normalize result set, the constant action,
			*/
        acb.pushGetResultSetFactoryExpression(mb);
        // arg 1
        resultSet.generate(acb, mb);
        // arg 2
        targetVTI.generate(acb, mb);
        mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getInsertVTIResultSet", ClassName.ResultSet, 2);
    }
}
Also used : ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ExecRowBuilder(org.apache.derby.iapi.sql.execute.ExecRowBuilder) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)

Aggregations

ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)79 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)23 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)19 UUID (org.apache.derby.catalog.UUID)15 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)14 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)10 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)8 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)8 TransactionController (org.apache.derby.iapi.store.access.TransactionController)8 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)8 SQLLongint (org.apache.derby.iapi.types.SQLLongint)8 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)7 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)7 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)7 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)7 RowLocation (org.apache.derby.iapi.types.RowLocation)7 DefaultInfoImpl (org.apache.derby.catalog.types.DefaultInfoImpl)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 DefaultDescriptor (org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)6