Coverage Report - liquibase.sqlgenerator.core.LockDatabaseChangeLogGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
LockDatabaseChangeLogGenerator
7%
1/14
N/A
2
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.typeconversion.TypeConverterFactory;
 5  
 import liquibase.exception.UnexpectedLiquibaseException;
 6  
 import liquibase.exception.ValidationErrors;
 7  
 import liquibase.sql.Sql;
 8  
 import liquibase.sqlgenerator.SqlGenerator;
 9  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 10  
 import liquibase.sqlgenerator.SqlGeneratorFactory;
 11  
 import liquibase.statement.core.LockDatabaseChangeLogStatement;
 12  
 import liquibase.statement.core.UpdateStatement;
 13  
 import liquibase.util.NetUtil;
 14  
 
 15  
 import java.net.InetAddress;
 16  
 import java.sql.Timestamp;
 17  
 
 18  10
 public class LockDatabaseChangeLogGenerator extends AbstractSqlGenerator<LockDatabaseChangeLogStatement> {
 19  
 
 20  
     public ValidationErrors validate(LockDatabaseChangeLogStatement statement, Database database,
 21  
             SqlGeneratorChain sqlGeneratorChain) {
 22  0
         return new ValidationErrors();
 23  
     }
 24  
 
 25  
     public Sql[] generateSql(LockDatabaseChangeLogStatement statement, Database database,
 26  
             SqlGeneratorChain sqlGeneratorChain) {
 27  0
         String liquibaseSchema = null;
 28  0
         liquibaseSchema = database.getLiquibaseSchemaName();
 29  
 
 30  
         InetAddress localHost;
 31  
         try {
 32  0
             localHost = NetUtil.getLocalHost();
 33  0
         } catch (Exception e) {
 34  0
             throw new UnexpectedLiquibaseException(e);
 35  0
         }
 36  
 
 37  0
         UpdateStatement updateStatement = new UpdateStatement(liquibaseSchema,
 38  
                 database.getDatabaseChangeLogLockTableName());
 39  0
         updateStatement.addNewColumnValue("LOCKED", true);
 40  0
         updateStatement.addNewColumnValue("LOCKGRANTED", new Timestamp(new java.util.Date().getTime()));
 41  0
         updateStatement
 42  
                 .addNewColumnValue("LOCKEDBY", localHost.getHostName() + " (" + localHost.getHostAddress() + ")");
 43  0
         updateStatement.setWhereClause(database.escapeColumnName(liquibaseSchema,
 44  
                 database.getDatabaseChangeLogTableName(), "ID")
 45  
                 + " = 1 AND "
 46  
                 + database.escapeColumnName(liquibaseSchema, database.getDatabaseChangeLogTableName(), "LOCKED")
 47  
                 + " = "
 48  
                 + TypeConverterFactory.getInstance().findTypeConverter(database).getBooleanType()
 49  
                         .getFalseBooleanValue());
 50  
 
 51  0
         return SqlGeneratorFactory.getInstance().generateSql(updateStatement, database);
 52  
 
 53  
     }
 54  
 }