try { doc.setSummary( "A machiavelian achievement of epic proportions" ); mainSession.flush(); fail( "expecting opt lock failure" ); } catch ( StaleObjectStateException expected ) { // expected result... } catch( StaleStateException expected ) { // expected result (if using versioned batching)... } catch( JDBCException e ) { // SQLServer will report this condition via a SQLException // when using its SNAPSHOT transaction isolation... if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) { throw e; } else { // it seems to "lose track" of the transaction as well... mainSession.getTransaction().rollback(); mainSession.beginTransaction(); } }
try { mainSession.delete( doc ); mainSession.flush(); fail( "expecting opt lock failure" ); } catch ( StaleObjectStateException e ) { // expected } catch( StaleStateException expected ) { // expected result (if using versioned batching)... } catch( JDBCException e ) { // SQLServer will report this condition via a SQLException // when using its SNAPSHOT transaction isolation... if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) { throw e; } else { // it seems to "lose track" of the transaction as well... mainSession.getTransaction().rollback(); mainSession.beginTransaction(); } }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/optlock/OptimisticLockTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/optlock/OptimisticLockTest.java
Method name: void testUpdateOptimisticLockFailure(String) Method name: void testDeleteOptimisticLockFailure(String)
Number of AST nodes: 4 Number of AST nodes: 4
1
try {
1
try {
2
			doc.setSummary( "A machiavelian achievement of epic proportions" );
2
			mainSession.delete( doc );
3
			mainSession.flush();
3
			mainSession.flush();
4
			fail( "expecting opt lock failure" );
4
			fail( "expecting opt lock failure" );
5
		}
5
		}
6
		catch ( StaleObjectStateException expected ) {
6
		catch ( StaleObjectStateException e ) {
7
			// expected result...
7
			// expected
8
		}
8
		}
9
		catch( StaleStateException expected ) {
9
		catch( StaleStateException expected ) {
10
			// expected result (if using versioned batching)...
10
			// expected result (if using versioned batching)...
11
		}
11
		}
12
		catch( JDBCException e ) {
12
		catch( JDBCException e ) {
13
			// SQLServer will report this condition via a SQLException
13
			// SQLServer will report this condition via a SQLException
14
			// when using its SNAPSHOT transaction isolation...
14
			// when using its SNAPSHOT transaction isolation...
15
			if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
15
			if ( ! ( getDialect() instanceof SQLServerDialect && e.getErrorCode() == 3960 ) ) {
16
				throw e;
16
				throw e;
17
			}
17
			}
18
			else {
18
			else {
19
				// it seems to "lose track" of the transaction as well...
19
				// it seems to "lose track" of the transaction as well...
20
				mainSession.getTransaction().rollback();
20
				mainSession.getTransaction().rollback();
21
				mainSession.beginTransaction();
21
				mainSession.beginTransaction();
22
			}
22
			}
23
		}
23
		}
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.8
Clones locationClones are declared in the same class
Number of node comparisons16
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)18.9
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    24
    try
    24
    try
    30
    try
    Differences
    Expression1Expression2Difference
    expectedeVARIABLE_NAME_MISMATCH
    30
    try
    25
    doc.setSummary("A machiavelian achievement of epic proportions");
    25
    doc.setSummary("A machiavelian achievement of epic proportions");
    Preondition Violations
    Unmatched statement doc.setSummary("A machiavelian achievement of epic proportions"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                                              
                                                            
    31
    mainSession.delete(doc);
    Preondition Violations
    Unmatched statement mainSession.delete(doc); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    31
    mainSession.delete(doc);
    26
    mainSession.flush();
    32
    mainSession.flush();
    27
    fail("expecting opt lock failure");
    33
    fail("expecting opt lock failure");
    Precondition Violations (2)
    Row Violation
    1Unmatched statement doc.setSummary("A machiavelian achievement of epic proportions"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement mainSession.delete(doc); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted