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.6
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)1.2
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    24
    try
    24
    try
    30
    try
    Differences
    Expression1Expression2Difference
    expectedeVARIABLE_NAME_MISMATCH
    30
    try
                                                            
    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);
    25
    doc.setSummary("A machiavelian achievement of epic proportions");
    25
    doc.setSummary("A machiavelian achievement of epic proportions");
    33
    fail("expecting opt lock failure");
    Differences
    Expression1Expression2Difference
    setSummaryfailMETHOD_INVOCATION_NAME_MISMATCH
    "A machiavelian achievement of epic proportions""expecting opt lock failure"LITERAL_VALUE_MISMATCH
    docMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression doc.setSummary("A machiavelian achievement of epic proportions") is a void method call, and thus it cannot be parameterized
    Expression fail("expecting opt lock failure") is a void method call, and thus it cannot be parameterized
    Expression doc.setSummary("A machiavelian achievement of epic proportions") is a void method call, and thus it cannot be parameterized
    Expression fail("expecting opt lock failure") is a void method call, and thus it cannot be parameterized
    33
    fail("expecting opt lock failure");
    26
    mainSession.flush();
    32
    mainSession.flush();
    27
    fail("expecting opt lock failure");
                                                                                  
    Precondition Violations (5)
    Row Violation
    1Unmatched 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
    2Expression doc.setSummary("A machiavelian achievement of epic proportions") is a void method call, and thus it cannot be parameterized
    3Expression fail("expecting opt lock failure") is a void method call, and thus it cannot be parameterized
    4Expression doc.setSummary("A machiavelian achievement of epic proportions") is a void method call, and thus it cannot be parameterized
    5Expression fail("expecting opt lock failure") is a void method call, and thus it cannot be parameterized