boolean result = false; try { SQLDatabaseMetaData md = prov.getCopyDestSession().getSQLConnection().getSQLMetaData(); ITableInfo[] tables = md.getTables(destCatalog, destSchema, destTableName, new String[] { "TABLE" }, null); if (tables != null && tables.length == 1) { ForeignKeyInfo[] fks = SQLUtilities.getImportedKeys(tables[0], md); for (ForeignKeyInfo existingKey : fks) { if (areEqual(existingKey, fkInfo)) { result = true; break; } } } else { log.error("Couldn't find an exact match for destination table " + destTableName + " in schema " + destSchema + " and catalog " + destCatalog + ". Skipping FK constraint"); } } catch (SQLException e) { log.error("Unexpected exception while attempting to determine if " + "a table (" + destTableName + ") has a particular foreign " + "key"); } return result;
boolean result = false; try { SQLDatabaseMetaData md = prov.getDiffDestSession().getSQLConnection().getSQLMetaData(); ITableInfo[] tables = md.getTables(destCatalog, destSchema, destTableName, new String[] { "TABLE" }, null); if (tables != null && tables.length == 1) { ForeignKeyInfo[] fks = SQLUtilities.getImportedKeys(tables[0], md); for (ForeignKeyInfo existingKey : fks) { if (areEqual(existingKey, fkInfo)) { result = true; break; } } } else { log.error("Couldn't find an exact match for destination table " + destTableName + " in schema " + destSchema + " and catalog " + destCatalog + ". Skipping FK constraint"); } } catch (SQLException e) { log.error("Unexpected exception while attempting to determine if " + "a table (" + destTableName + ") has a particular foreign " + "key"); } return result;
Clone fragments detected by clone detection tool
File path: /sql12/plugins/dbcopy/src/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java File path: /sql12/plugins/dbdiff/src/net/sourceforge/squirrel_sql/plugins/dbdiff/util/DBUtil.java
Method name: boolean tableHasForeignKey(String, String, String, ForeignKeyInfo, SessionInfoProvider) Method name: boolean tableHasForeignKey(String, String, String, ForeignKeyInfo, SessionInfoProvider)
Number of AST nodes: 12 Number of AST nodes: 12
1
boolean result = false;
1
boolean result = false;
2
		try
2
		try
3
		{
3
		{
4
			SQLDatabaseMetaData md = prov.getCopyDestSession().getSQLConnection().getSQLMetaData();
4
			SQLDatabaseMetaData md = prov.getDiffDestSession().getSQLConnection().getSQLMetaData();
5
			ITableInfo[] tables = 
5
			ITableInfo[] tables =
6
md.getTables(destCatalog, destSchema, destTableName, new String[]
6
				md.getTables(destCatalog, destSchema, destTableName, new String[]
7
				{ "TABLE" }, null);
7
 { "TABLE" }, null);
8
			if (tables != null && tables.length == 1)
8
			if (tables != null && tables.length == 1)
9
			{
9
			{
10
				ForeignKeyInfo[] fks = SQLUtilities.getImportedKeys(tables[0], md);
10
				ForeignKeyInfo[] fks = SQLUtilities.getImportedKeys(tables[0], md);
11
				for (ForeignKeyInfo existingKey : fks)
11
				for (ForeignKeyInfo existingKey : fks)
12
				{
12
				{
13
					if (areEqual(existingKey, fkInfo))
13
					if (areEqual(existingKey, fkInfo))
14
					{
14
					{
15
						result = true;
15
						result = true;
16
						break;
16
						break;
17
					}
17
					}
18
				}
18
				}
19
			} 
19
			}
20
else
20
			else
21
			{
21
			{
22
				log.error("Couldn't find an exact match for destination table " + destTableName + " in schema "
22
				log.error("Couldn't find an exact match for destination table " + destTableName + " in schema "
23
				      + destSchema + " and catalog " + destCatalog + ". Skipping FK constraint");
23
					+ destSchema + " and catalog " + destCatalog + ". Skipping FK constraint");
24
			}
24
			}
25
		} 
25
		}
26
catch (SQLException e)
26
		catch (SQLException e)
27
		{
27
		{
28
			log.error("Unexpected exception while attempting to determine if " + "a table (" + destTableName
28
			log.error("Unexpected exception while attempting to determine if " + "a table (" + destTableName
29
			      + ") has a particular foreign " + "key");
29
				+ ") has a particular foreign " + "key");
30
		}
30
		}
31
		return result;
31
		return result;
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)1.7
Clones locationClones are in different classes
Number of node comparisons32
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements12
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)12.3
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    boolean result = false;
    1
    boolean result = false;
    2
    try
    2
    try
    3
    SQLDatabaseMetaData md = prov.getCopyDestSession().getSQLConnection().getSQLMetaData();
    3
    SQLDatabaseMetaData md = prov.getCopyDestSession().getSQLConnection().getSQLMetaData();
    3
    SQLDatabaseMetaData md = prov.getDiffDestSession().getSQLConnection().getSQLMetaData();
    Differences
    Expression1Expression2Difference
    getCopyDestSessiongetDiffDestSessionMETHOD_INVOCATION_NAME_MISMATCH
    net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvidernet.sourceforge.squirrel_sql.plugins.dbdiff.SessionInfoProviderVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider of variable prov does not match with type net.sourceforge.squirrel_sql.plugins.dbdiff.SessionInfoProvider of variable prov
    • Make classes net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider and net.sourceforge.squirrel_sql.plugins.dbdiff.SessionInfoProvider extend a common superclass
    3
    SQLDatabaseMetaData md = prov.getDiffDestSession().getSQLConnection().getSQLMetaData();
    4
    ITableInfo[] tables = md.getTables(destCatalog, destSchema, destTableName, new String[] {"TABLE"}, null);
    4
    ITableInfo[] tables = md.getTables(destCatalog, destSchema, destTableName, new String[] {"TABLE"}, null);
    5
    if (tables != null && tables.length == 1)
    5
    if (tables != null && tables.length == 1)
    6
    ForeignKeyInfo[] fks = SQLUtilities.getImportedKeys(tables[0], md);
    6
    ForeignKeyInfo[] fks = SQLUtilities.getImportedKeys(tables[0], md);
    7
    for (ForeignKeyInfo existingKey : fks)
    7
    for (ForeignKeyInfo existingKey : fks)
    8
    if (areEqual(existingKey, fkInfo))
    8
    if (areEqual(existingKey, fkInfo))
    9
    result = true;
    9
    result = true;
    10
    break;
    10
    break;
    else
    else
    11
    log.error("Couldn't find an exact match for destination table " + destTableName + " in schema " + destSchema + " and catalog " + destCatalog + ". Skipping FK constraint");
    11
    log.error("Couldn't find an exact match for destination table " + destTableName + " in schema " + destSchema + " and catalog " + destCatalog + ". Skipping FK constraint");
    12
    return result;
    12
    return result;
    Precondition Violations (1)
    Row Violation
    1Type net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider of variable prov does not match with type net.sourceforge.squirrel_sql.plugins.dbdiff.SessionInfoProvider of variable prov