do { // The loop ensures atomicity of the // select + update even for no transaction // or read committed isolation level sql = query; SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC ); PreparedStatement qps = conn.prepareStatement(query); try { ResultSet rs = qps.executeQuery(); if ( !rs.next() ) { String err = "could not read a hi value - you need to populate the table: " + tableName; log.error(err); throw new IdentifierGenerationException(err); } result = rs.getInt(1); rs.close(); } catch (SQLException sqle) { log.error("could not read a hi value", sqle); throw sqle; } finally { qps.close(); } sql = update; SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC ); PreparedStatement ups = conn.prepareStatement(update); try { ups.setInt( 1, result + 1 ); ups.setInt( 2, result ); rows = ups.executeUpdate(); } catch (SQLException sqle) { log.error("could not update hi value in: " + tableName, sqle); throw sqle; } finally { ups.close(); } } while (rows==0);
do { SQL_STATEMENT_LOGGER.logStatement( selectQuery, FormatStyle.BASIC ); PreparedStatement selectPS = conn.prepareStatement( selectQuery ); try { ResultSet selectRS = selectPS.executeQuery(); if ( !selectRS.next() ) { String err = "could not read a hi value - you need to populate the table: " + tableName; log.error( err ); throw new IdentifierGenerationException( err ); } result = selectRS.getLong( 1 ); selectRS.close(); } catch ( SQLException sqle ) { log.error( "could not read a hi value", sqle ); throw sqle; } finally { selectPS.close(); } SQL_STATEMENT_LOGGER.logStatement( updateQuery, FormatStyle.BASIC ); PreparedStatement updatePS = conn.prepareStatement( updateQuery ); try { int increment = applyIncrementSizeToSourceValues ? incrementSize : 1; updatePS.setLong( 1, result + increment ); updatePS.setLong( 2, result ); rows = updatePS.executeUpdate(); } catch ( SQLException sqle ) { log.error( "could not updateQuery hi value in: " + tableName, sqle ); throw sqle; } finally { updatePS.close(); } } while ( rows == 0 );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/id/TableGenerator.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
Method name: Serializable doWorkInCurrentTransaction(Connection, String) Method name: Serializable doWorkInCurrentTransaction(Connection, String)
Number of AST nodes: 19 Number of AST nodes: 18
1
do {
1
do {
2
			// The loop ensures atomicity of the
3
			// select + update even for no transaction
4
			// or read committed isolation level
5
			sql = query;
2

6
			SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );
3
			SQL_STATEMENT_LOGGER.logStatement( selectQuery, FormatStyle.BASIC );
7
			PreparedStatement qps = conn.prepareStatement(query);
4
			PreparedStatement selectPS = conn.prepareStatement( selectQuery );
8
			try {
5
			try {
9
				ResultSet rs = qps.executeQuery();
6
				ResultSet selectRS = selectPS.executeQuery();
10
				if ( !rs.next() ) {
7
				if ( !selectRS.next() ) {
11
					String err = "could not read a hi value - you need to populate the table: " + tableName;
8
					String err = "could not read a hi value - you need to populate the table: " + tableName;
12
					log.error(err);
9
					log.error( err );
13
					throw new IdentifierGenerationException(err);
10
					throw new IdentifierGenerationException( err );
14
				}
11
				}
15
				result = rs.getInt(1);
12
				result = selectRS.getLong( 1 );
16
				rs.close();
13
				selectRS.close();
17
			}
14
			}
18
			catch (SQLException sqle) {
15
			catch ( SQLException sqle ) {
19
				log.error("could not read a hi value", sqle);
16
				log.error( "could not read a hi value", sqle );
20
				throw sqle;
17
				throw sqle;
21
			}
18
			}
22
			finally {
19
			finally {
23
				qps.close();
20
				selectPS.close();
24
			}
21
			}
25
			sql = update;
22

26
			SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );
23
			SQL_STATEMENT_LOGGER.logStatement( updateQuery, FormatStyle.BASIC );
27
			PreparedStatement ups = conn.prepareStatement(update);
24
			PreparedStatement updatePS = conn.prepareStatement( updateQuery );
28
			try {
25
			try {
29
				ups.setInt
26
				int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
30
( 1, result + 1 );
27
				updatePS.setLong( 1, result + increment );
31
				ups.setInt( 2, result );
28
				updatePS.setLong( 2, result );
32
				rows = ups.executeUpdate();
29
				rows = updatePS.executeUpdate();
33
			}
30
			}
34
			catch (SQLException sqle) {
31
			catch ( SQLException sqle ) {
35
				log.error("could not update hi value in: " + tableName, sqle);
32
				log.error( "could not updateQuery hi value in: " + tableName, sqle );
36
				throw sqle;
33
				throw sqle;
37
			}
34
			}
38
			finally {
35
			finally {
39
				ups.close();
36
				updatePS.close();
40
			}
37
			}
41
		}
38
		}
42
		while (rows==0);
