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 { // 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); return new Integer(result);
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/TableGenerator.java
Method name: Serializable doWorkInCurrentTransaction(Connection, String) Method name: Serializable doWorkInCurrentTransaction(Connection, String)
Number of AST nodes: 20 Number of AST nodes: 20
1
do {
1
do {
2
			// The loop ensures atomicity of the
2
			// The loop ensures atomicity of the
3
			// select + update even for no transaction
3
			// select + update even for no transaction
4
			// or read committed isolation level
4
			// or read committed isolation level
5
			//sql = query;
5
			sql = query;
6
			SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );
6
			SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );
7
			PreparedStatement qps = conn.prepareStatement(query);
7
			PreparedStatement qps = conn.prepareStatement(query);
8
			PreparedStatement ips = null;
8
			
9
			try {
10
				//qps.setString(1, key);
11
				ResultSet rs = qps.executeQuery();
12
				boolean isInitialized = rs.next();
13
				if ( !isInitialized ) {
14
					result = 0;
15
					ips = conn.prepareStatement(insert);
16
					//ips.setString(1, key);
17
					ips.setInt(1, result);
18
					ips.execute(
9
try {
10
				ResultSet rs = qps.executeQuery();
11
				if ( !rs.next() ) {
12
					String err = "could not read a hi value - you need to populate the table: " + tableName;
13
					log.error(err);
19
);
14
					throw new IdentifierGenerationException(err);
20
				}
15
				}
21
				else {
16
				
22
					result = rs.getInt(1);
17
result = rs.getInt(1);
23
				}
18
				
24
				rs.close();
19
rs.close();
25
			}
20
			}
26
			catch (SQLException sqle) {
21
			catch (SQLException sqle) {
27
				log.error("could not read or init a hi value", sqle);
22
				log.error("could not read a hi value", sqle);
28
				throw sqle;
23
				throw sqle;
29
			}
24
			}
30
			finally {
25
			finally {
31
				if (ips != null) {
26
				
32
					ips.close();
27
qps.close();
33
				}
28
			}
34
				qps.close();
29
			
35
			}
36
			//sql = update
30
sql = update;
37
;
31
			SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );
38
			PreparedStatement ups = conn.prepareStatement(update);
32
			PreparedStatement ups = conn.prepareStatement(update);
39
			try {
33
			try {
40
				ups.setInt( 1, result + 1 );
34
				ups.setInt( 1, result + 1 );
41
				ups.setInt( 2, result );
35
				ups.setInt( 2, result );
42
				//ups.setString( 3, key );
36
				
43
				rows = ups.executeUpdate();
37
rows = ups.executeUpdate();
44
			}
38
			}
45
			catch (SQLException sqle) {
39
			catch (SQLException sqle) {
46
				log.error("could not update hi value in: " + tableName, sqle);
40
				log.error("could not update hi value in: " + tableName, sqle);
47
				throw sqle;
41
				throw sqle;
48
			}
42
			}
49
			finally {
43
			finally {
50
				ups.close();
44
				ups.close();
51
			}
45
			}
52
		}
46
		}
53
		while (rows==0);
47
		while (rows==0);
54
		return new Integer(result);
48
		return new Integer(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)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.6
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    7
    ResultSet rs = qps.executeQuery();
    7
    ResultSet rs = qps.executeQuery();
    9
    if (!isInitialized)
    9
    if (!isInitialized)
    8
    if (!rs.next())
    Differences
    Expression1Expression2Difference
    isInitializedrs.next()TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression rs.next() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8
    if (!rs.next())
                                                                                                                                                                                      
    9
    String err = "could not read a hi value - you need to populate the table: " + tableName;
                                          
    10
    log.error(err);
    10
    result = 0;
                              
                                                                                                      
    11
    throw new IdentifierGenerationException(err);
    Preondition Violations
    Unmatched throw new IdentifierGenerationException(err);
    11
    throw new IdentifierGenerationException(err);
    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 rs.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