columnIdx < targetTable.getColumnCount() - 1 ? targetTable.getColumn(columnIdx + 1) :null, targetColumn));
targetColumn, columnIdx > 0 ? targetTable.getColumn(columnIdx - 1) : null, columnIdx < targetTable.getColumnCount() - 1 ? targetTable.getColumn(columnIdx + 1) :null));
    public List compareTables(Database sourceModel,                              Table    sourceTable,                              Database targetModel,                              Table    targetTable)    {        ArrayList changes = new ArrayList();        for (int fkIdx = 0; fkIdx < sourceTable.getForeignKeyCount(); fkIdx++)        {            ForeignKey sourceFk = sourceTable.getForeignKey(fkIdx);            ForeignKey targetFk = findCorrespondingForeignKey(targetTable, sourceFk);            if (targetFk == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Foreign key " + sourceFk + " needs to be removed from table " + sourceTable.getName());                }                changes.add(new RemoveForeignKeyChange(sourceTable, sourceFk));            }        }        for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)        {            ForeignKey targetFk = targetTable.getForeignKey(fkIdx);            ForeignKey sourceFk = findCorrespondingForeignKey(sourceTable, targetFk);            if (sourceFk == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Foreign key " + targetFk + " needs to be created for table " + sourceTable.getName());                }                // we have to use the target table here because the foreign key might                // reference a new column                changes.add(new AddForeignKeyChange(targetTable, targetFk));            }        }        for (int indexIdx = 0; indexIdx < sourceTable.getIndexCount(); indexIdx++)        {            Index sourceIndex = sourceTable.getIndex(indexIdx);            Index targetIndex = findCorrespondingIndex(targetTable, sourceIndex);            if (targetIndex == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Index " + sourceIndex.getName() + " needs to be removed from table " + sourceTable.getName());                }                changes.add(new RemoveIndexChange(sourceTable, sourceIndex));            }        }        for (int indexIdx = 0; indexIdx < targetTable.getIndexCount(); indexIdx++)        {            Index targetIndex = targetTable.getIndex(indexIdx);            Index sourceIndex = findCorrespondingIndex(sourceTable, targetIndex);            if (sourceIndex == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Index " + targetIndex.getName() + " needs to be created for table " + sourceTable.getName());                }                // we have to use the target table here because the index might                // reference a new column                changes.add(new AddIndexChange(targetTable, targetIndex));            }        }        for (int columnIdx = 0; columnIdx < targetTable.getColumnCount(); columnIdx++)        {            Column targetColumn = targetTable.getColumn(columnIdx);            Column sourceColumn = sourceTable.findColumn(targetColumn.getName(), _caseSensitive);            if (sourceColumn == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Column " + targetColumn.getName() + " needs to be created for table " + sourceTable.getName());                }                changes.add(new AddColumnChange(sourceTable,                                                columnIdx < targetTable.getColumnCount() - 1 ? targetTable.getColumn(columnIdx + 1) :null,                                                targetColumn));            }            else            {                changes.addAll(compareColumns(sourceTable, sourceColumn, targetTable, targetColumn));            }        }        Column[] sourcePK = sourceTable.getPrimaryKeyColumns();        Column[] targetPK = targetTable.getPrimaryKeyColumns();        if ((sourcePK.length == 0) && (targetPK.length > 0))        {            if (_log.isInfoEnabled())            {                _log.info("A primary key needs to be added to the table " + sourceTable.getName());            }            // we have to use the target table here because the primary key might            // reference a new column            changes.add(new AddPrimaryKeyChange(targetTable, targetPK));        }        else if ((targetPK.length == 0) && (sourcePK.length > 0))        {            if (_log.isInfoEnabled())            {                _log.info("The primary key needs to be removed from the table " + sourceTable.getName());            }            changes.add(new RemovePrimaryKeyChange(sourceTable, sourcePK));        }        else if ((sourcePK.length > 0) && (targetPK.length > 0))        {            boolean changePK = false;            if (sourcePK.length != targetPK.length)            {                changePK = true;            }            else            {                for (int pkColumnIdx = 0; (pkColumnIdx < sourcePK.length) && !changePK; pkColumnIdx++)                {                    if ((_caseSensitive  && !sourcePK[pkColumnIdx].getName().equals(targetPK[pkColumnIdx].getName())) ||                        (!_caseSensitive && !sourcePK[pkColumnIdx].getName().equalsIgnoreCase(targetPK[pkColumnIdx].getName())))                    {                        changePK = true;                    }                }            }            if (changePK)            {                if (_log.isInfoEnabled())                {                    _log.info("The primary key of table " + sourceTable.getName() + " needs to be changed");                }                changes.add(new PrimaryKeyChange(sourceTable, sourcePK, targetPK));            }        }                for (int columnIdx = 0; columnIdx < sourceTable.getColumnCount(); columnIdx++)        {            Column sourceColumn = sourceTable.getColumn(columnIdx);            Column targetColumn = targetTable.findColumn(sourceColumn.getName(), _caseSensitive);            if (targetColumn == null)            {                if (_log.isInfoEnabled())                {                    _log.info("Column " + sourceColumn.getName() + " needs to be removed from table " + sourceTable.getName());                }                changes.add(new RemoveColumnChange(sourceTable, sourceColumn));            }        }        return changes;    }