Session s = openSession(); Transaction t = s.beginTransaction(); Item i = new Item(); i.setName("widget"); i.setDescription("A really top-quality, full-featured widget."); s.persist(i); t.commit(); s.close(); SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics( getPrefixedRegionName(Item.class.getName())); assertEquals(slcs.getPutCount(), 1); assertEquals(slcs.getElementCountInMemory(), 1); assertEquals(slcs.getEntries().size(), 1); s = openSession(); t = s.beginTransaction(); i = (Item) s.get(Item.class, i.getId()); assertEquals(slcs.getHitCount(), 1); assertEquals(slcs.getMissCount(), 0); i.setDescription("A bog standard item"); t.commit(); s.close(); assertEquals(slcs.getPutCount(), 2); Object entry = slcs.getEntries().get(i.getId()); Map map; if (entry instanceof ReadWriteCache.Item) { map = (Map) ((ReadWriteCache.Item) entry).getValue(); } else { map = (Map) entry; } assertTrue(map.get("description").equals("A bog standard item")); assertTrue(map.get("name").equals("widget")); // cleanup s = openSession(); t = s.beginTransaction(); s.delete(i); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Item i = new Item(); i.setName("widget"); i.setDescription("A really top-quality, full-featured widget."); s.persist(i); t.commit(); s.close(); SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics() .getSecondLevelCacheStatistics( Item.class.getName() ); assertEquals( slcs.getPutCount(), 1 ); assertEquals( slcs.getElementCountInMemory(), 1 ); assertEquals( slcs.getEntries().size(), 1 ); s = openSession(); t = s.beginTransaction(); i = (Item) s.get( Item.class, i.getId() ); assertEquals( slcs.getHitCount(), 1 ); assertEquals( slcs.getMissCount(), 0 ); i.setDescription("A bog standard item"); t.commit(); s.close(); assertEquals( slcs.getPutCount(), 2 ); Object entry = slcs.getEntries().get( i.getId() ); Map map; if ( entry instanceof ReadWriteCache.Item ) { map = (Map) ( (ReadWriteCache.Item) entry ).getValue(); } else { map = (Map) entry; } assertTrue( map.get("description").equals("A bog standard item") ); assertTrue( map.get("name").equals("widget") ); // cleanup s = openSession(); t = s.beginTransaction(); s.delete( i ); t.commit(); s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/AbstractQueryCacheFunctionalTestCase.java File path: /hibernate-distribution-3.3.2.GA/project/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java
Method name: void testQueryCacheInvalidation() Method name: void testQueryCacheInvalidation()
Number of AST nodes: 33 Number of AST nodes: 33
1
Session s = openSession();
1
Session s = openSession();
2
        
3
Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
4
        
5
Item i = new Item();
3
		Item i = new Item();
6
        
7
i.setName("widget");
4
		i.setName("widget");
8
        
9
i.setDescription("A really top-quality, full-featured widget.");
5
		i.setDescription("A really top-quality, full-featured widget.");
10
        
11
s.persist(i);
6
		s.persist(i);
12
        
13
t.commit();
7
		t.commit();
14
        s.close();
15
        
8
		s.close();
16
SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics()
9
		SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics()
17
.getSecondLevelCacheStatistics(
10
				.getSecondLevelCacheStatistics(
18
              getPrefixedRegionName(Item.class.getName()));
11
 Item.class.getName() );
19
        
20
assertEquals(slcs.getPutCount(), 1);
12
		assertEquals( slcs.getPutCount(), 1 );
21
        
22
assertEquals(slcs.getElementCountInMemory(), 1);
13
		assertEquals( slcs.getElementCountInMemory(), 1 );
23
        
24
assertEquals(slcs.getEntries().size(), 1);
14
		assertEquals( slcs.getEntries().size(), 1 );
25
        
26
s = openSession();
15
		s = openSession();
27
        
