Coverage Report - liquibase.sqlgenerator.core.RenameViewGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
RenameViewGenerator
41%
7/17
66%
16/24
4.667
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.core.CacheDatabase;
 5  
 import liquibase.database.core.DB2Database;
 6  
 import liquibase.database.core.DerbyDatabase;
 7  
 import liquibase.database.core.FirebirdDatabase;
 8  
 import liquibase.database.core.H2Database;
 9  
 import liquibase.database.core.HsqlDatabase;
 10  
 import liquibase.database.core.InformixDatabase;
 11  
 import liquibase.database.core.MSSQLDatabase;
 12  
 import liquibase.database.core.MaxDBDatabase;
 13  
 import liquibase.database.core.MySQLDatabase;
 14  
 import liquibase.database.core.OracleDatabase;
 15  
 import liquibase.database.core.PostgresDatabase;
 16  
 import liquibase.database.core.SybaseASADatabase;
 17  
 import liquibase.exception.ValidationErrors;
 18  
 import liquibase.sql.Sql;
 19  
 import liquibase.sql.UnparsedSql;
 20  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 21  
 import liquibase.statement.core.RenameViewStatement;
 22  
 
 23  63
 public class RenameViewGenerator extends AbstractSqlGenerator<RenameViewStatement> {
 24  
 
 25  
     @Override
 26  
     public boolean supports(RenameViewStatement statement, Database database) {
 27  46
         return !(database instanceof DerbyDatabase || database instanceof HsqlDatabase
 28  
                 || database instanceof H2Database || database instanceof DB2Database
 29  
                 || database instanceof CacheDatabase || database instanceof FirebirdDatabase
 30  
                 || database instanceof InformixDatabase || database instanceof SybaseASADatabase);
 31  
     }
 32  
 
 33  
     @Override
 34  
     public ValidationErrors validate(RenameViewStatement renameViewStatement, Database database,
 35  
             SqlGeneratorChain sqlGeneratorChain) {
 36  7
         ValidationErrors validationErrors = new ValidationErrors();
 37  7
         validationErrors.checkRequiredField("oldViewName", renameViewStatement.getOldViewName());
 38  7
         validationErrors.checkRequiredField("newViewName", renameViewStatement.getNewViewName());
 39  
 
 40  7
         validationErrors.checkDisallowedField("schemaName", renameViewStatement.getSchemaName(), database,
 41  
                 OracleDatabase.class);
 42  
 
 43  7
         return validationErrors;
 44  
     }
 45  
 
 46  
     @Override
 47  
     public Sql[] generateSql(RenameViewStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
 48  
         String sql;
 49  
 
 50  0
         if (database instanceof MSSQLDatabase) {
 51  0
             sql = "exec sp_rename '" + database.escapeViewName(statement.getSchemaName(), statement.getOldViewName())
 52  
                     + "', '" + statement.getNewViewName() + '\'';
 53  0
         } else if (database instanceof MySQLDatabase) {
 54  0
             sql = "RENAME TABLE " + database.escapeViewName(statement.getSchemaName(), statement.getOldViewName())
 55  
                     + " TO " + database.escapeViewName(statement.getSchemaName(), statement.getNewViewName());
 56  0
         } else if (database instanceof PostgresDatabase) {
 57  0
             sql = "ALTER TABLE " + database.escapeViewName(statement.getSchemaName(), statement.getOldViewName())
 58  
                     + " RENAME TO " + database.escapeViewName(null, statement.getNewViewName());
 59  0
         } else if (database instanceof MaxDBDatabase) {
 60  0
             sql = "RENAME VIEW " + database.escapeViewName(statement.getSchemaName(), statement.getOldViewName())
 61  
                     + " TO " + database.escapeViewName(null, statement.getNewViewName());
 62  
         } else {
 63  0
             sql = "RENAME " + database.escapeViewName(statement.getSchemaName(), statement.getOldViewName()) + " TO "
 64  
                     + database.escapeViewName(null, statement.getNewViewName());
 65  
         }
 66  
 
 67  0
         return new Sql[] { new UnparsedSql(sql) };
 68  
     }
 69  
 }