1 | private String getOneToOneTriggerBody(ForeignKeyDefinition fkDef, | | 1 | /** |
2 | String exceptionName) { | | 2 | * Takes a list of strings and joins them with <code>separators</code>. |
3 | String tableName = fkDef.getTableName(); | | 3 | * |
4 | | | 4 | * @param strings |
5 | StringBuffer sb = new StringBuffer(); | | 5 | * The list of strings to be joined. |
6 | sb.append(" DECLARE VARIABLE x INTEGER;").append(LINE_SEPARATOR); | | 6 | * @param separators |
7 | | | 7 | * The string that should be put between the separate strings. |
8 | sb.append("BEGIN").append(LINE_SEPARATOR); | | 8 | * @return The joined string. |
9 | | | 9 | */ |
10 | sb.append(" "); | | 10 | public static String stringsToString(List strings, String separators) { |
11 | sb.append("SELECT COUNT(*) FROM ").append(tableName); | | 11 | StringBuffer sb = new StringBuffer(); |
12 | sb.append(" WHERE "); | | 12 | Iterator it = strings.iterator(); |
13 | | | 13 | while (it.hasNext()) { |
14 | StringBuffer sbWhere = new StringBuffer(); | | 14 | String s = (String) it.next(); |
15 | List columnNames = fkDef.getColumnNames(); | | 15 | if (sb.length() > 0) { |
16 | for (int i = 0; i < columnNames.size(); i++) { | | 16 | sb.append(separators); |
17 | if (sbWhere.length() > 0) { | | 17 | } |
18 | sbWhere.append(" AND "); | | 18 | sb.append(s); |
19 | } | | 19 | } |
20 | | | 20 | return sb.toString(); |
21 | String colName = (String) columnNames.get(i); | | 21 | } |
22 | | | | |
23 | sbWhere.append(colName); | | | |
24 | sbWhere.append(" = NEW.").append(colName); | | | |
25 | } | | | |
26 | | | | |
27 | List pkFields = fkDef.getTable().getPrimaryKeyFields(); | | | |
28 | for (int i = 0; i < pkFields.size(); i++) { | | | |
29 | String pkFieldName = (String) pkFields.get(i); | | | |
30 | sbWhere.append(" AND ").append(pkFieldName); | | | |
31 | sbWhere.append(" <> NEW.").append(pkFieldName); | | | |
32 | sbWhere.append(" "); | | | |
33 | } | | | |
34 | | | | |
35 | sb.append(sbWhere).append(" INTO :x;").append(LINE_SEPARATOR); | | | |
36 | | | | |
37 | sb.append(" IF (:x = 1) THEN").append(LINE_SEPARATOR); | | | |
38 | | | | |
39 | sb.append(" "); | | | |
40 | sb.append("EXCEPTION ").append(exceptionName); | | | |
41 | sb.append(";").append(LINE_SEPARATOR); | | | |
42 | | | | |
43 | sb.append("END !!").append(LINE_SEPARATOR); | | | |
44 | | | | |
45 | return sb.toString(); | | | |
46 | } | | | |