qualifiedTableName = getQualifiedTableName(definition, resultSetMetaData, colNumber);
}
final String columnName = getColumnName(definition, resultSetMetaData, colNumber);
final String columnLabel = resultSetMetaData.getColumnLabel(colNumber);
final ColumnMetaData column = Factory.getColumnMetaData();
column.setAttributes(colNumber, databaseName, qualifiedTableName, tableName, columnName,
getQualifiedColumnName(tableName, qualifiedTableName, readOnly, columnName), columnLabel,
getQualifiedColumnLabel(tableName, qualifiedTableName, readOnly, columnLabel),
resultSetMetaData.getColumnTypeName(colNumber),
resultSetMetaData.getColumnType(colNumber), readOnly);
TableMetaData table = (TableMetaDataImpl) tableMap.get(column.getQualifiedTableName());
if (table == null) {
// Create table metadata object and add to special references
final Table tableDef = SqlResourceDefinitionUtils.getTable(definition, column);
if (tableDef == null) {
throw new SqlResourceException("Definition requires table element for "
+ column.getTableName() + ", referenced by column " + column.getColumnLabel());
}
table = Factory.getTableMetaData();
table.setAttributes(tableName, qualifiedTableName, databaseName,
TableRole.valueOf(tableDef.getRole()));
tableMap.put(column.getQualifiedTableName(), table);
tables.add(table);
switch (table.getTableRole()) {
case Parent:
parentTable = table;
if (tableDef.getAlias() != null) {
table.setTableAlias(tableDef.getAlias());
}
// fall through
case ParentExtension:
parentPlusExtTables.add(table);
break;
case Child:
childTable = table;
if (tableDef.getAlias() != null) {
table.setTableAlias(tableDef.getAlias());
}
// fall through
case ChildExtension:
childPlusExtTables.add(table);
break;
case Join: // unlikely to be in the select columns, but just in case
joinTable = table;
joinList = new ArrayList<TableMetaData>(1);
joinList.add(joinTable);
break;
default: // Unknown
}
}
// Add column to the table
table.addColumn(column);
column.setTableRole(table.getTableRole());
// Add column to special column lists
allReadColumns.add(column);
switch (table.getTableRole()) {
case Parent: