include version number in log message

This commit is contained in:
Ken Stevens 2019-10-31 17:12:02 -04:00
parent 0cfea8a871
commit d1814947b3
18 changed files with 43 additions and 40 deletions

View File

@ -22,8 +22,7 @@ public class FlywayMigration implements JavaMigration {
@Override
public MigrationVersion getVersion() {
String flywayVersion = myTask.getFlywayVersion();
return MigrationVersion.fromVersion(flywayVersion);
return MigrationVersion.fromVersion(myTask.getFlywayVersion());
}
@Override

View File

@ -45,7 +45,7 @@ public class AddColumnTask extends BaseTableColumnTypeTask<AddColumnTask> {
public void execute() throws SQLException {
Set<String> columnNames = JdbcUtils.getColumnNames(getConnectionProperties(), getTableName());
if (columnNames.contains(getColumnName())) {
ourLog.info("Column {} already exists on table {} - No action performed", getColumnName(), getTableName());
logInfo(ourLog, "Column {} already exists on table {} - No action performed", getColumnName(), getTableName());
return;
}
@ -68,7 +68,7 @@ public class AddColumnTask extends BaseTableColumnTypeTask<AddColumnTask> {
throw new IllegalStateException();
}
ourLog.info("Adding column {} of type {} to table {}", getColumnName(), getSqlType(), getTableName());
logInfo(ourLog, "Adding column {} of type {} to table {}", getColumnName(), getSqlType(), getTableName());
executeSql(getTableName(), sql);
}

View File

@ -69,7 +69,7 @@ public class AddForeignKeyTask extends BaseTableColumnTask<AddForeignKeyTask> {
Set<String> existing = JdbcUtils.getForeignKeys(getConnectionProperties(), myForeignTableName, getTableName());
if (existing.contains(myConstraintName)) {
ourLog.info("Already have constraint named {} - No action performed", myConstraintName);
logInfo(ourLog, "Already have constraint named {} - No action performed", myConstraintName);
return;
}

View File

@ -90,7 +90,7 @@ public class AddIdGeneratorTask extends BaseTask<AddIdGeneratorTask> {
.collect(Collectors.toSet());
ourLog.debug("Currently have sequences: {}", sequenceNames);
if (sequenceNames.contains(myGeneratorName.toLowerCase())) {
ourLog.info("Sequence {} already exists - No action performed", myGeneratorName);
logInfo(ourLog, "Sequence {} already exists - No action performed", myGeneratorName);
return;
}

View File

@ -69,11 +69,11 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
public void execute() throws SQLException {
Set<String> indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName());
if (indexNames.contains(myIndexName)) {
ourLog.info("Index {} already exists on table {} - No action performed", myIndexName, getTableName());
logInfo(ourLog, "Index {} already exists on table {} - No action performed", myIndexName, getTableName());
return;
}
ourLog.info("Going to add a {} index named {} on table {} for columns {}", (myUnique ? "UNIQUE" : "NON-UNIQUE"), myIndexName, getTableName(), myColumns);
logInfo(ourLog, "Going to add a {} index named {} on table {} for columns {}", (myUnique ? "UNIQUE" : "NON-UNIQUE"), myIndexName, getTableName(), myColumns);
String unique = myUnique ? "unique " : "";
String columns = String.join(", ", myColumns);

View File

@ -55,7 +55,7 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
public void execute() throws SQLException {
if (JdbcUtils.getTableNames(getConnectionProperties()).contains(getTableName())) {
ourLog.info("Already have table named {} - No action performed", getTableName());
logInfo(ourLog, "Already have table named {} - No action performed", getTableName());
return;
}

View File

@ -55,14 +55,14 @@ public class AddTableRawSqlTask extends BaseTableTask<AddTableRawSqlTask> {
public void execute() throws SQLException {
Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties());
if (tableNames.contains(getTableName())) {
ourLog.info("Table {} already exists - No action performed", getTableName());
logInfo(ourLog, "Table {} already exists - No action performed", getTableName());
return;
}
List<String> sqlStatements = myDriverToSqls.computeIfAbsent(getDriverType(), t -> new ArrayList<>());
sqlStatements.addAll(myDriverNeutralSqls);
ourLog.info("Going to create table {} using {} SQL statements", getTableName(), sqlStatements.size());
logInfo(ourLog, "Going to create table {} using {} SQL statements", getTableName(), sqlStatements.size());
getConnectionProperties().getTxTemplate().execute(t -> {
JdbcTemplate jdbcTemplate = getConnectionProperties().newJdbcTemplate();

View File

@ -62,12 +62,12 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
@Override
public void execute() throws SQLException {
ourLog.info("Starting: {}", myDescription);
logInfo(ourLog, "Starting: {}", myDescription);
if (StringUtils.isNotBlank(myExecuteOnlyIfTableExists)) {
Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties());
if (!tableNames.contains(myExecuteOnlyIfTableExists.toUpperCase())) {
ourLog.info("Table {} does not exist - No action performed", myExecuteOnlyIfTableExists);
logInfo(ourLog, "Table {} does not exist - No action performed", myExecuteOnlyIfTableExists);
return;
}
}
@ -75,7 +75,7 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
for (TableAndColumn next : myConditionalOnExistenceOf) {
JdbcUtils.ColumnType columnType = JdbcUtils.getColumnType(getConnectionProperties(), next.getTable(), next.getColumn());
if (columnType == null) {
ourLog.info("Table {} does not have column {} - No action performed", next.getTable(), next.getColumn());
logInfo(ourLog, "Table {} does not have column {} - No action performed", next.getTable(), next.getColumn());
return;
}
}
@ -129,14 +129,14 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
List<Map<String, Object>> rows;
do {
ourLog.info("Querying for up to {} rows", myBatchSize);
logInfo(ourLog, "Querying for up to {} rows", myBatchSize);
rows = getTxTemplate().execute(t -> {
JdbcTemplate jdbcTemplate = newJdbcTemnplate();
jdbcTemplate.setMaxRows(myBatchSize);
return jdbcTemplate.query(mySql, new ColumnMapRowMapper());
});
ourLog.info("Processing {} rows", rows.size());
logInfo(ourLog, "Processing {} rows", rows.size());
List<Map<String, Object>> finalRows = rows;
getTxTemplate().execute(t -> {
for (Map<String, Object> nextRow : finalRows) {

View File

@ -99,7 +99,7 @@ public abstract class BaseTask<T extends BaseTask> {
Integer changes = getConnectionProperties().getTxTemplate().execute(t -> {
JdbcTemplate jdbcTemplate = getConnectionProperties().newJdbcTemplate();
int changesCount = jdbcTemplate.update(theSql, theArguments);
ourLog.info("SQL \"{}\" returned {}", theSql, changesCount);
logInfo(ourLog, "SQL \"{}\" returned {}", theSql, changesCount);
return changesCount;
});
@ -150,6 +150,10 @@ public abstract class BaseTask<T extends BaseTask> {
return releasePart + "." + myVersion;
}
protected void logInfo(Logger theLog, String theFormattedMessage, Object... theArguments) {
theLog.info(getFlywayVersion() + ": " + theFormattedMessage, theArguments);
}
public void validateVersion() {
Matcher matcher = versionPattern.matcher(myVersion);
if (!matcher.matches()) {

View File

@ -73,7 +73,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
JdbcTemplate jdbcTemplate = newJdbcTemnplate();
jdbcTemplate.setMaxRows(100000);
String sql = "SELECT * FROM " + getTableName() + " WHERE " + getColumnName() + " IS NULL";
ourLog.info("Finding up to {} rows in {} that requires hashes", myBatchSize, getTableName());
logInfo(ourLog, "Finding up to {} rows in {} that requires hashes", myBatchSize, getTableName());
jdbcTemplate.query(sql, rch);
rch.done();
@ -87,7 +87,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
break;
}
ourLog.info("Waiting for {} tasks to complete", futures.size());
logInfo(ourLog, "Waiting for {} tasks to complete", futures.size());
for (Future<?> next : futures) {
try {
next.get();
@ -119,7 +119,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable theRunnable, ThreadPoolExecutor theExecutor) {
ourLog.info("Note: Executor queue is full ({} elements), waiting for a slot to become available!", executorQueue.size());
logInfo(ourLog, "Note: Executor queue is full ({} elements), waiting for a slot to become available!", executorQueue.size());
StopWatch sw = new StopWatch();
try {
executorQueue.put(theRunnable);
@ -127,7 +127,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
throw new RejectedExecutionException("Task " + theRunnable.toString() +
" rejected from " + theE.toString());
}
ourLog.info("Slot become available after {}ms", sw.getMillis());
logInfo(ourLog, "Slot become available after {}ms", sw.getMillis());
}
};
myExecutor = new ThreadPoolExecutor(
@ -183,7 +183,7 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
return theRows.size();
});
ourLog.info("Updated {} rows on {} in {}", theRows.size(), getTableName(), sw.toString());
logInfo(ourLog, "Updated {} rows on {} in {}", theRows.size(), getTableName(), sw.toString());
};
return myExecutor.submit(task);
}

View File

@ -40,14 +40,14 @@ public class DropColumnTask extends BaseTableColumnTask<DropColumnTask> {
public void execute() throws SQLException {
Set<String> columnNames = JdbcUtils.getColumnNames(getConnectionProperties(), getTableName());
if (!columnNames.contains(getColumnName())) {
ourLog.info("Column {} does not exist on table {} - No action performed", getColumnName(), getTableName());
logInfo(ourLog, "Column {} does not exist on table {} - No action performed", getColumnName(), getTableName());
return;
}
String tableName = getTableName();
String columnName = getColumnName();
String sql = createSql(tableName, columnName);
ourLog.info("Dropping column {} on table {}", getColumnName(), getTableName());
logInfo(ourLog, "Dropping column {} on table {}", getColumnName(), getTableName());
executeSql(getTableName(), sql);
}

View File

@ -67,7 +67,7 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
Set<String> existing = JdbcUtils.getForeignKeys(getConnectionProperties(), myParentTableName, getTableName());
if (!existing.contains(myConstraintName)) {
ourLog.info("Don't have constraint named {} - No action performed", myConstraintName);
logInfo(ourLog, "Don't have constraint named {} - No action performed", myConstraintName);
return;
}

View File

@ -90,7 +90,7 @@ public class DropIdGeneratorTask extends BaseTask<DropIdGeneratorTask> {
.collect(Collectors.toSet());
ourLog.debug("Currently have sequences: {}", sequenceNames);
if (!sequenceNames.contains(myGeneratorName.toLowerCase())) {
ourLog.info("Sequence {} does not exist - No action performed", myGeneratorName);
logInfo(ourLog, "Sequence {} does not exist - No action performed", myGeneratorName);
return;
}

View File

@ -56,7 +56,7 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
Set<String> indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName());
if (!indexNames.contains(myIndexName)) {
ourLog.info("Index {} does not exist on table {} - No action needed", myIndexName, getTableName());
logInfo(ourLog, "Index {} does not exist on table {} - No action needed", myIndexName, getTableName());
return;
}
@ -65,7 +65,7 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
Optional<String> sql = createDropIndexSql(getConnectionProperties(), getTableName(), myIndexName, getDriverType());
if (sql.isPresent()) {
ourLog.info("Dropping {} index {} on table {}", uniquenessString, myIndexName, getTableName());
logInfo(ourLog, "Dropping {} index {} on table {}", uniquenessString, myIndexName, getTableName());
executeSql(getTableName(), sql.get());
}
}

View File

@ -45,10 +45,10 @@ public class DropTableTask extends BaseTableTask<DropTableTask> {
}
Set<String> foreignKeys = JdbcUtils.getForeignKeys(getConnectionProperties(), null, getTableName());
ourLog.info("Table {} has the following foreign keys: {}", getTableName(), foreignKeys);
logInfo(ourLog, "Table {} has the following foreign keys: {}", getTableName(), foreignKeys);
Set<String> indexNames = JdbcUtils.getIndexNames(getConnectionProperties(), getTableName());
ourLog.info("Table {} has the following indexes: {}", getTableName(), indexNames);
logInfo(ourLog, "Table {} has the following indexes: {}", getTableName(), indexNames);
for (String next : foreignKeys) {
List<String> sql = DropForeignKeyTask.generateSql(getTableName(), next, getDriverType());
@ -60,12 +60,12 @@ public class DropTableTask extends BaseTableTask<DropTableTask> {
for (String nextIndex : indexNames) {
Optional<String> sql = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType());
if (sql.isPresent()) {
ourLog.info("Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName());
logInfo(ourLog, "Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName());
executeSql(getTableName(), sql.get());
}
}
ourLog.info("Dropping table: {}", getTableName());
logInfo(ourLog, "Dropping table: {}", getTableName());
String sql = "DROP TABLE " + getTableName();
executeSql(getTableName(), sql);

View File

@ -65,7 +65,7 @@ public class ExecuteRawSqlTask extends BaseTask<ExecuteRawSqlTask> {
List<String> sqlStatements = myDriverToSqls.computeIfAbsent(getDriverType(), t -> new ArrayList<>());
sqlStatements.addAll(myDriverNeutralSqls);
ourLog.info("Going to execute {} SQL statements", sqlStatements.size());
logInfo(ourLog, "Going to execute {} SQL statements", sqlStatements.size());
for (String nextSql : sqlStatements) {
executeSql(null, nextSql);

View File

@ -49,7 +49,7 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
Set<String> columnNames = JdbcUtils.getColumnNames(getConnectionProperties(), getTableName());
if (!columnNames.contains(getColumnName())) {
ourLog.info("Column {} doesn't exist on table {} - No action performed", getColumnName(), getTableName());
logInfo(ourLog, "Column {} doesn't exist on table {} - No action performed", getColumnName(), getTableName());
return;
}
@ -71,7 +71,7 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
boolean alreadyOfCorrectType = existingType.equals(getColumnType(), columnLength);
boolean alreadyCorrectNullable = isNullable() == nullable;
if (alreadyOfCorrectType && alreadyCorrectNullable) {
ourLog.info("Column {} on table {} is already of type {} and has nullable {} - No action performed", getColumnName(), getTableName(), existingType, nullable);
logInfo(ourLog, "Column {} on table {} is already of type {} and has nullable {} - No action performed", getColumnName(), getTableName(), existingType, nullable);
return;
}
@ -128,13 +128,13 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
throw new IllegalStateException("Dont know how to handle " + getDriverType());
}
ourLog.info("Updating column {} on table {} to type {}", getColumnName(), getTableName(), type);
logInfo(ourLog, "Updating column {} on table {} to type {}", getColumnName(), getTableName(), type);
if (sql != null) {
executeSql(getTableName(), sql);
}
if (sqlNotNull != null) {
ourLog.info("Updating column {} on table {} to not null", getColumnName(), getTableName());
logInfo(ourLog, "Updating column {} on table {} to not null", getColumnName(), getTableName());
executeSql(getTableName(), sqlNotNull);
}
}

View File

@ -76,7 +76,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because both columns exist and data exists in " + myNewName);
}
ourLog.info("Table {} has columns {} and {} - Going to drop {} before renaming", getTableName(), myOldName, myNewName, myNewName);
logInfo(ourLog, "Table {} has columns {} and {} - Going to drop {} before renaming", getTableName(), myOldName, myNewName, myNewName);
String sql = DropColumnTask.createSql(getTableName(), myNewName);
executeSql(getTableName(), sql);
} else {
@ -88,7 +88,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
}
throw new SQLException("Can not rename " + getTableName() + "." + myOldName + " to " + myNewName + " because neither column exists!");
} else if (haveNewName) {
ourLog.info("Column {} already exists on table {} - No action performed", myNewName, getTableName());
logInfo(ourLog, "Column {} already exists on table {} - No action performed", myNewName, getTableName());
return;
}
@ -117,7 +117,7 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
throw new IllegalStateException();
}
ourLog.info("Renaming column {} on table {} to {}", myOldName, getTableName(), myNewName);
logInfo(ourLog, "Renaming column {} on table {} to {}", myOldName, getTableName(), myNewName);
executeSql(getTableName(), sql);
}