1 | |
package liquibase.database.core; |
2 | |
|
3 | |
import liquibase.database.AbstractDatabase; |
4 | |
import liquibase.database.DatabaseConnection; |
5 | |
import liquibase.exception.DatabaseException; |
6 | |
import liquibase.executor.ExecutorService; |
7 | |
import liquibase.statement.core.RawSqlStatement; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | 15 | public class MySQLDatabase extends AbstractDatabase { |
13 | |
public static final String PRODUCT_NAME = "MySQL"; |
14 | |
|
15 | |
public String getTypeName() { |
16 | 58 | return "mysql"; |
17 | |
} |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public int getPriority() { |
25 | 0 | return PRIORITY_DEFAULT; |
26 | |
} |
27 | |
|
28 | |
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException { |
29 | 1 | return PRODUCT_NAME.equalsIgnoreCase(conn.getDatabaseProductName()); |
30 | |
} |
31 | |
|
32 | |
public String getDefaultDriver(String url) { |
33 | 0 | if (url.startsWith("jdbc:mysql")) { |
34 | 0 | return "com.mysql.jdbc.Driver"; |
35 | |
} |
36 | 0 | return null; |
37 | |
} |
38 | |
|
39 | |
@Override |
40 | |
public boolean supportsSequences() { |
41 | 8 | return false; |
42 | |
} |
43 | |
|
44 | |
public boolean supportsInitiallyDeferrableColumns() { |
45 | 1 | return false; |
46 | |
} |
47 | |
|
48 | |
public String getCurrentDateTimeFunction() { |
49 | 1 | if (currentDateTimeFunction != null) { |
50 | 0 | return currentDateTimeFunction; |
51 | |
} |
52 | |
|
53 | 1 | return "NOW()"; |
54 | |
} |
55 | |
|
56 | |
@Override |
57 | |
public String getLineComment() { |
58 | 0 | return "--"; |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public String getConcatSql(String... values) { |
63 | 0 | StringBuffer returnString = new StringBuffer(); |
64 | 0 | returnString.append("CONCAT_WS("); |
65 | 0 | for (String value : values) { |
66 | 0 | returnString.append(value).append(", "); |
67 | |
} |
68 | |
|
69 | 0 | return returnString.toString().replaceFirst(", $", ")"); |
70 | |
} |
71 | |
|
72 | |
public boolean supportsTablespaces() { |
73 | 0 | return false; |
74 | |
} |
75 | |
|
76 | |
@Override |
77 | |
protected String getDefaultDatabaseSchemaName() throws DatabaseException { |
78 | |
|
79 | 0 | return getConnection().getCatalog(); |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public String convertRequestedSchemaToSchema(String requestedSchema) throws DatabaseException { |
84 | 0 | if (requestedSchema == null) { |
85 | 0 | return getDefaultDatabaseSchemaName(); |
86 | |
} |
87 | 0 | return requestedSchema; |
88 | |
} |
89 | |
|
90 | |
@Override |
91 | |
public String convertRequestedSchemaToCatalog(String requestedSchema) throws DatabaseException { |
92 | 0 | return requestedSchema; |
93 | |
} |
94 | |
|
95 | |
@Override |
96 | |
public String escapeDatabaseObject(String objectName) { |
97 | 16 | return "`" + objectName + "`"; |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public String escapeIndexName(String schemaName, String indexName) { |
102 | 0 | return escapeDatabaseObject(indexName); |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public boolean supportsForeignKeyDisable() { |
107 | 0 | return true; |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public boolean disableForeignKeyChecks() throws DatabaseException { |
112 | 0 | boolean enabled = ExecutorService.getInstance().getExecutor(this) |
113 | |
.queryForInt(new RawSqlStatement("SELECT @@FOREIGN_KEY_CHECKS")) == 1; |
114 | 0 | ExecutorService.getInstance().getExecutor(this).execute(new RawSqlStatement("SET FOREIGN_KEY_CHECKS=0")); |
115 | 0 | return enabled; |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public void enableForeignKeyChecks() throws DatabaseException { |
120 | 0 | ExecutorService.getInstance().getExecutor(this).execute(new RawSqlStatement("SET FOREIGN_KEY_CHECKS=1")); |
121 | 0 | } |
122 | |
} |