1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.core.DB2Database; |
5 | |
import liquibase.statement.core.InsertOrUpdateStatement; |
6 | |
|
7 | 10 | public class InsertOrUpdateGeneratorDB2 extends InsertOrUpdateGenerator { |
8 | |
|
9 | |
@Override |
10 | |
protected String getElse(Database database) { |
11 | 0 | return "\tELSEIF v_reccount = 1 THEN\n"; |
12 | |
} |
13 | |
|
14 | |
@Override |
15 | |
protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, |
16 | |
String whereClause) { |
17 | 0 | StringBuffer recordCheckSql = new StringBuffer(); |
18 | |
|
19 | 0 | recordCheckSql.append("BEGIN ATOMIC\n"); |
20 | 0 | recordCheckSql.append("\tDECLARE v_reccount INTEGER;\n"); |
21 | 0 | recordCheckSql.append("\tSET v_reccount = (SELECT COUNT(*) FROM " |
22 | |
+ database.escapeTableName(insertOrUpdateStatement.getSchemaName(), |
23 | |
insertOrUpdateStatement.getTableName()) + " WHERE "); |
24 | |
|
25 | 0 | recordCheckSql.append(whereClause); |
26 | 0 | recordCheckSql.append(");\n"); |
27 | |
|
28 | 0 | recordCheckSql.append("\tIF v_reccount = 0 THEN\n"); |
29 | |
|
30 | 0 | return recordCheckSql.toString(); |
31 | |
} |
32 | |
|
33 | |
@Override |
34 | |
public boolean supports(InsertOrUpdateStatement statement, Database database) { |
35 | 0 | return database instanceof DB2Database; |
36 | |
} |
37 | |
|
38 | |
@Override |
39 | |
protected String getPostUpdateStatements() { |
40 | 0 | StringBuffer endStatements = new StringBuffer(); |
41 | 0 | endStatements.append("END IF;\n"); |
42 | 0 | endStatements.append("END\n"); |
43 | 0 | return endStatements.toString(); |
44 | |
} |
45 | |
|
46 | |
} |