1 | |
package liquibase.database.core; |
2 | |
|
3 | |
import liquibase.database.AbstractDatabase; |
4 | |
import liquibase.database.DatabaseConnection; |
5 | |
import liquibase.exception.DatabaseException; |
6 | |
|
7 | |
import java.util.HashSet; |
8 | |
import java.util.Set; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
public class MSSQLDatabase extends AbstractDatabase { |
14 | |
public static final String PRODUCT_NAME = "Microsoft SQL Server"; |
15 | 18 | protected Set<String> systemTablesAndViews = new HashSet<String>(); |
16 | |
|
17 | |
public String getTypeName() { |
18 | 57 | return "mssql"; |
19 | |
} |
20 | |
|
21 | 18 | public MSSQLDatabase() { |
22 | 18 | systemTablesAndViews.add("syscolumns"); |
23 | 18 | systemTablesAndViews.add("syscomments"); |
24 | 18 | systemTablesAndViews.add("sysdepends"); |
25 | 18 | systemTablesAndViews.add("sysfilegroups"); |
26 | 18 | systemTablesAndViews.add("sysfiles"); |
27 | 18 | systemTablesAndViews.add("sysfiles1"); |
28 | 18 | systemTablesAndViews.add("sysforeignkeys"); |
29 | 18 | systemTablesAndViews.add("sysfulltextcatalogs"); |
30 | 18 | systemTablesAndViews.add("sysfulltextnotify"); |
31 | 18 | systemTablesAndViews.add("sysindexes"); |
32 | 18 | systemTablesAndViews.add("sysindexkeys"); |
33 | 18 | systemTablesAndViews.add("sysmembers"); |
34 | 18 | systemTablesAndViews.add("sysobjects"); |
35 | 18 | systemTablesAndViews.add("syspermissions"); |
36 | 18 | systemTablesAndViews.add("sysproperties"); |
37 | 18 | systemTablesAndViews.add("sysprotects"); |
38 | 18 | systemTablesAndViews.add("sysreferences"); |
39 | 18 | systemTablesAndViews.add("systypes"); |
40 | 18 | systemTablesAndViews.add("sysusers"); |
41 | |
|
42 | 18 | systemTablesAndViews.add("syssegments"); |
43 | 18 | systemTablesAndViews.add("sysconstraints"); |
44 | 18 | } |
45 | |
|
46 | |
public int getPriority() { |
47 | 0 | return PRIORITY_DEFAULT; |
48 | |
} |
49 | |
|
50 | |
@Override |
51 | |
public Set<String> getSystemTablesAndViews() { |
52 | 0 | return systemTablesAndViews; |
53 | |
} |
54 | |
|
55 | |
public boolean supportsInitiallyDeferrableColumns() { |
56 | 1 | return false; |
57 | |
} |
58 | |
|
59 | |
@Override |
60 | |
public boolean supportsSequences() { |
61 | 10 | return false; |
62 | |
} |
63 | |
|
64 | |
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException { |
65 | 1 | String databaseProductName = conn.getDatabaseProductName(); |
66 | 1 | return PRODUCT_NAME.equalsIgnoreCase(databaseProductName) || "SQLOLEDB".equalsIgnoreCase(databaseProductName); |
67 | |
} |
68 | |
|
69 | |
public String getDefaultDriver(String url) { |
70 | 2 | if (url.startsWith("jdbc:sqlserver")) { |
71 | 1 | return "com.microsoft.sqlserver.jdbc.SQLServerDriver"; |
72 | 1 | } else if (url.startsWith("jdbc:jtds:sqlserver")) { |
73 | 0 | return "net.sourceforge.jtds.jdbc.Driver"; |
74 | |
} |
75 | 1 | return null; |
76 | |
} |
77 | |
|
78 | |
public String getCurrentDateTimeFunction() { |
79 | 1 | if (currentDateTimeFunction != null) { |
80 | 0 | return currentDateTimeFunction; |
81 | |
} |
82 | |
|
83 | 1 | return "GETDATE()"; |
84 | |
} |
85 | |
|
86 | |
@Override |
87 | |
public String getAutoIncrementClause() { |
88 | 0 | return "IDENTITY"; |
89 | |
} |
90 | |
|
91 | |
@Override |
92 | |
protected String getDefaultDatabaseSchemaName() throws DatabaseException { |
93 | 0 | return null; |
94 | |
} |
95 | |
|
96 | |
@Override |
97 | |
public String getDefaultCatalogName() throws DatabaseException { |
98 | 0 | return getConnection().getCatalog(); |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public String getConcatSql(String... values) { |
103 | 0 | StringBuffer returnString = new StringBuffer(); |
104 | 0 | for (String value : values) { |
105 | 0 | returnString.append(value).append(" + "); |
106 | |
} |
107 | |
|
108 | 0 | return returnString.toString().replaceFirst(" \\+ $", ""); |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public String escapeIndexName(String schemaName, String indexName) { |
113 | |
|
114 | 0 | return super.escapeIndexName(null, indexName); |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public boolean supportsTablespaces() { |
160 | 0 | return true; |
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public boolean isSystemTable(String catalogName, String schemaName, String tableName) { |
165 | 0 | return super.isSystemTable(catalogName, schemaName, tableName) || schemaName.equals("sys"); |
166 | |
} |
167 | |
|
168 | |
@Override |
169 | |
public boolean isSystemView(String catalogName, String schemaName, String viewName) { |
170 | 0 | return super.isSystemView(catalogName, schemaName, viewName) || schemaName.equals("sys"); |
171 | |
} |
172 | |
|
173 | |
public String generateDefaultConstraintName(String tableName, String columnName) { |
174 | 0 | return "DF_" + tableName + "_" + columnName; |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public String escapeDatabaseObject(String objectName) { |
179 | 45 | return "[" + objectName + "]"; |
180 | |
} |
181 | |
|
182 | |
@Override |
183 | |
public String convertRequestedSchemaToCatalog(String requestedSchema) throws DatabaseException { |
184 | 0 | return getDefaultCatalogName(); |
185 | |
} |
186 | |
|
187 | |
@Override |
188 | |
public String convertRequestedSchemaToSchema(String requestedSchema) throws DatabaseException { |
189 | 0 | if (requestedSchema == null) { |
190 | 0 | requestedSchema = getDefaultDatabaseSchemaName(); |
191 | |
} |
192 | |
|
193 | 0 | if (requestedSchema == null) { |
194 | 0 | return "dbo"; |
195 | |
} |
196 | 0 | return requestedSchema; |
197 | |
} |
198 | |
|
199 | |
@Override |
200 | |
public String getDateLiteral(String isoDate) { |
201 | 0 | return super.getDateLiteral(isoDate).replace(' ', 'T'); |
202 | |
} |
203 | |
|
204 | |
@Override |
205 | |
public boolean supportsRestrictForeignKeys() { |
206 | 0 | return false; |
207 | |
} |
208 | |
|
209 | |
@Override |
210 | |
public String getDefaultSchemaName() { |
211 | 80 | String defaultSchemaName = super.getDefaultSchemaName(); |
212 | 80 | if (defaultSchemaName == null) { |
213 | 79 | return "dbo"; |
214 | |
} else { |
215 | 1 | return defaultSchemaName; |
216 | |
} |
217 | |
|
218 | |
} |
219 | |
} |