use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList in project derby by apache.
the class ResultColumnList method expandToAll.
/**
* Expand this ResultColumnList by adding all columns from the given
* table that are not in this list. The result is sorted by column
* position.
*
* @param td The TableDescriptor for the table in question
* @param tableName The name of the table as given in the query
*
* @return A new ResultColumnList expanded to include all columns in
* the given table.
*
* @exception StandardException Thrown on error
*/
ResultColumnList expandToAll(TableDescriptor td, TableName tableName) throws StandardException {
ResultColumn rc;
ColumnDescriptor cd;
ResultColumnList retval;
ResultColumn[] originalRCS;
int posn;
/* Get a new ResultColumnList */
retval = new ResultColumnList(getContextManager());
/*
** Form a sorted array of the ResultColumns
*/
originalRCS = getSortedByPosition();
posn = 0;
/* Iterate through the ColumnDescriptors for the given table */
ColumnDescriptorList cdl = td.getColumnDescriptorList();
int cdlSize = cdl.size();
for (int index = 0; index < cdlSize; index++) {
cd = cdl.elementAt(index);
if ((posn < originalRCS.length) && (cd.getPosition() == originalRCS[posn].getColumnPosition())) {
rc = originalRCS[posn];
posn++;
} else {
/* Build a ResultColumn/ColumnReference pair for the column */
rc = makeColumnReferenceFromName(tableName, cd.getColumnName());
/* Bind the new ResultColumn */
rc.bindResultColumnByPosition(td, cd.getPosition());
}
/* Add the ResultColumn to the list */
retval.addResultColumn(rc);
}
if (SanityManager.DEBUG)
SanityManager.ASSERT(posn == originalRCS.length, "ResultColumns in original list not added to expanded ResultColumnList");
return retval;
}
use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList in project derby by apache.
the class RenameNode method renameColumnBind.
// do any checking needs to be done at bind time for rename column
private void renameColumnBind(DataDictionary dd) throws StandardException {
ColumnDescriptor columnDescriptor = td.getColumnDescriptor(oldObjectName);
/* Verify that old column name does exist in the table */
if (columnDescriptor == null)
throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, oldObjectName, getFullName());
/* Verify that new column name does not exist in the table */
ColumnDescriptor cd = td.getColumnDescriptor(newObjectName);
if (cd != null)
throw descriptorExistsException(cd, td);
//
// You cannot rename a column which is referenced by the generation
// clause of a generated column.
//
ColumnDescriptorList generatedColumns = td.getGeneratedColumns();
int generatedColumnCount = generatedColumns.size();
for (int i = 0; i < generatedColumnCount; i++) {
ColumnDescriptor gc = generatedColumns.elementAt(i);
String[] referencedColumns = gc.getDefaultInfo().getReferencedColumnNames();
int refColCount = referencedColumns.length;
for (int j = 0; j < refColCount; j++) {
String refName = referencedColumns[j];
if (oldObjectName.equals(refName)) {
throw StandardException.newException(SQLState.LANG_GEN_COL_BAD_RENAME, oldObjectName, gc.getColumnName());
}
}
}
/* Verify that there are no check constraints using the column being renamed */
ConstraintDescriptorList constraintDescriptorList = dd.getConstraintDescriptors(td);
int size = constraintDescriptorList == null ? 0 : constraintDescriptorList.size();
ConstraintDescriptor constraintDescriptor;
ColumnDescriptorList checkConstraintCDL;
int checkConstraintCDLSize;
// go through all the constraints defined on the table
for (int index = 0; index < size; index++) {
constraintDescriptor = constraintDescriptorList.elementAt(index);
// renamed is not used in it's sql
if (constraintDescriptor.getConstraintType() == DataDictionary.CHECK_CONSTRAINT) {
checkConstraintCDL = constraintDescriptor.getColumnDescriptors();
checkConstraintCDLSize = checkConstraintCDL.size();
for (int index2 = 0; index2 < checkConstraintCDLSize; index2++) if (checkConstraintCDL.elementAt(index2) == columnDescriptor)
throw StandardException.newException(SQLState.LANG_RENAME_COLUMN_WILL_BREAK_CHECK_CONSTRAINT, oldObjectName, constraintDescriptor.getConstraintName());
}
}
}
use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList in project derby by apache.
the class FromBaseTable method genResultColList.
/**
* Build a ResultColumnList based on all of the columns in this FromBaseTable.
* NOTE - Since the ResultColumnList generated is for the FromBaseTable,
* ResultColumn.expression will be a BaseColumnNode.
*
* @return ResultColumnList representing all referenced columns
*
* @exception StandardException Thrown on error
*/
ResultColumnList genResultColList() throws StandardException {
ResultColumn resultColumn;
ValueNode valueNode;
/* Cache exposed name for this table.
* The exposed name becomes the qualifier for each column
* in the expanded list.
*/
TableName exposedName = getExposedTableName();
/* Add all of the columns in the table */
ResultColumnList rcList = new ResultColumnList((getContextManager()));
ColumnDescriptorList cdl = tableDescriptor.getColumnDescriptorList();
int cdlSize = cdl.size();
for (int index = 0; index < cdlSize; index++) {
/* Build a ResultColumn/BaseColumnNode pair for the column */
ColumnDescriptor colDesc = cdl.elementAt(index);
// A ColumnDescriptor instantiated through SYSCOLUMNSRowFactory only has
// the uuid set on it and no table descriptor set on it. Since we know here
// that this columnDescriptor is tied to tableDescriptor, set it so using
// setTableDescriptor method. ColumnDescriptor's table descriptor is used
// to get ResultSetMetaData.getTableName & ResultSetMetaData.getSchemaName
colDesc.setTableDescriptor(tableDescriptor);
valueNode = new BaseColumnNode(colDesc.getColumnName(), exposedName, colDesc.getType(), getContextManager());
resultColumn = new ResultColumn(colDesc, valueNode, getContextManager());
/* Build the ResultColumnList to return */
rcList.addResultColumn(resultColumn);
}
// add a row location column as necessary
if (rowLocationColumnName != null) {
CurrentRowLocationNode rowLocationNode = new CurrentRowLocationNode(getContextManager());
ResultColumn rowLocationColumn = new ResultColumn(rowLocationColumnName, rowLocationNode, getContextManager());
rowLocationColumn.markGenerated();
rowLocationNode.bindExpression(null, null, null);
rowLocationColumn.bindResultColumnToExpression();
rcList.addResultColumn(rowLocationColumn);
}
return rcList;
}
use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList in project derby by apache.
the class FromVTI method genResultColList.
private ResultColumnList genResultColList(TableDescriptor td) throws StandardException {
/* Add all of the columns in the table */
ResultColumnList rcList = new ResultColumnList((getContextManager()));
ColumnDescriptorList cdl = td.getColumnDescriptorList();
int cdlSize = cdl.size();
for (int index = 0; index < cdlSize; index++) {
/* Build a ResultColumn/BaseColumnNode pair for the column */
ColumnDescriptor colDesc = cdl.elementAt(index);
ValueNode valueNode = new BaseColumnNode(colDesc.getColumnName(), exposedName, colDesc.getType(), getContextManager());
ResultColumn resultColumn = new ResultColumn(colDesc, valueNode, getContextManager());
/* Build the ResultColumnList to return */
rcList.addResultColumn(resultColumn);
}
return rcList;
}
use of org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList in project derby by apache.
the class TableElementList method findIllegalGenerationReferences.
/**
* Complain if a generation clause references other generated columns. This
* is required by the SQL Standard, part 2, section 4.14.8.
*
* @param fromList The FromList in question.
* @param baseTable Table descriptor if this is an ALTER TABLE statement.
* @exception StandardException Thrown on error
*/
void findIllegalGenerationReferences(FromList fromList, TableDescriptor baseTable) throws StandardException {
ArrayList<ColumnDefinitionNode> generatedColumns = new ArrayList<ColumnDefinitionNode>();
HashSet<String> names = new HashSet<String>();
// add in existing generated columns if this is an ALTER TABLE statement
if (baseTable != null) {
ColumnDescriptorList cdl = baseTable.getGeneratedColumns();
int count = cdl.size();
for (int i = 0; i < count; i++) {
names.add(cdl.elementAt(i).getColumnName());
}
}
// find all of the generated columns
for (TableElementNode element : this) {
ColumnDefinitionNode cdn;
if (!(element instanceof ColumnDefinitionNode)) {
continue;
}
cdn = (ColumnDefinitionNode) element;
if (!cdn.hasGenerationClause()) {
continue;
}
generatedColumns.add(cdn);
names.add(cdn.getColumnName());
}
// now look at their generation clauses to see if they reference one
// another
int count = generatedColumns.size();
for (int i = 0; i < count; i++) {
ColumnDefinitionNode cdn = generatedColumns.get(i);
GenerationClauseNode generationClauseNode = cdn.getGenerationClauseNode();
List<ColumnReference> referencedColumns = generationClauseNode.findReferencedColumns();
int refCount = referencedColumns.size();
for (int j = 0; j < refCount; j++) {
String name = referencedColumns.get(j).getColumnName();
if (name != null) {
if (names.contains(name)) {
throw StandardException.newException(SQLState.LANG_CANT_REFERENCE_GENERATED_COLUMN, cdn.getColumnName());
}
}
}
}
}
Aggregations