versionGenerator.setGeneratingLogging(isGeneratingLogging());
boolean isFirstTable = true;
for (Iterator iter = myTables.iterator(); iter.hasNext(); ) {
String tableName = (String) iter.next();
Table table = sch.getTable(tableName);
if (table == null) {
throw new IllegalArgumentException("Invalid table name: " + tableName);
}
VersionGenerator.ColumnUpdater columnUpdater;
if (isFirstTable) {
Column column = null;
int columnNum = -1;
int i = 0;
for (Iterator colIter = table.getColumns(); colIter.hasNext(); i++) {
Column colIterColumn = (Column) colIter.next();
if (colIterColumn.getName().equals(columnName)) {
column = colIterColumn;
columnNum = i;
break;
}
}
if (column == null) {
throw new IllegalArgumentException("No column " + columnName +
" found in table " + table.getQName());
}
isFirstTable = false;
columnUpdater = new VerNumIncrementer(columnNum);
} else {
List pkColumns = new ArrayList();
Index primaryKey = table.getPrimaryKey();
if (primaryKey != null) {
for (Iterator pkIter = primaryKey.getColumns(); pkIter.hasNext(); ) {
Column pkColumn = (Column) pkIter.next();
int columnNum = -1;
int i = 0;
for (Iterator colIter = table.getColumns(); colIter.hasNext(); i++) {
Column colIterColumn = (Column) colIter.next();
if (colIterColumn.getName().equals(pkColumn.getName())) {
columnNum = i;
break;
}
}
if (columnNum == -1) {
throw new IllegalStateException("Primary key column " + pkColumn.getQName() +
" not found in table " + table.getQName());
}
pkColumns.add(new Integer(columnNum));
}
}
if (pkColumns.size() == 0) {
throw new IllegalArgumentException("The table " + table.getQName() +
" doesn't have a primary key.");
}
columnUpdater = new IdIncrementer(pkColumns);
}
versionGenerator.addTable(table, columnUpdater);