28
t = s.beginTransaction();
16
		t = s.beginTransaction();
29
        
30
i = (Item) s.get(Item.class, i.getId());
17
		i = (Item) s.get( Item.class, i.getId() );
31
        
32
assertEquals(slcs.getHitCount(), 1);
18
		assertEquals( slcs.getHitCount(), 1 );
33
        
34
assertEquals(slcs.getMissCount(), 0);
19
		assertEquals( slcs.getMissCount(), 0 );
35
        
36
i.setDescription("A bog standard item");
20
		i.setDescription("A bog standard item");
37
        
38
t.commit();
21
		t.commit();
39
        s.close();
40
        
22
		s.close();
41
assertEquals(slcs.getPutCount(), 2);
23
		assertEquals( slcs.getPutCount(), 2 );
42
        
43
Object entry = slcs.getEntries().get(i.getId());
24
		Object entry = slcs.getEntries().get( i.getId() );
44
        Map map;
45
        
25
		Map map;
46
if (entry instanceof ReadWriteCache.Item) {
26
		if ( entry instanceof ReadWriteCache.Item ) {
47
            
48
map = (Map) ((ReadWriteCache.Item) entry).getValue();
27
			map = (Map) ( (ReadWriteCache.Item) entry ).getValue();
49
        } else {
50
            map = (Map) entry;
51
        }
52
        
28
		}
29
		else {
30
			map = (Map) entry;
31
		}
53
assertTrue(map.get("description").equals("A bog standard item"));
32
		assertTrue( map.get("description").equals("A bog standard item") );
54
        
55
assertTrue(map.get("name").equals("widget"));
33
		assertTrue( map.get("name").equals("widget") );
56
        // cleanup
57
        
34
		// cleanup
58
s = openSession();
35
		s = openSession();
59
        
60
t = s.beginTransaction();
36
		t = s.beginTransaction();
61
        
62
s.delete(i);
37
		s.delete(
63
        
38
 i );
64
t.commit();
39
		t.commit();
65
        
