File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java | |||
Method name: void testIterateWithClearTopOfLoop()
|
Method name: void testIterateWithEvictTopOfLoop()
|
|||
Number of AST nodes: 30 | Number of AST nodes: 28 | |||
1 | Session s = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | s.beginTransaction();↵ | 2 | s.beginTransaction();↵ | |
3 | Set parents = new HashSet();↵ | 3 | Set parents = new HashSet();↵ | |
4 | for (int i=0; i<5; i++) {↵ | 4 | for (int i=0; i<5; i++) {↵ | |
5 | Parent p = new Parent( String.valueOf( i ) );↵ | 5 | Parent p = new Parent( String.valueOf( i + 100 ) );↵ | |
6 | Child child = new Child( "child" + i );↵ | 6 | Child child = new Child( "child" + i );↵ | |
7 | child.setParent( p );↵ | 7 | child.setParent( p );↵ | |
8 | p.getChildren().add( child );↵ | 8 | p.getChildren().add( child );↵ | |
9 | s.save( p );↵ | 9 | s.save( p );↵ | |
10 | parents.add(p);↵ | 10 | parents.add(p);↵ | |
11 | }↵ | 11 | }↵ | |
12 | s.getTransaction().commit();↵ | 12 | s.getTransaction().commit();↵ | |
13 | s.close();↵ | 13 | s.close();↵ | |
14 | s = openSession();↵ | 14 | s = openSession();↵ | |
15 | s.beginTransaction();↵ | 15 | s.beginTransaction();↵ | |
16 | int i = 0;↵ | 16 | Parent p = null;↵ | |
17 | for ( Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {↵ | 17 | for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {↵ | |
18 | i++;↵ | 18 | i↵ | |
19 | if (i % 2 == 0) {↵ | |||
20 | s.flush();↵ | |||
21 | s.clear();↵ | |||
22 | }↵ | |||
23 | Parent ↵ | 19 | f ( p != null) { s.evict(p); }↵ | |
24 | p = (Parent) it.next();↵ | 20 | p = (Parent) it.next();↵ | |
25 | assertEquals( 1, p.getChildren().size() );↵ | 21 | assertEquals( 1, p.getChildren().size() );↵ | |
26 | }↵ | 22 | }↵ | |
27 | s.getTransaction().commit();↵ | 23 | s.getTransaction().commit();↵ | |
28 | s.close();↵ | 24 | s.close();↵ | |
29 | s = openSession();↵ | 25 | s = openSession();↵ | |
30 | s.beginTransaction();↵ | 26 | s.beginTransaction();↵ | |
31 | for (Iterator it=parents.iterator(); it.hasNext(); ) {↵ | 27 | for (Iterator it=parents.iterator(); it.hasNext(); ) {↵ | |
32 | s.delete(it.next());↵ | 28 | s.delete(it.next());↵ | |
33 | }↵ | 29 | }↵ | |
34 | s.getTransaction().commit();↵ | 30 | s.getTransaction().commit();↵ | |
35 | s.close(); | 31 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 1 |
Number of non-refactorable cases | 0 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.2 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 94 |
Number of mapped statements | 22 |
Number of unmapped statements in the first code fragment | 8 |
Number of unmapped statements in the second code fragment | 6 |
Time elapsed for statement mapping (ms) | 26.9 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Session s = openSession(); | 1 | Session s = openSession(); | |||||||||||||
2 | s.beginTransaction(); | 2 | s.beginTransaction(); | |||||||||||||
3 | Set parents = new HashSet(); | 3 | Set parents = new HashSet(); | |||||||||||||
4 | for (int i = 0; i < 5; i++) | 4 | for (int i = 0; i < 5; i++) | |||||||||||||
5 | Parent p = new Parent(String.valueOf(i)); |
| 5 | Parent p = new Parent(String.valueOf(i + 100)); | ||||||||||||
6 | Child child = new Child("child" + i); | 6 | Child child = new Child("child" + i); | |||||||||||||
7 | child.setParent(p); | 7 | child.setParent(p); | |||||||||||||
8 | p.getChildren().add(child); | 8 | p.getChildren().add(child); | |||||||||||||
9 | s.save(p); | 9 | s.save(p); | |||||||||||||
10 | parents.add(p); | 10 | parents.add(p); | |||||||||||||
11 | s.getTransaction().commit(); | 11 | s.getTransaction().commit(); | |||||||||||||
12 | s.close(); | 12 | s.close(); | |||||||||||||
13 | s = openSession(); | 13 | s = openSession(); | |||||||||||||
14 | s.beginTransaction(); | 14 | s.beginTransaction(); | |||||||||||||
| 15 | Parent p = null; | ||||||||||||||
15 | int i = 0; | | ||||||||||||||
|
| 16 | for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); ) | |||||||||||||
| 17 | if (p != null) | ||||||||||||||
|
| 18 | s.evict(p); | |||||||||||||
| 19 | p = (Parent)it.next(); | ||||||||||||||
| 20 | assertEquals(1, p.getChildren().size()); | ||||||||||||||
16 | for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); ) |
| | |||||||||||||
17 | i++; | | ||||||||||||||
18 | if (i % 2 == 0) | | ||||||||||||||
19 | s.flush(); |
| | |||||||||||||
20 | s.clear(); |
| | |||||||||||||
21 | Parent p = (Parent)it.next(); | | ||||||||||||||
22 | assertEquals(1, p.getChildren().size()); | | ||||||||||||||
23 | s.getTransaction().commit(); | 21 | s.getTransaction().commit(); | |||||||||||||
24 | s.close(); | 22 | s.close(); | |||||||||||||
25 | s = openSession(); | 23 | s = openSession(); | |||||||||||||
26 | s.beginTransaction(); | 24 | s.beginTransaction(); | |||||||||||||
27 | for (Iterator it = parents.iterator(); it.hasNext(); ) | 25 | for (Iterator it = parents.iterator(); it.hasNext(); ) | |||||||||||||
28 | s.delete(it.next()); | 26 | s.delete(it.next()); | |||||||||||||
29 | s.getTransaction().commit(); | 27 | s.getTransaction().commit(); | |||||||||||||
30 | s.close(); | 28 | s.close(); |
Row | Violation |
---|---|
1 | Expression i cannot be parameterized, because it has dependencies to/from statements that will be extracted |
2 | Expression i + 100 cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement for(Iterator it=s.createQuery("from Parent").iterate(); it.hasNext()) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement s.evict(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | Unmatched statement for(Iterator it=s.createQuery("from Parent").iterate(); it.hasNext()) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
6 | Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement s.clear(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |