* Return the columns set for this version when the columns are spread
* across multiple tables.
*/
public Column[] getMultiTableColumns(Version vers, Column[] templates,
boolean adapt) {
Table primaryTable = vers.getClassMapping().getTable();
List<DBIdentifier> secondaryTableNames = Arrays.asList(vers
.getClassMapping().getMappingInfo().getSecondaryTableIdentifiers());
Map<Table, List<Column>> assign = new LinkedHashMap<Table,
List<Column>>();
for (Column col : templates) {
DBIdentifier tableName = col.getTableIdentifier();
Table table;
if (DBIdentifier.isEmpty(tableName)
|| tableName.equals(primaryTable.getIdentifier())) {
table = primaryTable;
} else if (secondaryTableNames.contains(tableName)) {
table = primaryTable.getSchema().getTable(tableName);
} else {
throw new UserException(_loc.get("bad-version-column-table",
col.getIdentifier().toString(), tableName));
}
if (!assign.containsKey(table))
assign.put(table, new ArrayList<Column>());
assign.get(table).add(col);
}
MappingDefaults def = vers.getMappingRepository().getMappingDefaults();
List<Column> result = new ArrayList<Column>();
Set<Map.Entry<Table,List<Column>>> assignSet = assign.entrySet();
for (Map.Entry<Table,List<Column>> assignEntry : assignSet) {
Table table = assignEntry.getKey();
List<Column> cols = assignEntry.getValue();
Column[] partTemplates = cols.toArray(new Column[cols.size()]);
def.populateColumns(vers, table, partTemplates);
result.addAll(Arrays.asList(createColumns(vers, null, partTemplates,
table, adapt)));