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));
}
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());
}
}
}
}
}
}
Aggregations