Search in sources :

Example 1 with CreateConstraintConstantAction

use of org.apache.derby.impl.sql.execute.CreateConstraintConstantAction in project derby by apache.

the class CreateTableNode method makeConstantAction.

/**
 * Create the Constant information that will drive the guts of Execution.
 *
 * @exception StandardException		Thrown on failure
 */
@Override
public ConstantAction makeConstantAction() throws StandardException {
    TableElementList coldefs = tableElementList;
    // for each column, stuff system.column
    ColumnInfo[] colInfos = new ColumnInfo[coldefs.countNumberOfColumns()];
    int numConstraints = coldefs.genColumnInfos(colInfos);
    /* If we've seen a constraint, then build a constraint list */
    CreateConstraintConstantAction[] conActions = null;
    SchemaDescriptor sd = getSchemaDescriptor(tableType != TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE, true);
    if (numConstraints > 0) {
        conActions = new CreateConstraintConstantAction[numConstraints];
        coldefs.genConstraintActions(true, conActions, getRelativeName(), sd, getDataDictionary());
    }
    // if the any of columns are "long" and user has not specified a
    // page size, set the pagesize to 32k.
    // Also in case where the approximate sum of the column sizes is
    // greater than the bump threshold , bump the pagesize to 32k
    boolean table_has_long_column = false;
    int approxLength = 0;
    for (int i = 0; i < colInfos.length; i++) {
        DataTypeDescriptor dts = colInfos[i].getDataType();
        if (dts.getTypeId().isLongConcatableTypeId()) {
            table_has_long_column = true;
            break;
        }
        approxLength += dts.getTypeId().getApproximateLengthInBytes(dts);
    }
    if (table_has_long_column || (approxLength > Property.TBL_PAGE_SIZE_BUMP_THRESHOLD)) {
        if (((properties == null) || (properties.get(Property.PAGE_SIZE_PARAMETER) == null)) && (PropertyUtil.getServiceProperty(getLanguageConnectionContext().getTransactionCompile(), Property.PAGE_SIZE_PARAMETER) == null)) {
            if (properties == null)
                properties = new Properties();
            properties.put(Property.PAGE_SIZE_PARAMETER, Property.PAGE_SIZE_DEFAULT_LONG);
        }
    }
    return (getGenericConstantActionFactory().getCreateTableConstantAction(sd.getSchemaName(), getRelativeName(), tableType, colInfos, conActions, properties, lockGranularity, onCommitDeleteRows, onRollbackDeleteRows));
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) ColumnInfo(org.apache.derby.impl.sql.execute.ColumnInfo) Properties(java.util.Properties) CreateConstraintConstantAction(org.apache.derby.impl.sql.execute.CreateConstraintConstantAction)

Example 2 with CreateConstraintConstantAction

use of org.apache.derby.impl.sql.execute.CreateConstraintConstantAction in project derby by apache.

the class AlterTableNode method prepConstantAction.

/**
 *	Generate arguments to constant action. Called by makeConstantAction() in this class and in
 *	our subclass RepAlterTableNode.
 *
 * @exception StandardException		Thrown on failure
 */
private void prepConstantAction() throws StandardException {
    if (tableElementList != null) {
        genColumnInfo();
    }
    if (numConstraints > 0) {
        conActions = new ConstraintConstantAction[numConstraints];
        tableElementList.genConstraintActions(false, conActions, getRelativeName(), schemaDescriptor, getDataDictionary());
        for (int conIndex = 0; conIndex < conActions.length; conIndex++) {
            ConstraintConstantAction cca = conActions[conIndex];
            if (cca instanceof CreateConstraintConstantAction) {
                int constraintType = cca.getConstraintType();
                if (constraintType == DataDictionary.PRIMARYKEY_CONSTRAINT) {
                    DataDictionary dd = getDataDictionary();
                    // Check to see if a constraint of the same type
                    // already exists
                    ConstraintDescriptorList cdl = dd.getConstraintDescriptors(baseTable);
                    if (cdl.getPrimaryKey() != null) {
                        throw StandardException.newException(SQLState.LANG_ADD_PRIMARY_KEY_FAILED1, baseTable.getQualifiedName());
                    }
                }
            }
        }
    }
}
Also used : ConstraintConstantAction(org.apache.derby.impl.sql.execute.ConstraintConstantAction) CreateConstraintConstantAction(org.apache.derby.impl.sql.execute.CreateConstraintConstantAction) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) CreateConstraintConstantAction(org.apache.derby.impl.sql.execute.CreateConstraintConstantAction)

Aggregations

CreateConstraintConstantAction (org.apache.derby.impl.sql.execute.CreateConstraintConstantAction)2 Properties (java.util.Properties)1 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)1 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)1 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)1 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)1 ColumnInfo (org.apache.derby.impl.sql.execute.ColumnInfo)1 ConstraintConstantAction (org.apache.derby.impl.sql.execute.ConstraintConstantAction)1