1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.exception.DatabaseException; |
5 | |
import liquibase.exception.UnexpectedLiquibaseException; |
6 | |
import liquibase.exception.ValidationErrors; |
7 | |
import liquibase.sql.Sql; |
8 | |
import liquibase.sql.UnparsedSql; |
9 | |
import liquibase.sqlgenerator.SqlGenerator; |
10 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
11 | |
import liquibase.statement.core.GetViewDefinitionStatement; |
12 | |
|
13 | 132 | public class GetViewDefinitionGenerator extends AbstractSqlGenerator<GetViewDefinitionStatement> { |
14 | |
|
15 | |
public ValidationErrors validate(GetViewDefinitionStatement getViewDefinitionStatement, Database database, |
16 | |
SqlGeneratorChain sqlGeneratorChain) { |
17 | 0 | ValidationErrors validationErrors = new ValidationErrors(); |
18 | 0 | validationErrors.checkRequiredField("viewName", getViewDefinitionStatement.getViewName()); |
19 | 0 | return validationErrors; |
20 | |
} |
21 | |
|
22 | |
public Sql[] generateSql(GetViewDefinitionStatement statement, Database database, |
23 | |
SqlGeneratorChain sqlGeneratorChain) { |
24 | |
try { |
25 | 0 | String sql = "select view_definition from information_schema.views where upper(table_name)='" |
26 | |
+ statement.getViewName().toUpperCase() + "'"; |
27 | 0 | if (database.convertRequestedSchemaToCatalog(statement.getSchemaName()) != null) { |
28 | 0 | sql += " and table_schema='" + database.convertRequestedSchemaToSchema(statement.getSchemaName()) + "'"; |
29 | 0 | } else if (database.convertRequestedSchemaToCatalog(statement.getSchemaName()) != null) { |
30 | 0 | sql += " and table_catalog='" + database.convertRequestedSchemaToCatalog(statement.getSchemaName()) |
31 | |
+ "'"; |
32 | |
} |
33 | |
|
34 | 0 | return new Sql[] { new UnparsedSql(sql) }; |
35 | 0 | } catch (DatabaseException e) { |
36 | 0 | throw new UnexpectedLiquibaseException(e); |
37 | |
} |
38 | |
} |
39 | |
} |