String name = /*cols[i].getCatalog() + "." +*/ cols[i].getSchema() + "." + cols[i].getTable() + "." + cols[i].getColName();
map2.put(name, cols[i]);
}
// scan map1
Map ret = new TreeMap();
String[] keys = (String[])map1.keySet().toArray(new String[map1.size()]);
for (int i=0; i < keys.length; i++) {
SqlColumn[] val = new SqlColumn[2];
SqlColumn val1 = (SqlColumn)map1.get(keys[i]);
SqlColumn val2 = (SqlColumn)map2.remove(keys[i]);
if (val2 == null) { // then the column has been deleted
val[0] = val1;
val[1] = null;
ret.put(keys[i], val);
}
else { // check if it has changed
if(!val1.isSame(val2)) {
ret.put(keys[i], new SqlColumn[] { val1, val2 });
}
}
}
// and now scam map2 for still remaining (new) columns
keys = (String[])map2.keySet().toArray(new String[map2.size()]);
for (int i=0; i < keys.length; i++) {
SqlColumn[] val = new SqlColumn[2];
val[0] = null;
val[1] = (SqlColumn)map2.get(keys[i]);
ret.put(keys[i], val);
}
// and now build the output string ...
StringBuffer buf = new StringBuffer(1024);
buf.append("<descDiff>\n");
Iterator iter = ret.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
buf.append("\n\n\n <!-- column ").append(name);
SqlColumn[] val = (SqlColumn[])ret.get(name);
if (val[0] == null) { // new column
buf.append(" NEW -->\n");
buf.append(val[1].toXml(" "));
}
else if (val[1] == null) { // deleted column