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: 22 | Number of AST nodes: 22 | |||
1 | int result;↵ | 1 | int result;↵ | |
2 | int rows;↵ | 2 | int rows;↵ | |
3 | do {↵ | 3 | do {↵ | |
4 | // The loop ensures atomicity of the↵ | 4 | // The loop ensures atomicity of the↵ | |
5 | // select + update even for no transaction↵ | 5 | // select + update even for no transaction↵ | |
6 | // or read committed isolation level↵ | 6 | // or read committed isolation level↵ | |
7 | //sql = query;↵ | 7 | sql = query;↵ | |
8 | SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );↵ | 8 | SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );↵ | |
9 | PreparedStatement qps = conn.prepareStatement(query);↵ | 9 | PreparedStatement qps = conn.prepareStatement(query);↵ | |
10 | PreparedStatement ips = null;↵ | 10 | ↵ | |
11 | try {↵ | |||
12 | //qps.setString(1, key);↵ | |||
13 | ResultSet rs = qps.executeQuery();↵ | |||
14 | boolean isInitialized = rs.next();↵ | |||
15 | if ( !isInitialized ) {↵ | |||
16 | result = 0;↵ | |||
17 | ips = conn.prepareStatement(insert);↵ | |||
18 | //ips.setString(1, key);↵ | |||
19 | ips.setInt(1, result);↵ | |||
20 | ips.execute(↵ | 11 | try {↵ | |
12 | ResultSet rs = qps.executeQuery();↵ | |||
13 | if ( !rs.next() ) {↵ | |||
14 | String err = "could not read a hi value - you need to populate the table: " + tableName;↵ | |||
15 | log.error(err);↵ | |||
21 | );↵ | 16 | throw new IdentifierGenerationException(err);↵ | |
22 | }↵ | 17 | }↵ | |
23 | else {↵ | 18 | ↵ | |
24 | result = rs.getInt(1);↵ | 19 | result = rs.getInt(1);↵ | |
25 | }↵ | 20 | ↵ | |
26 | rs.close();↵ | 21 | rs.close();↵ | |
27 | }↵ | 22 | }↵ | |
28 | catch (SQLException sqle) {↵ | 23 | catch (SQLException sqle) {↵ | |
29 | log.error("could not read or init a hi value", sqle);↵ | 24 | log.error("could not read a hi value", sqle);↵ | |
30 | throw sqle;↵ | 25 | throw sqle;↵ | |
31 | }↵ | 26 | }↵ | |
32 | finally {↵ | 27 | finally {↵ | |
33 | if (ips != null) {↵ | 28 | ↵ | |
34 | ips.close();↵ | 29 | qps.close();↵ | |
35 | }↵ | 30 | }↵ | |
36 | qps.close();↵ | 31 | ↵ | |
37 | }↵ | |||
38 | //sql = update↵ | 32 | sql = update;↵ | |
39 | ;↵ | 33 | SQL_STATEMENT_LOGGER.logStatement( sql, FormatStyle.BASIC );↵ | |
40 | PreparedStatement ups = conn.prepareStatement(update);↵ | 34 | PreparedStatement ups = conn.prepareStatement(update);↵ | |
41 | try {↵ | 35 | try {↵ | |
42 | ups.setInt( 1, result + 1 );↵ | 36 | ups.setInt( 1, result + 1 );↵ | |
43 | ups.setInt( 2, result );↵ | 37 | ups.setInt( 2, result );↵ | |
44 | //ups.setString( 3, key );↵ | 38 | ↵ | |
45 | rows = ups.executeUpdate();↵ | 39 | rows = ups.executeUpdate();↵ | |
46 | }↵ | 40 | }↵ | |
47 | catch (SQLException sqle) {↵ | 41 | catch (SQLException sqle) {↵ | |
48 | log.error("could not update hi value in: " + tableName, sqle);↵ | 42 | log.error("could not update hi value in: " + tableName, sqle);↵ | |
49 | throw sqle;↵ | 43 | throw sqle;↵ | |
50 | }↵ | 44 | }↵ | |
51 | finally {↵ | 45 | finally {↵ | |
52 | ups.close();↵ | 46 | ups.close();↵ | |
53 | }↵ | 47 | }↵ | |
54 | }↵ | 48 | }↵ | |
55 | while (rows==0);↵ | 49 | while (rows==0);↵ | |
56 | return new Integer(result); | 50 |
| |
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.2 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 79 |
Number of mapped statements | 11 |
Number of unmapped statements in the first code fragment | 11 |
Number of unmapped statements in the second code fragment | 11 |
Time elapsed for statement mapping (ms) | 12.9 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||
---|---|---|---|---|---|---|---|---|
1 | int result; | 1 | int result; | |||||
2 | int rows; | 2 | int rows; | |||||
21 | do while(rows == 0) | 21 | do while(rows == 0) | |||||
| 3 | sql = query; | ||||||
3 | SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC); | 4 | SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC); | |||||
4 | PreparedStatement qps = conn.prepareStatement(query); | 5 | PreparedStatement qps = conn.prepareStatement(query); | |||||
5 | PreparedStatement ips = null; |
| | |||||
|
| 6 | try | |||||
|
| 7 | ResultSet rs = qps.executeQuery(); | |||||
|
| 8 | if (!rs.next()) | |||||
|
| 9 | String err = "could not read a hi value - you need to populate the table: " + tableName; | |||||
| 10 | log.error(err); | ||||||
|
| 11 | throw new IdentifierGenerationException(err); | |||||
|
| 12 | result = rs.getInt(1); | |||||
|
| 13 | rs.close(); | |||||
6 | try |
| | |||||
7 | ResultSet rs = qps.executeQuery(); |
| | |||||
8 | boolean isInitialized = rs.next(); |
| | |||||
9 | if (!isInitialized) | | ||||||
10 | result = 0; |
| | |||||
11 | ips = conn.prepareStatement(insert); | | ||||||
12 | ips.setInt(1, result); | | ||||||
13 | ips.execute(); | | ||||||
else | | |||||||
14 | result = rs.getInt(1); |
| | |||||
15 | rs.close(); |
| | |||||
|
| 14 | sql = update; | |||||
| 15 | SQL_STATEMENT_LOGGER.logStatement(sql, FormatStyle.BASIC); | ||||||
16 | PreparedStatement ups = conn.prepareStatement(update); | 16 | PreparedStatement ups = conn.prepareStatement(update); | |||||
17 | try | 17 | try | |||||
18 | ups.setInt(1, result + 1); | 18 | ups.setInt(1, result + 1); | |||||
19 | ups.setInt(2, result); | 19 | ups.setInt(2, result); | |||||
20 | rows = ups.executeUpdate(); | 20 | rows = ups.executeUpdate(); | |||||
22 | return new Integer(result); | 22 | return new Integer(result); |
Row | Violation |
---|---|
1 | Unmatched statement PreparedStatement ips=null; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement try cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement ResultSet rs=qps.executeQuery(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement ResultSet rs=qps.executeQuery(); 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 |
5 | Unmatched statement if(!rs.next()) 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 String err="could not read a hi value - you need to populate the table: " + tableName; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Unmatched throw new IdentifierGenerationException(err); |
8 | 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 |
9 | 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 |
10 | Unmatched statement rs.close(); 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 | Unmatched statement try cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
12 | Unmatched statement ResultSet rs=qps.executeQuery(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
13 | Unmatched statement ResultSet rs=qps.executeQuery(); 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 boolean isInitialized=rs.next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
15 | Unmatched statement boolean isInitialized=rs.next(); 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 statement result=0; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
17 | 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 |
18 | Unmatched statement rs.close(); 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 | Unmatched statement sql=update; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
20 | The refactoring of the clones is infeasible, because classes org.hibernate.id.MultipleHiLoPerTableGenerator and org.hibernate.id.TableGenerator do not have a common superclass |