File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/lock/RepeatableReadTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/jpa/lock/RepeatableReadTest.java | |||
Method name: void testStaleVersionedInstanceFoundInQueryResult()
|
Method name: void testStaleNonVersionedInstanceFoundInQueryResult()
|
|||
Number of AST nodes: 32 | Number of AST nodes: 31 | |||
1 | if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) {↵ | 1 | if ( getDialect().doesReadCommittedCauseWritersToBlockReaders()) {↵ | |
2 | reportSkip( "lock blocking", "stale versioned instance" );↵ | 2 | reportSkip( "lock blocking", "stale versioned instance" );↵ | |
3 | return;↵ | 3 | return;↵ | |
4 | }↵ | 4 | }↵ | |
5 | String check = "EJB3 Specification";↵ | 5 | String check = "Lock Modes";↵ | |
6 | Session s1 = getSessions().openSession();↵ | 6 | Session s1 = getSessions().openSession();↵ | |
7 | Transaction t1 = s1.beginTransaction();↵ | 7 | Transaction t1 = s1.beginTransaction();↵ | |
8 | Item item = new Item( check );↵ | 8 | Part part = new Part( new Item( "EJB3 Specification" ), check, "3.3.5.3", new BigDecimal( 0.0 ) );↵ | |
9 | s1.save( item );↵ | 9 | s1.save( part );↵ | |
10 | t1.commit();↵ | 10 | t1.commit();↵ | |
11 | s1.close();↵ | 11 | s1.close();↵ | |
12 | Long itemId = item.getId();↵ | 12 | Long partId = ↵ | |
13 | long initialVersion = item.getVersion();↵ | 13 | part.getId();↵ | |
14 | // Now, open a new Session and re-load the item...↵ | 14 | // Now, open a new Session and re-load the part...↵ | |
15 | s1 = getSessions().openSession();↵ | 15 | s1 = getSessions().openSession();↵ | |
16 | t1 = s1.beginTransaction();↵ | 16 | t1 = s1.beginTransaction();↵ | |
17 | item = ( Item ) s1.get( Item.class, itemId );↵ | 17 | part = ( Part ) s1.get( Part.class, partId );↵ | |
18 | // now that the item is associated with the persistence-context of that session,↵ | 18 | // now that the item is associated with the persistence-context of that session,↵ | |
19 | // open a new session and modify it "behind the back" of the first session↵ | 19 | // open a new session and modify it "behind the back" of the first session↵ | |
20 | Session s2 = getSessions().openSession();↵ | 20 | Session s2 = getSessions().openSession();↵ | |
21 | Transaction t2 = s2.beginTransaction();↵ | 21 | Transaction t2 = s2.beginTransaction();↵ | |
22 | Item item2 = ( Item ) s2.get( Item.class, itemId );↵ | 22 | Part part2 = ( Part ) s2.get( Part.class, partId );↵ | |
23 | item2.setName( "EJB3 Persistence Spec" );↵ | 23 | part2.setName( "Lock Mode Types" );↵ | |
24 | t2.commit();↵ | 24 | t2.commit();↵ | |
25 | s2.close();↵ | 25 | s2.close();↵ | |
26 | // at this point, s1 now contains stale data, so try an hql query which↵ | 26 | // at this point, s1 now contains stale data, so try an hql query which↵ | |
27 | // returns said item and make sure we get the previously associated state↵ | 27 | // returns said part and make sure we get the previously associated state↵ | |
28 | // (i.e., the old name and the old version)↵ | 28 | // (i.e., the old name)↵ | |
29 | item2 = ( Item ) s1.createQuery( "select i from Item i" ).list().get( 0 );↵ | 29 | part2 = ( Part ) s1.createQuery( "select p from Part p" ).list().get( 0 );↵ | |
30 | assertTrue( item == item2 );↵ | 30 | assertTrue( part == part2 );↵ | |
31 | assertEquals( "encountered non-repeatable read", check, item2.getName() );↵ | 31 | assertEquals( "encountered non-repeatable read", check, ↵ | |
32 | assertEquals( "encountered non-repeatable read", initialVersion, item2.getVersion() );↵ | 32 | part2.getName() );↵ | |
33 | t1.commit();↵ | 33 | t1.commit();↵ | |
34 | s1.close();↵ | 34 | s1.close();↵ | |
35 | // clean up↵ | 35 | // clean up↵ | |
36 | s1 = getSessions().openSession();↵ | 36 | s1 = getSessions().openSession();↵ | |
37 | t1 = s1.beginTransaction();↵ | 37 | t1 = s1.beginTransaction();↵ | |
38 | s1.createQuery( "delete Item" ).executeUpdate(↵ | 38 | s1.delete( part2 );↵ | |
39 | );↵ | 39 | s1.delete( part2.getItem() );↵ | |
40 | t1.commit();↵ | 40 | t1.commit();↵ | |
41 | s1.close(); | 41 |
| |
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 declared in the same class |
Number of node comparisons | 286 |
Number of mapped statements | 25 |
Number of unmapped statements in the first code fragment | 7 |
Number of unmapped statements in the second code fragment | 6 |
Time elapsed for statement mapping (ms) | 38.1 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | if (getDialect().doesReadCommittedCauseWritersToBlockReaders()) | 1 | if (getDialect().doesReadCommittedCauseWritersToBlockReaders()) | ||||||||||||||||||||||
2 | reportSkip("lock blocking", "stale versioned instance"); | 2 | reportSkip("lock blocking", "stale versioned instance"); | ||||||||||||||||||||||
3 | return; | 3 | return; | ||||||||||||||||||||||
4 | String check = "EJB3 Specification"; |
| 4 | String check = "Lock Modes"; | |||||||||||||||||||||
5 | Session s1 = getSessions().openSession(); | 5 | Session s1 = getSessions().openSession(); | ||||||||||||||||||||||
6 | Transaction t1 = s1.beginTransaction(); | 6 | Transaction t1 = s1.beginTransaction(); | ||||||||||||||||||||||
|
| 7 | Part part = new Part(new Item("EJB3 Specification"), check, "3.3.5.3", new BigDecimal(0.0)); | ||||||||||||||||||||||
7 | Item item = new Item(check); |
| | ||||||||||||||||||||||
8 | s1.save(item); |
| 8 | s1.save(part); | |||||||||||||||||||||
9 | t1.commit(); | 9 | t1.commit(); | ||||||||||||||||||||||
10 | s1.close(); | 10 | s1.close(); | ||||||||||||||||||||||
11 | Long itemId = item.getId(); |
| 11 | Long partId = part.getId(); | |||||||||||||||||||||
12 | long initialVersion = item.getVersion(); | | |||||||||||||||||||||||
13 | s1 = getSessions().openSession(); | 12 | s1 = getSessions().openSession(); | ||||||||||||||||||||||
14 | t1 = s1.beginTransaction(); | 13 | t1 = s1.beginTransaction(); | ||||||||||||||||||||||
|
| 14 | part = (Part)s1.get(Part.class, partId); | ||||||||||||||||||||||
15 | item = (Item)s1.get(Item.class, itemId); |
| | ||||||||||||||||||||||
16 | Session s2 = getSessions().openSession(); | 15 | Session s2 = getSessions().openSession(); | ||||||||||||||||||||||
17 | Transaction t2 = s2.beginTransaction(); | 16 | Transaction t2 = s2.beginTransaction(); | ||||||||||||||||||||||
|
| 17 | Part part2 = (Part)s2.get(Part.class, partId); | ||||||||||||||||||||||
18 | Item item2 = (Item)s2.get(Item.class, itemId); |
| | ||||||||||||||||||||||
19 | item2.setName("EJB3 Persistence Spec"); |
| 18 | part2.setName("Lock Mode Types"); | |||||||||||||||||||||
20 | t2.commit(); | 19 | t2.commit(); | ||||||||||||||||||||||
21 | s2.close(); | 20 | s2.close(); | ||||||||||||||||||||||
|
| 21 | part2 = (Part)s1.createQuery("select p from Part p").list().get(0); | ||||||||||||||||||||||
22 | item2 = (Item)s1.createQuery("select i from Item i").list().get(0); |
| | ||||||||||||||||||||||
23 | assertTrue(item == item2); |
| 22 | assertTrue(part == part2); | |||||||||||||||||||||
24 | assertEquals("encountered non-repeatable read", check, item2.getName()); |
| 23 | assertEquals("encountered non-repeatable read", check, part2.getName()); | |||||||||||||||||||||
25 | assertEquals("encountered non-repeatable read", initialVersion, item2.getVersion()); | | |||||||||||||||||||||||
26 | t1.commit(); | 24 | t1.commit(); | ||||||||||||||||||||||
27 | s1.close(); | 25 | s1.close(); | ||||||||||||||||||||||
28 | s1 = getSessions().openSession(); | 26 | s1 = getSessions().openSession(); | ||||||||||||||||||||||
29 | t1 = s1.beginTransaction(); | 27 | t1 = s1.beginTransaction(); | ||||||||||||||||||||||
|
| 28 | s1.delete(part2); | ||||||||||||||||||||||
|
| 29 | s1.delete(part2.getItem()); | ||||||||||||||||||||||
30 | s1.createQuery("delete Item").executeUpdate(); |
| | ||||||||||||||||||||||
31 | t1.commit(); | 30 | t1.commit(); | ||||||||||||||||||||||
32 | s1.close(); | 31 | s1.close(); |
Row | Violation |
---|---|
1 | Unmatched statement Part part=new Part(new Item("EJB3 Specification"),check,"3.3.5.3",new BigDecimal(0.0)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement Item item=new Item(check); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part |
4 | Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part |
5 | Unmatched statement part=(Part)s1.get(Part.class,partId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
6 | Unmatched statement item=(Item)s1.get(Item.class,itemId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement Part part2=(Part)s2.get(Part.class,partId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
8 | Unmatched statement Item item2=(Item)s2.get(Item.class,itemId); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
9 | Type org.hibernate.test.jpa.Item of variable item2 does not match with type org.hibernate.test.jpa.Part of variable part2 |
10 | Unmatched statement part2=(Part)s1.createQuery("select p from Part p").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
11 | Unmatched statement item2=(Item)s1.createQuery("select i from Item i").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
12 | Type org.hibernate.test.jpa.Item of variable item does not match with type org.hibernate.test.jpa.Part of variable part |
13 | Type org.hibernate.test.jpa.Item of variable item2 does not match with type org.hibernate.test.jpa.Part of variable part2 |
14 | Type org.hibernate.test.jpa.Item of variable item2 does not match with type org.hibernate.test.jpa.Part of variable part2 |
15 | Unmatched statement s1.delete(part2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
16 | Unmatched statement s1.delete(part2.getItem()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
17 | Unmatched statement s1.createQuery("delete Item").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
18 | Clone fragment #1 returns variables check, itemId, s1, s2 , while Clone fragment #2 returns variables check, partId, s1, s2 |