Only log one line and don't create a Statement and then decide not to use it

because the migration has already been performed.
This commit is contained in:
Michael Bayne
2007-02-18 21:43:08 +00:00
parent 84c842aeeb
commit 2bc9c26119
@@ -79,31 +79,30 @@ public abstract class EntityMigration extends Modifier
}
public int invoke (Connection conn) throws SQLException {
if (!JDBCUtil.tableContainsColumn(conn, _tableName, _oldColumnName)) {
if (JDBCUtil.tableContainsColumn(conn, _tableName, _newColumnName)) {
// we'll accept this inconsistency
log.warning(_tableName + "." + _oldColumnName + " already renamed to " +
_newColumnName + ".");
return 0;
}
// but this is not OK
throw new IllegalArgumentException(
_tableName + " does not contain '" + _oldColumnName + "'");
}
// nor is this
if (JDBCUtil.tableContainsColumn(conn, _tableName, _newColumnName)) {
throw new IllegalArgumentException(
_tableName + " already contains '" + _newColumnName + "'");
}
Statement stmt = conn.createStatement();
try {
log.info("Changing '" + _oldColumnName + "' to '" + _newColumnDef + "' in " +
_tableName);
if (!JDBCUtil.tableContainsColumn(conn, _tableName, _oldColumnName)) {
if (JDBCUtil.tableContainsColumn(conn, _tableName, _newColumnName)) {
// we'll accept this inconsistency
log.warning("Column rename appears already performed.");
return 0;
}
// but this is not OK
throw new IllegalArgumentException(
_tableName + " does not contain '" + _oldColumnName + "'");
}
// nor is this
if (JDBCUtil.tableContainsColumn(conn, _tableName, _newColumnName)) {
throw new IllegalArgumentException(
_tableName + " already contains '" + _newColumnName + "'");
}
return stmt.executeUpdate("alter table " + _tableName + " change column " +
_oldColumnName + " " + _newColumnDef);
} finally {
stmt.close();
}