Coverage Report - liquibase.change.core.RenameTableChange
 
Classes in this File Line Coverage Branch Coverage Complexity
RenameTableChange
78%
18/23
100%
4/4
1.2
 
 1  
 package liquibase.change.core;
 2  
 
 3  
 import liquibase.change.AbstractChange;
 4  
 import liquibase.change.Change;
 5  
 import liquibase.change.ChangeMetaData;
 6  
 import liquibase.database.Database;
 7  
 import liquibase.database.core.DB2Database;
 8  
 import liquibase.statement.SqlStatement;
 9  
 import liquibase.statement.core.RenameTableStatement;
 10  
 import liquibase.statement.core.ReorganizeTableStatement;
 11  
 import liquibase.util.StringUtils;
 12  
 
 13  
 import java.util.ArrayList;
 14  
 import java.util.List;
 15  
 
 16  
 /**
 17  
  * Renames an existing table.
 18  
  */
 19  
 public class RenameTableChange extends AbstractChange {
 20  
 
 21  
     private String schemaName;
 22  
     private String oldTableName;
 23  
 
 24  
     private String newTableName;
 25  
 
 26  
     public RenameTableChange() {
 27  21
         super("renameTable", "Rename Table", ChangeMetaData.PRIORITY_DEFAULT);
 28  21
     }
 29  
 
 30  
     public String getSchemaName() {
 31  45
         return schemaName;
 32  
     }
 33  
 
 34  
     public void setSchemaName(String schemaName) {
 35  2
         this.schemaName = StringUtils.trimToNull(schemaName);
 36  2
     }
 37  
 
 38  
     public String getOldTableName() {
 39  44
         return oldTableName;
 40  
     }
 41  
 
 42  
     public void setOldTableName(String oldTableName) {
 43  3
         this.oldTableName = oldTableName;
 44  3
     }
 45  
 
 46  
     public String getNewTableName() {
 47  47
         return newTableName;
 48  
     }
 49  
 
 50  
     public void setNewTableName(String newTableName) {
 51  3
         this.newTableName = newTableName;
 52  3
     }
 53  
 
 54  
     public SqlStatement[] generateStatements(Database database) {
 55  44
         List<SqlStatement> statements = new ArrayList<SqlStatement>();
 56  44
         String schemaName = getSchemaName() == null ? database.getDefaultSchemaName() : getSchemaName();
 57  44
         statements.add(new RenameTableStatement(schemaName, getOldTableName(), getNewTableName()));
 58  44
         if (database instanceof DB2Database) {
 59  3
             statements.add(new ReorganizeTableStatement(schemaName, getNewTableName()));
 60  
         }
 61  
 
 62  44
         return statements.toArray(new SqlStatement[statements.size()]);
 63  
     }
 64  
 
 65  
     @Override
 66  
     protected Change[] createInverses() {
 67  0
         RenameTableChange inverse = new RenameTableChange();
 68  0
         inverse.setSchemaName(getSchemaName());
 69  0
         inverse.setOldTableName(getNewTableName());
 70  0
         inverse.setNewTableName(getOldTableName());
 71  
 
 72  0
         return new Change[] { inverse };
 73  
     }
 74  
 
 75  
     public String getConfirmationMessage() {
 76  1
         return "Table " + oldTableName + " renamed to " + newTableName;
 77  
     }
 78  
 }