1 | |
package liquibase.database.core; |
2 | |
|
3 | |
import liquibase.database.AbstractDatabase; |
4 | |
import liquibase.database.DatabaseConnection; |
5 | |
import liquibase.exception.DatabaseException; |
6 | |
import liquibase.exception.UnexpectedLiquibaseException; |
7 | |
import liquibase.executor.ExecutorService; |
8 | |
import liquibase.logging.LogFactory; |
9 | |
import liquibase.statement.core.GetViewDefinitionStatement; |
10 | |
import liquibase.statement.core.RawSqlStatement; |
11 | |
|
12 | |
import java.util.HashSet; |
13 | |
import java.util.List; |
14 | |
import java.util.Map; |
15 | |
import java.util.Set; |
16 | |
import java.util.regex.Pattern; |
17 | |
|
18 | |
public class InformixDatabase extends AbstractDatabase { |
19 | |
|
20 | |
private static final String PRODUCT_NAME = "Informix Dynamic Server"; |
21 | |
private static final String INTERVAL_FIELD_QUALIFIER = "HOUR TO FRACTION(5)"; |
22 | |
private static final String DATETIME_FIELD_QUALIFIER = "YEAR TO FRACTION(5)"; |
23 | |
|
24 | 5 | private Set<String> systemTablesAndViews = new HashSet<String>(); |
25 | |
|
26 | 1 | private static final Pattern CREATE_VIEW_AS_PATTERN = Pattern.compile("^CREATE\\s+.*?VIEW\\s+.*?AS\\s+", |
27 | |
Pattern.CASE_INSENSITIVE | Pattern.DOTALL); |
28 | |
|
29 | |
public InformixDatabase() { |
30 | 5 | super(); |
31 | 5 | systemTablesAndViews.add("systables"); |
32 | 5 | systemTablesAndViews.add("syscolumns"); |
33 | 5 | systemTablesAndViews.add("sysindices"); |
34 | 5 | systemTablesAndViews.add("systabauth"); |
35 | 5 | systemTablesAndViews.add("syscolauth"); |
36 | 5 | systemTablesAndViews.add("sysviews"); |
37 | 5 | systemTablesAndViews.add("sysusers"); |
38 | 5 | systemTablesAndViews.add("sysdepend"); |
39 | 5 | systemTablesAndViews.add("syssynonyms"); |
40 | 5 | systemTablesAndViews.add("syssyntable"); |
41 | 5 | systemTablesAndViews.add("sysconstraints"); |
42 | 5 | systemTablesAndViews.add("sysreferences"); |
43 | 5 | systemTablesAndViews.add("syschecks"); |
44 | 5 | systemTablesAndViews.add("sysdefaults"); |
45 | 5 | systemTablesAndViews.add("syscoldepend"); |
46 | 5 | systemTablesAndViews.add("sysprocedures"); |
47 | 5 | systemTablesAndViews.add("sysprocbody"); |
48 | 5 | systemTablesAndViews.add("sysprocplan"); |
49 | 5 | systemTablesAndViews.add("sysprocauth"); |
50 | 5 | systemTablesAndViews.add("sysblobs"); |
51 | 5 | systemTablesAndViews.add("sysopclstr"); |
52 | 5 | systemTablesAndViews.add("systriggers"); |
53 | 5 | systemTablesAndViews.add("systrigbody"); |
54 | 5 | systemTablesAndViews.add("sysdistrib"); |
55 | 5 | systemTablesAndViews.add("sysfragments"); |
56 | 5 | systemTablesAndViews.add("sysobjstate"); |
57 | 5 | systemTablesAndViews.add("sysviolations"); |
58 | 5 | systemTablesAndViews.add("sysfragauth"); |
59 | 5 | systemTablesAndViews.add("sysroleauth"); |
60 | 5 | systemTablesAndViews.add("sysxtdtypes"); |
61 | 5 | systemTablesAndViews.add("sysattrtypes"); |
62 | 5 | systemTablesAndViews.add("sysxtddesc"); |
63 | 5 | systemTablesAndViews.add("sysinherits"); |
64 | 5 | systemTablesAndViews.add("syscolattribs"); |
65 | 5 | systemTablesAndViews.add("syslogmap"); |
66 | 5 | systemTablesAndViews.add("syscasts"); |
67 | 5 | systemTablesAndViews.add("sysxtdtypeauth"); |
68 | 5 | systemTablesAndViews.add("sysroutinelangs"); |
69 | 5 | systemTablesAndViews.add("syslangauth"); |
70 | 5 | systemTablesAndViews.add("sysams"); |
71 | 5 | systemTablesAndViews.add("systabamdata"); |
72 | 5 | systemTablesAndViews.add("sysopclasses"); |
73 | 5 | systemTablesAndViews.add("syserrors"); |
74 | 5 | systemTablesAndViews.add("systraceclasses"); |
75 | 5 | systemTablesAndViews.add("systracemsgs"); |
76 | 5 | systemTablesAndViews.add("sysaggregates"); |
77 | 5 | systemTablesAndViews.add("syssequences"); |
78 | 5 | systemTablesAndViews.add("sysdirectives"); |
79 | 5 | systemTablesAndViews.add("sysxasourcetypes"); |
80 | 5 | systemTablesAndViews.add("sysxadatasources"); |
81 | 5 | systemTablesAndViews.add("sysseclabelcomponents"); |
82 | 5 | systemTablesAndViews.add("sysseclabelcomponentelements"); |
83 | 5 | systemTablesAndViews.add("syssecpolicies"); |
84 | 5 | systemTablesAndViews.add("syssecpolicycomponents"); |
85 | 5 | systemTablesAndViews.add("syssecpolicyexemptions"); |
86 | 5 | systemTablesAndViews.add("sysseclabels"); |
87 | 5 | systemTablesAndViews.add("sysseclabelnames"); |
88 | 5 | systemTablesAndViews.add("sysseclabelauth"); |
89 | 5 | systemTablesAndViews.add("syssurrogateauth"); |
90 | 5 | systemTablesAndViews.add("sysproccolumns"); |
91 | |
|
92 | 5 | systemTablesAndViews.add("sysdomains"); |
93 | 5 | systemTablesAndViews.add("sysindexes"); |
94 | 5 | } |
95 | |
|
96 | |
@Override |
97 | |
protected Set<String> getSystemTablesAndViews() { |
98 | 0 | return systemTablesAndViews; |
99 | |
} |
100 | |
|
101 | |
public int getPriority() { |
102 | 0 | return PRIORITY_DEFAULT; |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public void setConnection(DatabaseConnection connection) { |
107 | 0 | super.setConnection(connection); |
108 | |
try { |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | 0 | ExecutorService.getInstance().getExecutor(this) |
114 | |
.execute(new RawSqlStatement("EXECUTE PROCEDURE IFX_ALLOW_NEWLINE('T');")); |
115 | 0 | } catch (Exception e) { |
116 | 0 | throw new UnexpectedLiquibaseException( |
117 | |
"Could not allow newline characters in quoted strings with IFX_ALLOW_NEWLINE", e); |
118 | 0 | } |
119 | 0 | } |
120 | |
|
121 | |
public String getCurrentDateTimeFunction() { |
122 | 0 | if (currentDateTimeFunction != null) { |
123 | 0 | return currentDateTimeFunction; |
124 | |
} |
125 | |
|
126 | 0 | return "CURRENT " + DATETIME_FIELD_QUALIFIER; |
127 | |
} |
128 | |
|
129 | |
public String getDefaultDriver(String url) { |
130 | 1 | if (url.startsWith("jdbc:informix-sqli")) { |
131 | 1 | return "com.informix.jdbc.IfxDriver"; |
132 | |
} |
133 | 0 | return null; |
134 | |
} |
135 | |
|
136 | |
public String getTypeName() { |
137 | 56 | return "informix"; |
138 | |
} |
139 | |
|
140 | |
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException { |
141 | 0 | return PRODUCT_NAME.equals(conn.getDatabaseProductName()); |
142 | |
} |
143 | |
|
144 | |
public boolean supportsInitiallyDeferrableColumns() { |
145 | 0 | return false; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public boolean supportsTablespaces() { |
152 | 0 | return true; |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public String getViewDefinition(String schemaName, String viewName) throws DatabaseException { |
157 | 0 | List<Map> retList = ExecutorService.getInstance().getExecutor(this) |
158 | |
.queryForList(new GetViewDefinitionStatement(schemaName, viewName)); |
159 | |
|
160 | 0 | StringBuilder sb = new StringBuilder(); |
161 | 0 | for (Map rowMap : retList) { |
162 | 0 | String s = (String) rowMap.get("VIEWTEXT"); |
163 | 0 | sb.append(s); |
164 | 0 | } |
165 | 0 | return CREATE_VIEW_AS_PATTERN.matcher(sb.toString()).replaceFirst(""); |
166 | |
} |
167 | |
|
168 | |
@Override |
169 | |
public String getAutoIncrementClause() { |
170 | 0 | return ""; |
171 | |
} |
172 | |
|
173 | |
@Override |
174 | |
public String getDateLiteral(String isoDate) { |
175 | 3 | if (isTimeOnly(isoDate)) { |
176 | 1 | return "INTERVAL (" + super.getDateLiteral(isoDate).replaceAll("'", "") + ") " + INTERVAL_FIELD_QUALIFIER; |
177 | 2 | } else if (isDateOnly(isoDate)) { |
178 | 1 | return super.getDateLiteral(isoDate); |
179 | |
} else { |
180 | 1 | return "DATETIME (" + super.getDateLiteral(isoDate).replaceAll("'", "") + ") " + DATETIME_FIELD_QUALIFIER; |
181 | |
} |
182 | |
} |
183 | |
|
184 | |
@Override |
185 | |
public boolean supportsRestrictForeignKeys() { |
186 | |
|
187 | 0 | return false; |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public boolean supportsSchemas() { |
192 | 5 | return false; |
193 | |
} |
194 | |
} |