39
 while ( rows == 0 );
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)0.6
Clones locationClones are in different classes having the same super class
Number of node comparisons87
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements14
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment4
    Time elapsed for statement mapping (ms)10.3
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    21
    do while(rows == 0)
    20
    do while(rows == 0)
    3
    sql = query;
    3
    sql = query;
    Preondition Violations
    Unmatched statement sql=query; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                              
    4
    SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC);
    4
    SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC);
    3
    SQL_STATEMENT_LOGGER.logStatement(selectQuery, FormatStyle.BASIC);
    Differences
    Expression1Expression2Difference
    sqlselectQueryVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression sql cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3
    SQL_STATEMENT_LOGGER.logStatement(selectQuery, FormatStyle.BASIC);
    5
    PreparedStatement qps = conn.prepareStatement(query);
    5
    PreparedStatement qps = conn.prepareStatement(query);
    4
    PreparedStatement selectPS = conn.prepareStatement(selectQuery);
    Differences
    Expression1Expression2Difference
    qpsselectPSVARIABLE_NAME_MISMATCH
    queryselectQueryVARIABLE_NAME_MISMATCH
    4
    PreparedStatement selectPS = conn.prepareStatement(selectQuery);
    6
    try
    6
    try
    5
    try
    Differences
    Expression1Expression2Difference
    qpsselectPSVARIABLE_NAME_MISMATCH
    5
    try
    7
    ResultSet rs = qps.executeQuery();
    7
    ResultSet rs = qps.executeQuery();
    6
    ResultSet selectRS = selectPS.executeQuery();
    Differences
    Expression1Expression2Difference
    rsselectRSVARIABLE_NAME_MISMATCH
    qpsselectPSVARIABLE_NAME_MISMATCH
    6
    ResultSet selectRS = selectPS.executeQuery();
    8
    if (!rs.next())
    8
    if (!rs.next())
    7
    if (!selectRS.next())
    Differences
    Expression1Expression2Difference
    rsselectRSVARIABLE_NAME_MISMATCH
    7
    if (!selectRS.next())
    9
    String err = "could not read a hi value - you need to populate the table: " + tableName;
    8
    String err = "could not read a hi value - you need to populate the table: " + tableName;
    10
    log.error(err);
    9
    log.error(err);
    11
    throw new IdentifierGenerationException(err);
    10
    throw new IdentifierGenerationException(err);
                                                                  
    11
    result = selectRS.getLong(1);
    Preondition Violations
    Unmatched statement result=selectRS.getLong(1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement result=selectRS.getLong(1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    11
    result = selectRS.getLong(1);
    12
    result = rs.getInt(1);
    12
    result = rs.getInt(1);
    Preondition Violations
    Unmatched statement result=rs.getInt(1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement result=rs.getInt(1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                    
    13
    rs.close();
    13
    rs.close();
    12
    selectRS.close();
    Differences
    Expression1Expression2Difference
    rsselectRSVARIABLE_NAME_MISMATCH
    12
    selectRS.close();
    14
    sql = update;
    14
    sql = update;
    Preondition Violations
    Unmatched statement sql=update; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                  
    15
    SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC);
    15
    SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC);
    13
    SQL_STATEMENT_LOGGER.logStatement(updateQuery, FormatStyle.BASIC);
    Differences
    Expression1Expression2Difference
    sqlupdateQueryVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression sql cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    SQL_STATEMENT_LOGGER.logStatement(updateQuery, FormatStyle.BASIC);
    16
    PreparedStatement ups = conn.prepareStatement(update);
    16
    PreparedStatement ups = conn.prepareStatement(update);
    14
    PreparedStatement updatePS = conn.prepareStatement(updateQuery);
    Differences
    Expression1Expression2Difference
    upsupdatePSVARIABLE_NAME_MISMATCH
    updateupdateQueryVARIABLE_NAME_MISMATCH
    14
    PreparedStatement updatePS = conn.prepareStatement(updateQuery);
    17
    try
    17
    try
    15
    try
    Differences
    Expression1Expression2Difference
    "could not update hi value in: ""could not updateQuery hi value in: "LITERAL_VALUE_MISMATCH
    upsupdatePSVARIABLE_NAME_MISMATCH
    15
    try
                                                                                                                                                  
    16
    int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
    Preondition Violations
    Unmatched statement int increment=applyIncrementSizeToSourceValues ? incrementSize : 1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
                                                                                          
    17
    updatePS.setLong(1, result + increment);
    Preondition Violations
    Unmatched statement updatePS.setLong(1,result + increment); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement updatePS.setLong(1,result + increment); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    17
    updatePS.setLong(1, result + increment);
                                                                  
    18
    updatePS.setLong(2, result);
    Preondition Violations
    Unmatched statement updatePS.setLong(2,result); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement updatePS.setLong(2,result); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    18
    updatePS.setLong(2, result);
    18
    ups.setInt(1, result + 1);
    18
    ups.setInt(1, result + 1);
    Preondition Violations
    Unmatched statement ups.setInt(1,result + 1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement ups.setInt(1,result + 1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                              
    19
    ups.setInt(2, result);
    19
    ups.setInt(2, result);
    Preondition Violations
    Unmatched statement ups.setInt(2,result); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement ups.setInt(2,result); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                      
    20
    rows = ups.executeUpdate();
    20
    rows = ups.executeUpdate();
    19
    rows = updatePS.executeUpdate();
    Differences
    Expression1Expression2Difference
    upsupdatePSVARIABLE_NAME_MISMATCH
    19
    rows = updatePS.executeUpdate();
    Precondition Violations (18)
    Row Violation
    1Unmatched statement sql=query; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression sql cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement result=selectRS.getLong(1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement result=selectRS.getLong(1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    5Unmatched statement result=rs.getInt(1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement result=rs.getInt(1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    7Unmatched statement sql=update; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Expression sql cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Unmatched statement int increment=applyIncrementSizeToSourceValues ? incrementSize : 1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement updatePS.setLong(1,result + increment); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement updatePS.setLong(1,result + increment); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    12Unmatched statement updatePS.setLong(2,result); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Unmatched statement updatePS.setLong(2,result); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    14Unmatched statement ups.setInt(1,result + 1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement ups.setInt(1,result + 1); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    16Unmatched statement ups.setInt(2,result); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement ups.setInt(2,result); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    18Clone fragment #1 returns variables rs, ups , while Clone fragment #2 returns variables selectRS, updatePS