01: package liquibase.database.sql;
02:
03: import liquibase.database.*;
04: import liquibase.exception.StatementNotSupportedOnDatabaseException;
05:
06: public class RenameViewStatement implements SqlStatement {
07:
08: private String schemaName;
09: private String oldViewName;
10: private String newViewName;
11:
12: public RenameViewStatement(String schemaName, String oldViewName,
13: String newViewName) {
14: this .schemaName = schemaName;
15: this .oldViewName = oldViewName;
16: this .newViewName = newViewName;
17: }
18:
19: public String getSchemaName() {
20: return schemaName;
21: }
22:
23: public String getOldViewName() {
24: return oldViewName;
25: }
26:
27: public String getNewViewName() {
28: return newViewName;
29: }
30:
31: public String getSqlStatement(Database database)
32: throws StatementNotSupportedOnDatabaseException {
33: if (!supportsDatabase(database)) {
34: throw new StatementNotSupportedOnDatabaseException(this ,
35: database);
36: }
37:
38: if (database instanceof MSSQLDatabase) {
39: return "exec sp_rename '"
40: + database.escapeViewName(getSchemaName(),
41: getOldViewName()) + "', "
42: + getNewViewName();
43: } else if (database instanceof MySQLDatabase) {
44: return "RENAME TABLE "
45: + database.escapeViewName(getSchemaName(),
46: getOldViewName())
47: + " TO "
48: + database.escapeTableName(getSchemaName(),
49: getNewViewName());
50: } else if (database instanceof PostgresDatabase) {
51: return "ALTER TABLE "
52: + database.escapeViewName(getSchemaName(),
53: getOldViewName()) + " RENAME TO "
54: + getNewViewName();
55: } else if (database instanceof MaxDBDatabase) {
56: return "RENAME VIEW "
57: + database.escapeViewName(getSchemaName(),
58: getOldViewName()) + " TO "
59: + getNewViewName();
60: }
61:
62: if (getSchemaName() != null
63: && database instanceof OracleDatabase) {
64: throw new StatementNotSupportedOnDatabaseException(
65: "Cannot specify schema when renaming in oracle",
66: this , database);
67: }
68:
69: return "RENAME "
70: + database.escapeViewName(getSchemaName(),
71: getOldViewName()) + " TO " + getNewViewName();
72: }
73:
74: public String getEndDelimiter(Database database) {
75: return ";";
76: }
77:
78: public boolean supportsDatabase(Database database) {
79: return !(database instanceof DerbyDatabase
80: || database instanceof HsqlDatabase
81: || database instanceof DB2Database
82: || database instanceof CacheDatabase || database instanceof FirebirdDatabase);
83: }
84: }
|