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 ); | |
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.3 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 28 |
Number of mapped statements | 2 |
Number of unmapped statements in the first code fragment | 6 |
Number of unmapped statements in the second code fragment | 3 |
Time elapsed for statement mapping (ms) | 1.5 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7 | ResultSet rs = qps.executeQuery(); |
| 6 | ResultSet selectRS = selectPS.executeQuery(); | |||||||||||||
9 | if (!isInitialized) |
| 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); | ||||||||||||||
10 | result = 0; | | |||||||||||||||
11 | ips = conn.prepareStatement(insert); | | |||||||||||||||
12 | ips.setInt(1, result); | | |||||||||||||||
13 | ips.execute(); | | |||||||||||||||
else | | ||||||||||||||||
14 | result = rs.getInt(1); |
| |
Row | Violation |
---|---|
1 | Expression selectRS.next() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
2 | Unmatched throw new IdentifierGenerationException(err); |
3 | 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 |