private String getOneToOneTriggerBody(ForeignKeyDefinition fkDef, String exceptionName) { String tableName = fkDef.getTableName(); StringBuffer sb = new StringBuffer(); sb.append(" DECLARE VARIABLE x INTEGER;").append(LINE_SEPARATOR); sb.append("BEGIN").append(LINE_SEPARATOR); sb.append(" "); sb.append("SELECT COUNT(*) FROM ").append(tableName); sb.append(" WHERE "); StringBuffer sbWhere = new StringBuffer(); List columnNames = fkDef.getColumnNames(); for (int i = 0; i < columnNames.size(); i++) { if (sbWhere.length() > 0) { sbWhere.append(" AND "); } String colName = (String) columnNames.get(i); sbWhere.append(colName); sbWhere.append(" = NEW.").append(colName); } List pkFields = fkDef.getTable().getPrimaryKeyFields(); for (int i = 0; i < pkFields.size(); i++) { String pkFieldName = (String) pkFields.get(i); sbWhere.append(" AND ").append(pkFieldName); sbWhere.append(" <> NEW.").append(pkFieldName); sbWhere.append(" "); } sb.append(sbWhere).append(" INTO :x;").append(LINE_SEPARATOR); sb.append(" IF (:x = 1) THEN").append(LINE_SEPARATOR); sb.append(" "); sb.append("EXCEPTION ").append(exceptionName); sb.append(";").append(LINE_SEPARATOR); sb.append("END !!").append(LINE_SEPARATOR); return sb.toString(); }
/** * Takes a list of strings and joins them with <code>separators</code>. * * @param strings * The list of strings to be joined. * @param separators * The string that should be put between the separate strings. * @return The joined string. */ public static String stringsToString(List strings, String separators) { StringBuffer sb = new StringBuffer(); Iterator it = strings.iterator(); while (it.hasNext()) { String s = (String) it.next(); if (sb.length() > 0) { sb.append(separators); } sb.append(s); } return sb.toString(); }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml-sql/src/org/argouml/language/sql/FirebirdSqlCodeCreator.java File path: /ArgoUML-0.34-src/argouml-sql/src/org/argouml/language/sql/Utils.java
Method name: String getOneToOneTriggerBody(ForeignKeyDefinition, String) Method name: String stringsToString(List, String)
Number of AST nodes: 6 Number of AST nodes: 5
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
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.833
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    10
    for (int i = 0; i < columnNames.size(); i++)
    10
    for (int i = 0; i < columnNames.size(); i++)
    3
    while (it.hasNext())
    Differences
    Expression1Expression2Difference
    i < columnNames.size()it.hasNext()TYPE_COMPATIBLE_REPLACEMENT
    3
    while (it.hasNext())
                                                                
    4
    String s = (String)it.next();
    11
    if (sbWhere.length() > 0)
    11
    if (sbWhere.length() > 0)
    5
    if (sb.length() > 0)
    Differences
    Expression1Expression2Difference
    sbWheresbVARIABLE_NAME_MISMATCH
    5
    if (sb.length() > 0)
    12
    sbWhere.append(" AND ");
    12
    sbWhere.append(" AND ");
    6
    sb.append(separators);
    Differences
    Expression1Expression2Difference
    " AND "separatorsTYPE_COMPATIBLE_REPLACEMENT
    sbWheresbVARIABLE_NAME_MISMATCH
    6
    sb.append(separators);
    13
    String colName = (String)columnNames.get(i);
    13
    String colName = (String)columnNames.get(i);
    Preondition Violations
    Unmatched statement String colName=(String)columnNames.get(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                
    14
    sbWhere.append(colName);
    14
    sbWhere.append(colName);
    7
    sb.append(s);
    Differences
    Expression1Expression2Difference
    colNamesVARIABLE_NAME_MISMATCH
    sbWheresbVARIABLE_NAME_MISMATCH
    7
    sb.append(s);
    15
    sbWhere.append(" = NEW.").append(colName);
                                                                                                
    Precondition Violations (2)
    Row Violation
    1Unmatched statement String colName=(String)columnNames.get(i); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Clone fragment #1 returns variables i , while Clone fragment #2 returns variables