Session s = openSession(); Transaction txn = s.beginTransaction(); VersionedItem item = new VersionedItem(); item.setName("steve"); item.setDescription("steve's item"); s.save(item); txn.commit(); s.close(); Long initialVersion = item.getVersion(); // manually revert the version property item.setVersion(new Long(item.getVersion().longValue() - 1)); try { s = openSession(); txn = s.beginTransaction(); s.update(item); txn.commit(); s.close(); fail("expected stale write to fail"); } catch (Throwable expected) { // expected behavior here if (txn != null) { try { txn.rollback(); } catch (Throwable ignore) { } } } finally { if (s != null && s.isOpen()) { try { s.close(); } catch (Throwable ignore) { } } } // check the version value in the cache... SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics( getPrefixedRegionName(VersionedItem.class.getName())); Object entry = slcs.getEntries().get(item.getId()); Long cachedVersionValue; if (entry instanceof ReadWriteCache.Lock) { // FIXME don't know what to test here cachedVersionValue = new Long(((ReadWriteCache.Lock) entry).getUnlockTimestamp()); } else { cachedVersionValue = (Long) ((Map) entry).get("_version"); assertEquals(initialVersion.longValue(), cachedVersionValue.longValue()); } // cleanup s = openSession(); txn = s.beginTransaction(); item = (VersionedItem) s.load(VersionedItem.class, item.getId()); s.delete(item); txn.commit(); s.close();
Session s = openSession(); Transaction txn = s.beginTransaction(); VersionedItem item = new VersionedItem(); item.setName( "steve" ); item.setDescription( "steve's item" ); s.save( item ); txn.commit(); s.close(); Long initialVersion = item.getVersion(); // manually revert the version property item.setVersion( new Long( item.getVersion().longValue() - 1 ) ); try { s = openSession(); txn = s.beginTransaction(); s.update( item ); txn.commit(); s.close(); fail( "expected stale write to fail" ); } catch( Throwable expected ) { // expected behavior here if ( txn != null ) { try { txn.rollback(); } catch( Throwable ignore ) { } } } finally { if ( s != null && s.isOpen() ) { try { s.close(); } catch( Throwable ignore ) { } } } // check the version value in the cache... SecondLevelCacheStatistics slcs = sfi().getStatistics() .getSecondLevelCacheStatistics( VersionedItem.class.getName() ); Object entry = slcs.getEntries().get( item.getId() ); Long cachedVersionValue; if ( entry instanceof ReadWriteCache.Lock ) { //FIXME don't know what to test here cachedVersionValue = new Long( ( (ReadWriteCache.Lock) entry).getUnlockTimestamp() ); } else { cachedVersionValue = ( Long ) ( (Map) entry ).get( "_version" ); assertEquals( initialVersion.longValue(), cachedVersionValue.longValue() ); } // cleanup s = openSession(); txn = s.beginTransaction(); item = ( VersionedItem ) s.load( VersionedItem.class, item.getId() ); s.delete( item ); txn.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/AbstractEntityCacheFunctionalTestCase.java File path: /hibernate-distribution-3.3.2.GA/project/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java
Method name: void testStaleWritesLeaveCacheConsistent() Method name: void testStaleWritesLeaveCacheConsistent()
Number of AST nodes: 30 Number of AST nodes: 30
1
Session s = openSession();
1
Session s = openSession();
2
        Transaction txn = s.beginTransaction();
2
		Transaction txn = s.beginTransaction();
3
        VersionedItem item = new VersionedItem();
3
		VersionedItem item = new VersionedItem();
4
        item.setName("steve");
4
		item.setName( "steve" );
5
        item.setDescription("steve's item");
5
		item.setDescription( "steve's item" );
6
        s.save(item);
6
		s.save( item );
7
        txn.commit();
7
		txn.commit();
8
        s.close();
8
		s.close();
9
        Long initialVersion = item.getVersion();
9
		Long initialVersion = item.getVersion();
10
        // manually revert the version property
10
		// manually revert the version property
11
        item.setVersion(new Long(item.getVersion().longValue() - 1));
11
		item.setVersion( new Long( item.getVersion().longValue() - 1 ) );
