1 | |
|
2 | |
|
3 | |
|
4 | |
package liquibase.database.core; |
5 | |
|
6 | |
import java.util.HashSet; |
7 | |
import java.util.Set; |
8 | |
|
9 | |
import liquibase.database.AbstractDatabase; |
10 | |
import liquibase.database.DatabaseConnection; |
11 | |
import liquibase.exception.DatabaseException; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
public class SybaseASADatabase extends AbstractDatabase { |
18 | |
|
19 | |
private static final Set<String> SYSTEM_TABLES_AND_VIEWS; |
20 | |
|
21 | |
static { |
22 | 1 | SYSTEM_TABLES_AND_VIEWS = new HashSet<String>(); |
23 | 1 | SYSTEM_TABLES_AND_VIEWS.add("dummy"); |
24 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysarticle"); |
25 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysarticlecol"); |
26 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysarticlecols"); |
27 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysarticles"); |
28 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysattribute"); |
29 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysattributename"); |
30 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscapabilities"); |
31 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscapability"); |
32 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscapabilityname"); |
33 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscatalog"); |
34 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscolauth"); |
35 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscollation"); |
36 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscollationmappings"); |
37 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscolperm"); |
38 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscolstat"); |
39 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscolstats"); |
40 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscolumn"); |
41 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syscolumns"); |
42 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysdomain"); |
43 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysevent"); |
44 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syseventtype"); |
45 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysextent"); |
46 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysexternlogins"); |
47 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysfile"); |
48 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysfkcol"); |
49 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysforeignkey"); |
50 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysforeignkeys"); |
51 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysgroup"); |
52 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysgroups"); |
53 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysindex"); |
54 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysindexes"); |
55 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysinfo"); |
56 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysixcol"); |
57 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysjar"); |
58 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysjarcomponent"); |
59 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysjavaclass"); |
60 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syslogin"); |
61 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptblock"); |
62 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoption"); |
63 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptions"); |
64 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptjoinstrategy"); |
65 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptorder"); |
66 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptorders"); |
67 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptplans"); |
68 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptquantifier"); |
69 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptrequest"); |
70 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptrewrite"); |
71 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptstat"); |
72 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysoptstrategies"); |
73 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysprocauth"); |
74 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysprocedure"); |
75 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysprocparm"); |
76 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysprocparms"); |
77 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysprocperm"); |
78 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syspublication"); |
79 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syspublications"); |
80 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremoteoption"); |
81 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremoteoptions"); |
82 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremoteoptiontype"); |
83 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremotetype"); |
84 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremotetypes"); |
85 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremoteuser"); |
86 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysremoteusers"); |
87 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysschedule"); |
88 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysservers"); |
89 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssqlservertype"); |
90 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssubscription"); |
91 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssubscriptions"); |
92 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssync"); |
93 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssyncdefinitions"); |
94 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssyncpublicationdefaults"); |
95 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssyncs"); |
96 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssyncsites"); |
97 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssyncsubscriptions"); |
98 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssynctemplates"); |
99 | 1 | SYSTEM_TABLES_AND_VIEWS.add("syssyncusers"); |
100 | 1 | SYSTEM_TABLES_AND_VIEWS.add("systabauth"); |
101 | 1 | SYSTEM_TABLES_AND_VIEWS.add("systable"); |
102 | 1 | SYSTEM_TABLES_AND_VIEWS.add("systableperm"); |
103 | 1 | SYSTEM_TABLES_AND_VIEWS.add("systrigger"); |
104 | 1 | SYSTEM_TABLES_AND_VIEWS.add("systriggers"); |
105 | 1 | SYSTEM_TABLES_AND_VIEWS.add("systypemap"); |
106 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysuserauth"); |
107 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysuserlist"); |
108 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysusermessages"); |
109 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysuseroptions"); |
110 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysuserperm"); |
111 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysuserperms"); |
112 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysusertype"); |
113 | 1 | SYSTEM_TABLES_AND_VIEWS.add("sysviews"); |
114 | 1 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public SybaseASADatabase() { |
120 | 1 | super(); |
121 | 1 | } |
122 | |
|
123 | |
@Override |
124 | |
public int getPriority() { |
125 | 0 | return PRIORITY_DEFAULT; |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
@Override |
134 | |
public String getCurrentDateTimeFunction() { |
135 | 0 | if (currentDateTimeFunction != null) { |
136 | 0 | return currentDateTimeFunction; |
137 | |
} |
138 | |
|
139 | 0 | return "now()"; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
@Override |
148 | |
public String getDefaultDriver(String url) { |
149 | 0 | if (url.startsWith("jdbc:sybase")) { |
150 | 0 | return "com.sybase.jdbc3.jdbc.SybDriver"; |
151 | |
} else { |
152 | 0 | return null; |
153 | |
} |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
@Override |
162 | |
public String getTypeName() { |
163 | |
|
164 | 56 | return "asany"; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
@Override |
173 | |
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException { |
174 | 0 | return "Adaptive Server Anywhere".equalsIgnoreCase(conn.getDatabaseProductName()) |
175 | |
|| "SQL Anywhere".equalsIgnoreCase(conn.getDatabaseProductName()); |
176 | |
} |
177 | |
|
178 | |
@Override |
179 | |
public String getDefaultCatalogName() throws DatabaseException { |
180 | 0 | return getConnection().getCatalog(); |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
protected String getDefaultDatabaseSchemaName() throws DatabaseException { |
185 | 0 | return null; |
186 | |
} |
187 | |
|
188 | |
@Override |
189 | |
public String convertRequestedSchemaToSchema(String requestedSchema) throws DatabaseException { |
190 | 0 | if (requestedSchema == null) { |
191 | 0 | requestedSchema = getDefaultDatabaseSchemaName(); |
192 | |
} |
193 | |
|
194 | 0 | if (requestedSchema == null) { |
195 | 0 | return "DBA"; |
196 | |
} |
197 | 0 | return requestedSchema; |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public String getDefaultSchemaName() { |
202 | |
|
203 | 98 | return super.getDefaultSchemaName(); |
204 | |
} |
205 | |
|
206 | |
@Override |
207 | |
public String getViewDefinition(String schemaName, String viewName) throws DatabaseException { |
208 | |
|
209 | 0 | return super.getViewDefinition(schemaName, viewName); |
210 | |
} |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
@Override |
218 | |
public boolean supportsInitiallyDeferrableColumns() { |
219 | 0 | return false; |
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
@Override |
228 | |
public boolean supportsTablespaces() { |
229 | 0 | return true; |
230 | |
} |
231 | |
|
232 | |
@Override |
233 | |
public String convertRequestedSchemaToCatalog(String requestedSchema) throws DatabaseException { |
234 | |
|
235 | 0 | return getDefaultCatalogName(); |
236 | |
|
237 | |
} |
238 | |
|
239 | |
@Override |
240 | |
public Set<String> getSystemTablesAndViews() { |
241 | 0 | return SYSTEM_TABLES_AND_VIEWS; |
242 | |
} |
243 | |
|
244 | |
@Override |
245 | |
public boolean supportsSequences() { |
246 | 8 | return false; |
247 | |
} |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
@Override |
255 | |
public String getAutoIncrementClause() { |
256 | 0 | return "default autoincrement"; |
257 | |
} |
258 | |
|
259 | |
@Override |
260 | |
public void setAutoCommit(boolean b) throws DatabaseException { |
261 | |
|
262 | |
|
263 | |
|
264 | 0 | if (b || super.isAutoCommit()) { |
265 | 0 | super.setAutoCommit(b); |
266 | |
} |
267 | 0 | } |
268 | |
|
269 | |
@Override |
270 | |
public String escapeDatabaseObject(String objectName) { |
271 | 20 | return "\"" + objectName + "\""; |
272 | |
} |
273 | |
|
274 | |
} |