Skip to content

Commit

Permalink
Merge pull request #2217 from liquibase/LB-2126
Browse files Browse the repository at this point in the history
Make lock granted time be consistent with date executed time.  Modify listLocks message. LB-2126
  • Loading branch information
suryaaki2 committed Jan 12, 2022
2 parents 491eead + 648e2a0 commit f5a9b16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion liquibase-core/src/main/java/liquibase/Liquibase.java
Expand Up @@ -1942,12 +1942,13 @@ public void reportLocks(PrintStream out) throws LiquibaseException {
+ "@" + getDatabase().getConnection().getURL());
if (locks.length == 0) {
out.println(" - No locks");
return;
}
for (DatabaseChangeLogLock lock : locks) {
out.println(" - " + lock.getLockedBy() + " at " +
DateFormat.getDateTimeInstance().format(lock.getLockGranted()));
}

out.println("NOTE: The lock time displayed is based on the database's configured time");
}

public void forceReleaseLocks() throws LiquibaseException {
Expand Down
Expand Up @@ -8,6 +8,7 @@
import liquibase.sql.Sql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.SqlGeneratorFactory;
import liquibase.statement.DatabaseFunction;
import liquibase.statement.core.LockDatabaseChangeLogStatement;
import liquibase.statement.core.UpdateStatement;
import liquibase.util.NetUtil;
Expand Down Expand Up @@ -44,9 +45,10 @@ public Sql[] generateSql(LockDatabaseChangeLogStatement statement, Database data
ObjectQuotingStrategy currentStrategy = database.getObjectQuotingStrategy();
database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY);
try {
String dateValue = database.getCurrentDateTimeFunction();
UpdateStatement updateStatement = new UpdateStatement(liquibaseCatalog, liquibaseSchema, database.getDatabaseChangeLogLockTableName());
updateStatement.addNewColumnValue("LOCKED", true);
updateStatement.addNewColumnValue("LOCKGRANTED", new Timestamp(new java.util.Date().getTime()));
updateStatement.addNewColumnValue("LOCKGRANTED", new DatabaseFunction(dateValue));
updateStatement.addNewColumnValue("LOCKEDBY", hostname + hostDescription + " (" + hostaddress + ")");
updateStatement.setWhereClause(database.escapeColumnName(liquibaseCatalog, liquibaseSchema, database.getDatabaseChangeLogTableName(), "ID") + " = 1 AND " + database.escapeColumnName(liquibaseCatalog, liquibaseSchema, database.getDatabaseChangeLogTableName(), "LOCKED") + " = "+ DataTypeFactory.getInstance().fromDescription("boolean", database).objectToSql(false, database));

Expand Down

0 comments on commit f5a9b16

Please sign in to comment.