12
        try {
13
            
12
		try {
14
s = openSession();
13
			s = openSession();
15
            txn = s.beginTransaction();
14
			txn = s.beginTransaction();
16
            s.update(item);
15
			s.update( item );
17
            txn.commit();
16
			txn.commit();
18
            s.close();
19
            
17
			s.close();
20
fail("expected stale write to fail");
18
			fail( "expected stale write to fail" );
21
        } 
19
		}
22
catch (Throwable expected) {
20
		catch( Throwable expected ) {
23
            // expected behavior here
21
			// expected behavior here
24
            if (txn != null) {
22
			if ( txn != null ) {
25
                try {
26
                    txn.rollback();
27
                } 
23
				try {
24
					txn.rollback();
25
				}
28
catch (Throwable ignore) {
26
				catch( Throwable ignore ) {
29
                }
30
            }
31
        } finally {
32
            
27
				}
28
			}
29
		}
30
		finally {
33
if (s != null && s.isOpen()) {
31
			if ( s != null && s.isOpen() ) {
34
                try {
35
                    s.close();
36
                } 
32
				try {
33
					s.close();
34
				}
37
catch (Throwable ignore) {
35
				catch( Throwable ignore ) {
38
                }
39
            }
40
        }
41
        
36
				}
37
			}
38
		}
42
// check the version value in the cache...
39
		// check the version value in the cache...
43
        SecondLevelCacheStatistics slcs = sfi().getStatistics()
40
		SecondLevelCacheStatistics slcs = sfi().getStatistics()
44
.getSecondLevelCacheStatistics(
41
				.getSecondLevelCacheStatistics(
45
              getPrefixedRegionName(VersionedItem.class.getName()));
42
 VersionedItem.class.getName() );
46
        Object entry = slcs.getEntries().get(item.getId());
43
		Object entry = slcs.getEntries().get( item.getId() );
47
        Long cachedVersionValue;
44
		Long cachedVersionValue;
48
        if (entry instanceof ReadWriteCache.Lock) {
45
		if ( entry instanceof ReadWriteCache.Lock ) {
49
            // FIXME don't know what to test here
46
			//FIXME don't know what to test here
50
            cachedVersionValue = new Long(((ReadWriteCache.Lock) entry).getUnlockTimestamp());
47
			cachedVersionValue = new Long( ( (ReadWriteCache.Lock) entry).getUnlockTimestamp() );
51
        } else {
52
            
48
		}
49
		else {
53
cachedVersionValue = (Long) ((Map) entry).get("_version");
50
			cachedVersionValue = ( Long ) ( (Map) entry ).get( "_version" );
54
            assertEquals(initialVersion.longValue(), cachedVersionValue.longValue());
51
			assertEquals( initialVersion.longValue(), cachedVersionValue.longValue() );
55
        }
56
        
52
		}
57
// cleanup
53
		// cleanup
58
        s = openSession();
54
		s = openSession();
59
        txn = s.beginTransaction();
55
		txn = s.beginTransaction();
60
        item = (VersionedItem) s.load(VersionedItem.class, item.getId());
56
		item = ( VersionedItem ) s.load( VersionedItem.class, item.getId() );
61
        s.delete(item);
57
		s.delete( item );
62
        txn.commit();
58
		txn.commit();
63
        s.close();
59
		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)1.3
