ArrayList newTables = new ArrayList();  for (int tableIdx = 0; tableIdx < desiredModel.getTableCount(); tableIdx++) { Table desiredTable = desiredModel.getTable(tableIdx); Table currentTable = currentModel.findTable(desiredTable.getName());  if (currentTable == null) { if (_log.isInfoEnabled()) { _log.info("Creating table " + desiredTable.getName()); } createTable(desiredModel, desiredTable);  newTables.add(desiredTable); } else { alterTable(currentModel, currentTable, desiredModel, desiredTable, doDrops, modifyColumns); } }    for (Iterator fkIt = newTables.iterator(); fkIt.hasNext();) { createExternalForeignKeys(desiredModel, (Table)fkIt.next()); }   for (int idx = 0; idx < currentModel.getTableCount(); idx++) { Table currentTable = currentModel.getTable(idx); Table desiredTable = desiredModel.findTable(currentTable.getName());  if ((desiredTable == null) && (currentTable.getName() != null) && (currentTable.getName().length() > 0)) { if (doDrops) { if (_log.isInfoEnabled()) { _log.info("Dropping table " + currentTable.getName()); } dropTable(currentTable); } else { String text = "Table " + currentTable.getName() + " can be dropped";  if (_log.isInfoEnabled()) { _log.info(text); } printComment(text); } } }
alterDatabase(currentModel, desiredModel, false, false);
    public void alterDatabase(Database currentModel, Database desiredModel, boolean doDrops, boolean modifyColumns) throws IOException    {        ArrayList newTables = new ArrayList();        for (int tableIdx = 0; tableIdx < desiredModel.getTableCount(); tableIdx++)        {            Table desiredTable = desiredModel.getTable(tableIdx);            Table currentTable = currentModel.findTable(desiredTable.getName());            if (currentTable == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Creating table " + desiredTable.getName());                }                createTable(desiredModel, desiredTable);                // we're deferring foreignkey generation                newTables.add(desiredTable);            }            else            {                alterTable(currentModel, currentTable,                           desiredModel, desiredTable,                           doDrops, modifyColumns);            }        }        // generating deferred foreignkeys        //TODO should we try to generate new FKs on existing tables?        for (Iterator fkIt = newTables.iterator(); fkIt.hasNext();)        {            createExternalForeignKeys(desiredModel, (Table)fkIt.next());        }        // check for table drops        for (int idx = 0; idx < currentModel.getTableCount(); idx++)        {            Table currentTable = currentModel.getTable(idx);            Table desiredTable = desiredModel.findTable(currentTable.getName());            if ((desiredTable == null) && (currentTable.getName() != null) && (currentTable.getName().length() > 0))            {                if (doDrops)                {                    if (_log.isInfoEnabled())                    {                        _log.info("Dropping table " + currentTable.getName());                    }                    dropTable(currentTable);                }                else                {                    String text = "Table " + currentTable.getName() + " can be dropped";                    if (_log.isInfoEnabled())                    {                        _log.info(text);                    }                    printComment(text);                }            }        }    }