Coverage Report - liquibase.sqlgenerator.core.GetViewDefinitionGeneratorMSSQL
 
Classes in this File Line Coverage Branch Coverage Complexity
GetViewDefinitionGeneratorMSSQL
18%
2/11
N/A
2
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.core.MSSQLDatabase;
 5  
 import liquibase.exception.DatabaseException;
 6  
 import liquibase.exception.UnexpectedLiquibaseException;
 7  
 import liquibase.sql.Sql;
 8  
 import liquibase.sql.UnparsedSql;
 9  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 10  
 import liquibase.statement.core.GetViewDefinitionStatement;
 11  
 
 12  10
 public class GetViewDefinitionGeneratorMSSQL extends GetViewDefinitionGenerator {
 13  
     @Override
 14  
     public int getPriority() {
 15  1
         return PRIORITY_DATABASE;
 16  
     }
 17  
 
 18  
     @Override
 19  
     public boolean supports(GetViewDefinitionStatement statement, Database database) {
 20  0
         return database instanceof MSSQLDatabase;
 21  
     }
 22  
 
 23  
     @Override
 24  
     public Sql[] generateSql(GetViewDefinitionStatement statement, Database database,
 25  
             SqlGeneratorChain sqlGeneratorChain) {
 26  
         try {
 27  0
             String sql = "select isnull(object_definition(OBJECT_ID(object_id)), view_definition) from sys.objects, sys.schemas, INFORMATION_SCHEMA.VIEWS where objects.type='v' and upper(objects.name)='"
 28  
                     + statement.getViewName().toUpperCase() + "'";
 29  0
             sql += " and objects.schema_id=schemas.schema_id and schemas.name='"
 30  
                     + database.convertRequestedSchemaToSchema(statement.getSchemaName()) + "'";
 31  0
             sql += " AND upper(table_name)='" + statement.getViewName().toUpperCase() + "'";
 32  
             // if (StringUtils.trimToNull(schemaName) != null) {
 33  0
             sql += " and table_schema='" + database.convertRequestedSchemaToSchema(statement.getSchemaName()) + "'";
 34  0
             sql += " and table_catalog='" + database.getDefaultCatalogName() + "'";
 35  
 
 36  
             // log.info("GetViewDefinitionSQL: "+sql);
 37  
 
 38  0
             return new Sql[] { new UnparsedSql(sql) };
 39  0
         } catch (DatabaseException e) {
 40  0
             throw new UnexpectedLiquibaseException(e);
 41  
         }
 42  
     }
 43  
 }