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: 22 | Number of AST nodes: 22 | |||
1 | int result;↵ | 1 | long result; ↵ | |
2 | int rows;↵ | 2 | int rows; ↵ | |
3 | do {↵ | 3 | do {↵ | |
4 | // The loop ensures atomicity of the↵ | |||
5 | // select + update even for no transaction↵ | |||
6 | // or read committed isolation level↵ | |||
7 | sql = query;↵ | 4 | ↵ | |
8 | SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );↵ | 5 | SQL_STATEMENT_LOGGER.logStatement( selectQuery, FormatStyle.BASIC ); ↵ | |
9 | PreparedStatement qps = conn.prepareStatement(query);↵ | 6 | PreparedStatement selectPS = conn.prepareStatement( selectQuery ); ↵ | |
10 | try {↵ | 7 | try { ↵ | |
11 | ResultSet rs = qps.executeQuery();↵ | 8 | ResultSet selectRS = selectPS.executeQuery(); ↵ | |
12 | if ( !rs.next() ) {↵ | 9 | if ( !selectRS.next() ) { ↵ | |
13 | String err = "could not read a hi value - you need to populate the table: " + tableName;↵ | 10 | String err = "could not read a hi value - you need to populate the table: " + tableName; ↵ | |
14 | log.error(err);↵ | 11 | log.error( err ); ↵ | |
15 | throw new IdentifierGenerationException(err);↵ | 12 | throw new IdentifierGenerationException( err ); ↵ | |
16 | }↵ | 13 | } ↵ | |
17 | result = rs.getInt(1);↵ | 14 | result = selectRS.getLong( 1 ); ↵ | |
18 | rs.close();↵ | 15 | selectRS.close(); ↵ | |
19 | }↵ | 16 | } ↵ | |
20 | catch (SQLException sqle) {↵ | 17 | catch ( SQLException sqle ) { ↵ | |
21 | log.error("could not read a hi value", sqle);↵ | 18 | log.error( "could not read a hi value", sqle ); ↵ | |
22 | throw sqle;↵ | 19 | throw sqle; ↵ | |
23 | }↵ | 20 | } ↵ | |
24 | finally {↵ | 21 | finally { ↵ | |
25 | qps.close();↵ | 22 | selectPS.close(); ↵ | |
26 | }↵ | 23 | }↵ | |
27 | sql = update;↵ | |||
24 | ↵ | |||
28 | SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );↵ | 25 | SQL_STATEMENT_LOGGER.logStatement( updateQuery, FormatStyle.BASIC ); ↵ | |
29 | PreparedStatement ups = conn.prepareStatement(update);↵ | 26 | PreparedStatement updatePS = conn.prepareStatement( updateQuery ); ↵ | |
30 | try {↵ | 27 | try {↵ | |
28 | int increment = applyIncrementSizeToSourceValues ? incrementSize : 1; ↵ | |||
31 | ups.setInt( 1, result + 1 );↵ | 29 | updatePS.setLong( 1, result + increment ); ↵ | |
32 | ups.setInt( 2, result );↵ | 30 | updatePS.setLong( 2, result ); ↵ | |
33 | rows = ups.executeUpdate();↵ | 31 | rows = updatePS.executeUpdate(); ↵ | |
34 | }↵ | 32 | } ↵ | |
35 | catch (SQLException sqle) {↵ | 33 | catch ( SQLException sqle ) { ↵ | |
36 | log.error("could not update hi value in: " + tableName, sqle);↵ | 34 | log.error( "could not updateQuery hi value in: " + tableName, sqle ); ↵ | |
37 | throw sqle;↵ | 35 | throw sqle; ↵ | |
38 | }↵ | 36 | } ↵ | |
39 | finally {↵ | 37 | finally { ↵ | |
40 | ups.close();↵ | 38 | updatePS.close(); ↵ | |
41 | }↵ | 39 | } ↵ | |
42 | }↵ | 40 | }↵ | |
43 | while (rows==0);↵ | 41 | while ( rows == 0 );↵ | |
42 | accessCounter++;↵ | |||
43 | ↵ | |||
44 | return new Integer(result); | 44 | return new Long( result ); | |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.7 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 99 |
Number of mapped statements | 15 |
Number of unmapped statements in the first code fragment | 7 |
Number of unmapped statements in the second code fragment | 7 |
Time elapsed for statement mapping (ms) | 6.7 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | long result; | |||||||||||||||
1 | int result; |
| 2 | int rows; | |||||||||||||
2 | int rows; | | |||||||||||||||
21 | do while(rows == 0) | 20 | do while(rows == 0) | ||||||||||||||
3 | sql = query; |
| | ||||||||||||||
4 | SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC); |
| 3 | SQL_STATEMENT_LOGGER.logStatement(selectQuery, FormatStyle.BASIC); | |||||||||||||
5 | PreparedStatement qps = conn.prepareStatement(query); |
| 4 | PreparedStatement selectPS = conn.prepareStatement(selectQuery); | |||||||||||||
6 | try |
| 5 | try | |||||||||||||
7 | ResultSet rs = qps.executeQuery(); |
| 6 | ResultSet selectRS = selectPS.executeQuery(); | |||||||||||||
8 | if (!rs.next()) |
| 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); | ||||||||||||||
12 | result = rs.getInt(1); |
| | ||||||||||||||
13 | rs.close(); |
| 12 | selectRS.close(); | |||||||||||||
14 | sql = update; |
| | ||||||||||||||
15 | SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC); |
| 13 | SQL_STATEMENT_LOGGER.logStatement(updateQuery, FormatStyle.BASIC); | |||||||||||||
16 | PreparedStatement ups = conn.prepareStatement(update); |
| 14 | PreparedStatement updatePS = conn.prepareStatement(updateQuery); | |||||||||||||
17 | try |
| 15 | try | |||||||||||||
|
| 16 | int increment = applyIncrementSizeToSourceValues ? incrementSize : 1; | ||||||||||||||
|
| 17 | updatePS.setLong(1, result + increment); | ||||||||||||||
|
| 18 | updatePS.setLong(2, result); | ||||||||||||||
18 | ups.setInt(1, result + 1); |
| | ||||||||||||||
19 | ups.setInt(2, result); |
| | ||||||||||||||
20 | rows = ups.executeUpdate(); |
| 19 | rows = updatePS.executeUpdate(); | |||||||||||||
| 21 | accessCounter++; | |||||||||||||||
|
| 22 | return new Long(result); | ||||||||||||||
22 | return new Integer(result); |
| |
Row | Violation |
---|---|
1 | Unmatched statement sql=query; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | 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 |
3 | 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 |
4 | 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 |
5 | 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 |
6 | Unmatched statement sql=update; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | 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 |
8 | 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 |
9 | 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 |
10 | 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 |
11 | 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 |
12 | 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 |
13 | 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 |
14 | 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 |
15 | 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 |
16 | Unmatched return new Long(result); |
17 | Unmatched return new Integer(result); |
18 | Clone fragment #1 returns variables result, rs, ups , while Clone fragment #2 returns variables selectRS, updatePS |