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);
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: 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
			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 {
15
				
22
					result = rs.getInt(1);
16
result = selectRS.getLong( 1 );
23
				}
17
				
24
				rs.close();
18
selectRS.close();
25
			}
19
			}
26
			catch (SQLException sqle) {
20
			catch ( SQLException sqle ) {
27
				log.error("could not read or init a hi value", sqle);
21
				log.error( "could not read a hi value", sqle );
28
				throw sqle;
22
				throw sqle;
29
			}
23
			}
30
			finally {
24
			finally {
31
				if (ips != null) {
25
				
32
					ips.close();
26
selectPS.close();
33
				}
27
			
34
				qps.close();
35
			}
36
			//sql = update;
28
}
29
			SQL_STATEMENT_LOGGER.logStatement( updateQuery, FormatStyle.BASIC );
37
			PreparedStatement ups = conn.prepareStatement(update);
30
			PreparedStatement updatePS = conn.prepareStatement( updateQuery );
38
			try {
31
			try {
39
				ups.setInt( 1, result + 1 );
32
				int increment = applyIncrementSizeToSourceValues ? incrementSize : 1;
40
				ups.setInt( 2, result );
33
				updatePS.setLong( 1, result + increment );
41
				//ups.setString( 3, key );
34
				updatePS.setLong( 2, result );
42
				rows = ups.executeUpdate();
35
				rows = updatePS.executeUpdate();
43
			}
36
			}
44
			catch (SQLException sqle) {
37
			catch ( SQLException sqle ) {
45
				log.error("could not update hi value in: " + tableName, sqle);
38
				log.error( "could not updateQuery hi value in: " + tableName, sqle );
46
				throw sqle;
39
				throw sqle;
47
			}
40
			}
48
			finally {
41
			finally {
49
				ups.close();
42
				updatePS.close();
50
			}
43
			}
51
		}
44
		}
52
		while (rows==0);
45
 while ( rows == 0 );
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.2
Clones locationClones are in different classes having the same super class
Number of node comparisons1