Clones locationClones are in different classes having the same super class
Number of node comparisons255
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements28
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)24.2
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    Transaction txn = s.beginTransaction();
    2
    Transaction txn = s.beginTransaction();
                                                                                        
    3
    VersionedItem item = new VersionedItem();
    3
    VersionedItem item = new VersionedItem();
                                                                                        
    4
    item.setName("steve");
    4
    item.setName("steve");
    4
    item.setName("steve");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    4
    item.setName("steve");
    5
    item.setDescription("steve's item");
    5
    item.setDescription("steve's item");
    5
    item.setDescription("steve's item");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    5
    item.setDescription("steve's item");
    6
    s.save(item);
    6
    s.save(item);
    6
    s.save(item);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    6
    s.save(item);
    7
    txn.commit();
    7
    txn.commit();
    8
    s.close();
    8
    s.close();
    9
    Long initialVersion = item.getVersion();
    9
    Long initialVersion = item.getVersion();
    9
    Long initialVersion = item.getVersion();
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    9
    Long initialVersion = item.getVersion();
    10
    item.setVersion(new Long(item.getVersion().longValue() - 1));
    10
    item.setVersion(new Long(item.getVersion().longValue() - 1));
    10
    item.setVersion(new Long(item.getVersion().longValue() - 1));
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    10
    item.setVersion(new Long(item.getVersion().longValue() - 1));
    11
    try
    11
    try
    12
    s = openSession();
    12
    s = openSession();
    13
    txn = s.beginTransaction();
    13
    txn = s.beginTransaction();
    14
    s.update(item);
    14
    s.update(item);
    14
    s.update(item);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    14
    s.update(item);
    15
    txn.commit();
    15
    txn.commit();
    16
    s.close();
    16
    s.close();
    17
    fail("expected stale write to fail");
    17
    fail("expected stale write to fail");
    18
    SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(getPrefixedRegionName(VersionedItem.class.getName()));
    18
    SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(getPrefixedRegionName(VersionedItem.class.getName()));
    18
    SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(VersionedItem.class.getName());
    Differences
    Expression1Expression2Difference
    getPrefixedRegionNamegetNameMETHOD_INVOCATION_NAME_MISMATCH
    getPrefixedRegionName(VersionedItem.class.getName())VersionedItem.class.getName()ARGUMENT_NUMBER_MISMATCH
    VersionedItem.classMISSING_METHOD_INVOCATION_EXPRESSION
    18
    SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(VersionedItem.class.getName());
    19
    Object entry = slcs.getEntries().get(item.getId());
    19
    Object entry = slcs.getEntries().get(item.getId());
    19
    Object entry = slcs.getEntries().get(item.getId());
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    19
    Object entry = slcs.getEntries().get(item.getId());
    20
    Long cachedVersionValue;
    20
    Long cachedVersionValue;
    21
    if (entry instanceof ReadWriteCache.Lock)
    21
    if (entry instanceof ReadWriteCache.Lock)
    22
    cachedVersionValue = new Long(((ReadWriteCache.Lock)entry).getUnlockTimestamp());
    22
    cachedVersionValue = new Long(((ReadWriteCache.Lock)entry).getUnlockTimestamp());
    else
    else
    23
    cachedVersionValue = (Long)((Map)entry).get("_version");
    23
    cachedVersionValue = (Long)((Map)entry).get("_version");
    24
    assertEquals(initialVersion.longValue(), cachedVersionValue.longValue());
    24
    assertEquals(initialVersion.longValue(), cachedVersionValue.longValue());
    25
    s = openSession();
    25
    s = openSession();
    26
    txn = s.beginTransaction();
    26
    txn = s.beginTransaction();
                                                                                                                                      
    27
    item = (VersionedItem)s.load(VersionedItem.class, item.getId());
    Preondition Violations
    Unmatched statement item=(VersionedItem)s.load(VersionedItem.class,item.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27
    item = (VersionedItem)s.load(VersionedItem.class, item.getId());
    27
    item = (VersionedItem)s.load(VersionedItem.class, item.getId());
    27
    item = (VersionedItem)s.load(VersionedItem.class, item.getId());
    Preondition Violations
    Unmatched statement item=(VersionedItem)s.load(VersionedItem.class,item.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                      
    28
    s.delete(item);
    28
    s.delete(item);
    28
    s.delete(item);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.cache.jbc2.functional.VersionedItemorg.hibernate.test.cache.VersionedItemVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    • Make classes org.hibernate.test.cache.jbc2.functional.VersionedItem and org.hibernate.test.cache.VersionedItem extend a common superclass
    28
    s.delete(item);
    29
    txn.commit();
    29
    txn.commit();
    30
    s.close();
    30
    s.close();
    Precondition Violations (11)
    Row Violation
    1Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    2Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    3Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    4Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    5Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    6Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    7Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    8Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item
    9Unmatched statement item=(VersionedItem)s.load(VersionedItem.class,item.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement item=(VersionedItem)s.load(VersionedItem.class,item.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item