1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.core.InformixDatabase; |
5 | |
import liquibase.sql.Sql; |
6 | |
import liquibase.sql.UnparsedSql; |
7 | |
import liquibase.sqlgenerator.SqlGenerator; |
8 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
9 | |
import liquibase.statement.core.AddUniqueConstraintStatement; |
10 | |
|
11 | 76 | public class AddUniqueConstraintGeneratorInformix extends AddUniqueConstraintGenerator { |
12 | |
|
13 | 13 | public AddUniqueConstraintGeneratorInformix() { |
14 | |
|
15 | 13 | } |
16 | |
|
17 | |
@Override |
18 | |
public int getPriority() { |
19 | 1 | return SqlGenerator.PRIORITY_DATABASE; |
20 | |
} |
21 | |
|
22 | |
@Override |
23 | |
public boolean supports(AddUniqueConstraintStatement statement, Database database) { |
24 | 76 | return (database instanceof InformixDatabase); |
25 | |
} |
26 | |
|
27 | |
@Override |
28 | |
public Sql[] generateSql(AddUniqueConstraintStatement statement, Database database, |
29 | |
SqlGeneratorChain sqlGeneratorChain) { |
30 | |
|
31 | 0 | final String sqlNoContraintNameTemplate = "ALTER TABLE %s ADD CONSTRAINT UNIQUE (%s)"; |
32 | 0 | final String sqlTemplate = "ALTER TABLE %s ADD CONSTRAINT UNIQUE (%s) CONSTRAint %s"; |
33 | 0 | if (statement.getConstraintName() == null) { |
34 | 0 | return new Sql[] { new UnparsedSql(String.format(sqlNoContraintNameTemplate, |
35 | |
database.escapeTableName(statement.getSchemaName(), statement.getTableName()), |
36 | |
database.escapeColumnNameList(statement.getColumnNames()))) }; |
37 | |
} else { |
38 | 0 | return new Sql[] { new UnparsedSql(String.format(sqlTemplate, |
39 | |
database.escapeTableName(statement.getSchemaName(), statement.getTableName()), |
40 | |
database.escapeColumnNameList(statement.getColumnNames()), |
41 | |
database.escapeConstraintName(statement.getConstraintName()))) }; |
42 | |
} |
43 | |
|
44 | |
} |
45 | |
|
46 | |
} |