66
s.close();
40
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.2
Clones locationClones are in different classes having the same super class
Number of node comparisons329
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements31
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)27.6
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
                                              
    3
    Item i = new Item();
    3
    Item i = new Item();
                                              
    4
    i.setName("widget");
    4
    i.setName("widget");
    4
    i.setName("widget");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.Itemorg.hibernate.test.cache.ItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    • Make classes org.hibernate.test.cache.jbc2.functional.Item and org.hibernate.test.cache.Item extend a common superclass
    4
    i.setName("widget");
    5
    i.setDescription("A really top-quality, full-featured widget.");
    5
    i.setDescription("A really top-quality, full-featured widget.");
    5
    i.setDescription("A really top-quality, full-featured widget.");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.Itemorg.hibernate.test.cache.ItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    • Make classes org.hibernate.test.cache.jbc2.functional.Item and org.hibernate.test.cache.Item extend a common superclass
    5
    i.setDescription("A really top-quality, full-featured widget.");
    6
    s.persist(i);
    6
    s.persist(i);
    6
    s.persist(i);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.Itemorg.hibernate.test.cache.ItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    • Make classes org.hibernate.test.cache.jbc2.functional.Item and org.hibernate.test.cache.Item extend a common superclass
    6
    s.persist(i);
    7
    t.commit();
    7
    t.commit();
    8
    s.close();
    8
    s.close();
    9
    SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(getPrefixedRegionName(Item.class.getName()));
    9
    SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(getPrefixedRegionName(Item.class.getName()));
    9
    SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(Item.class.getName());
    Differences
    Expression1Expression2Difference
    getPrefixedRegionNamegetNameMETHOD_INVOCATION_NAME_MISMATCH
    getPrefixedRegionName(Item.class.getName())Item.class.getName()ARGUMENT_NUMBER_MISMATCH
    Item.classMISSING_METHOD_INVOCATION_EXPRESSION
    9
    SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(Item.class.getName());
    10
    assertEquals(slcs.getPutCount(), 1);
    10
    assertEquals(slcs.getPutCount(), 1);
    11
    assertEquals(slcs.getElementCountInMemory(), 1);
    11
    assertEquals(slcs.getElementCountInMemory(), 1);
    12
    assertEquals(slcs.getEntries().size(), 1);
    12
    assertEquals(slcs.getEntries().size(), 1);
    13
    s = openSession();
    13
    s = openSession();
    14
    t = s.beginTransaction();
    14
    t = s.beginTransaction();
                                                                                    
    15
    i = (Item)s.get(Item.class, i.getId());
    Preondition Violations
    Unmatched statement i=(Item)s.get(Item.class,i.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    i = (Item)s.get(Item.class, i.getId());
    15
    i = (Item)s.get(Item.class, i.getId());
    15
    i = (Item)s.get(Item.class, i.getId());
    Preondition Violations
    Unmatched statement i=(Item)s.get(Item.class,i.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                    
    16
    assertEquals(slcs.getHitCount(), 1);
    16
    assertEquals(slcs.getHitCount(), 1);
    17
    assertEquals(slcs.getMissCount(), 0);
    17
    assertEquals(slcs.getMissCount(), 0);
    18
    i.setDescription("A bog standard item");
    18
    i.setDescription("A bog standard item");
    18
    i.setDescription("A bog standard item");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.Itemorg.hibernate.test.cache.ItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    • Make classes org.hibernate.test.cache.jbc2.functional.Item and org.hibernate.test.cache.Item extend a common superclass
    18
    i.setDescription("A bog standard item");
    19
    t.commit();
    19
    t.commit();
    20
    s.close();
    20
    s.close();
    21
    assertEquals(slcs.getPutCount(), 2);
    21
    assertEquals(slcs.getPutCount(), 2);
    22
    Object entry = slcs.getEntries().get(i.getId());
    22
    Object entry = slcs.getEntries().get(i.getId());
    22
    Object entry = slcs.getEntries().get(i.getId());
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.Itemorg.hibernate.test.cache.ItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    • Make classes org.hibernate.test.cache.jbc2.functional.Item and org.hibernate.test.cache.Item extend a common superclass
    22
    Object entry = slcs.getEntries().get(i.getId());
    23
    Map map;
    23
    Map map;
    24
    if (entry instanceof ReadWriteCache.Item)
    24
    if (entry instanceof ReadWriteCache.Item)
    25
    map = (Map)((ReadWriteCache.Item)entry).getValue();
    25
    map = (Map)((ReadWriteCache.Item)entry).getValue();
    else
    else
    26
    map = (Map)entry;
    26
    map = (Map)entry;
    27
    assertTrue(map.get("description").equals("A bog standard item"));
    27
    assertTrue(map.get("description").equals("A bog standard item"));
    28
    assertTrue(map.get("name").equals("widget"));
    28
    assertTrue(map.get("name").equals("widget"));
    29
    s = openSession();
    29
    s = openSession();
    30
    t = s.beginTransaction();
    30
    t = s.beginTransaction();
    31
    s.delete(i);
    31
    s.delete(i);
    31
    s.delete(i);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.Itemorg.hibernate.test.cache.ItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    • Make classes org.hibernate.test.cache.jbc2.functional.Item and org.hibernate.test.cache.Item extend a common superclass
    31
    s.delete(i);
    32
    t.commit();
    32
    t.commit();
    33
    s.close();
    33
    s.close();
    Precondition Violations (8)
    Row Violation
    1Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    2Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    3Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    4Unmatched statement i=(Item)s.get(Item.class,i.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement i=(Item)s.get(Item.class,i.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    7Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i
    8Type org.hibernate.test.cache.jbc2.functional.Item of variable i does not match with type org.hibernate.test.cache.Item of variable i