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); PreparedStatement ips = null; try { //qps.setString(1, key); ResultSet rs = qps.executeQuery(); boolean isInitialized = rs.next(); if ( !isInitialized ) { result = 0; ips = conn.prepareStatement(insert); //ips.setString(1, key); ips.setInt(1, result); ips.execute(); } else { result = rs.getInt(1); } rs.close(); } catch (SQLException sqle) { log.error("could not read or init a hi value", sqle); throw sqle; } finally { if (ips != null) { ips.close(); } qps.close(); } //sql = update; PreparedStatement ups = conn.prepareStatement(update); try { ups.setInt( 1, result + 1 ); ups.setInt( 2, result ); //ups.setString( 3, key ); rows = ups.executeUpdate(); } catch (SQLException sqle) { log.error("could not update hi value in: " + tableName, sqle); throw sqle; } finally { ups.close(); } } while (rows==0); return new Integer(result);
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/MultipleHiLoPerTableGenerator.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: 20 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
			PreparedStatement ips = null;
9
			try {
10
				//qps.setString(1, key);
5
			try {
11
				ResultSet rs = qps.executeQuery();
6
				ResultSet selectRS = selectPS.executeQuery();
12
				boolean isInitialized = rs.next();
7
				
13
				if ( !isInitialized ) {
8
if ( !selectRS.next() ) {
14
					result = 0;
9
					
15
					ips = conn.prepareStatement(insert);
16
					//ips.setString(1, key
10
String err = "could not read a hi value - you need to populate the table: " + tableName;
17
);
11
					log.error( err );
18
					ips.setInt(1, result);
12
					
19
					ips.execute();
13
throw new IdentifierGenerationException( err );
20
				}
14
				}
21
				else {
22
					result = rs.getInt(1);
15
				result = 
23
				}
24
				rs
16
selectRS.getLong( 1 );
25
.close();
17
				selectRS.close();
26
			}
18
			}
27
			catch (SQLException sqle) {
19
			catch ( SQLException sqle ) {
28
				log.error("could not read or init a hi value", sqle);
20
				log.error( "could not read a hi value", sqle );
29
				throw sqle;
21
				throw sqle;
30
			}
22
			}
31
			finally {
23
			finally {
32
				if (ips != null) {
24
				
33
					ips.close();
25
selectPS.close();
34
				}
26
			
35
				qps.close();
36
			}
37
			//sql = update;
27
}
28
			SQL_STATEMENT_LOGGER.logStatement( updateQuery, FormatStyle.BASIC );
38
			PreparedStatement ups = conn.prepareStatement(update);
29
			PreparedStatement updatePS = conn.prepareStatement( updateQuery );
39
			try {
30
			try {
40
				ups.setInt( 1, result + 1 );
31
				int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
41
				ups.setInt( 2, result );
32
				updatePS.setLong( 1, result + increment );
42
				//ups.setString( 3, key );
33
				updatePS.setLong( 2, result );
43
				rows = ups.executeUpdate();
34
				rows = updatePS.executeUpdate();
44
			}
35
			}
45
			catch (SQLException sqle) {
36
			catch ( SQLException sqle ) {
46
				log.error("could not update hi value in: " + tableName, sqle);
37
				log.error( "could not updateQuery hi value in: " + tableName, sqle );
47
				throw sqle;
38
				throw sqle;
48
			}
39
			}
49
			finally {
40
			finally {
50
				ups.close();
41
				updatePS.close();
51
			}
42
			}
52
		}
43
		}
53
		while (rows==0);
44
 while ( rows ==
54
		return new Integer(result);
45
 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.3
Clones locationClones are in different classes having the same super class
Number of node comparisons28
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment6
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)1.5
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    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();
    9
    if (!isInitialized)
    9
    if (!isInitialized)
    7
    if (!selectRS.next())
    Differences
    Expression1Expression2Difference
    isInitializedselectRS.next()TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression selectRS.next() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7
    if (!selectRS.next())
                                                                                                                                                                                      
    8
    String err = "could not read a hi value - you need to populate the table: " + tableName;
                                        
    9
    log.error(err);
                                                                                                      
    10
    throw new IdentifierGenerationException(err);
    Preondition Violations
    Unmatched throw new IdentifierGenerationException(err);
    10
    throw new IdentifierGenerationException(err);
    10
    result = 0;
                              
    11
    ips = conn.prepareStatement(insert);
                                                                                
    12
    ips.setInt(1, result);
                                                      
    13
    ips.execute();
                                        
    else
            
    14
    result = rs.getInt(1);
    14
    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
                                                    
    Precondition Violations (3)
    Row Violation
    1Expression selectRS.next() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Unmatched throw new IdentifierGenerationException(err);
    3Unmatched 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