Session s = openSession(); s.beginTransaction(); VersionedNode child = new VersionedNode( "child", "child" ); s.persist( child ); s.getTransaction().commit(); s.close(); clearCounts(); child.setName( "new child name" ); VersionedNode parent = new VersionedNode( "parent", "parent"); parent.addChild( child ); s = openSession(); s.beginTransaction(); s.update( child ); s.setReadOnly( child, true ); s.getTransaction().commit(); s.close(); assertUpdateCount( 0 ); assertInsertCount( 1 ); s = openSession(); s.beginTransaction(); parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); assertEquals( child.getName(), "child" ); assertNull( child.getParent() ); assertEquals( 0, child.getVersion() ); assertNotNull( parent ); assertEquals( 0, parent.getChildren().size() ); assertEquals( 0, parent.getVersion() ); s.delete( parent ); s.delete( child ); s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); VersionedNode child = new VersionedNode( "child", "child" ); s.persist( child ); s.getTransaction().commit(); s.close(); clearCounts(); child.setName( "new child name" ); VersionedNode parent = new VersionedNode( "parent", "parent"); parent.addChild( child ); s = openSession(); s.beginTransaction(); child = ( VersionedNode ) s.merge( child ); s.setReadOnly( child, true ); s.getTransaction().commit(); s.close(); assertUpdateCount( 1 ); assertInsertCount( 1 ); s = openSession(); s.beginTransaction(); parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() ); child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() ); assertEquals( child.getName(), "child" ); assertNull( child.getParent() ); assertEquals( 0, child.getVersion() ); assertNotNull( parent ); assertEquals( 0, parent.getChildren().size() ); assertEquals( 1, parent.getVersion() ); // hmmm, why is was version updated? s.delete( parent ); s.delete( child ); s.getTransaction().commit(); s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java
Method name: void testUpdateChildWithNewParentCommitWithReadOnlyChild() Method name: void testMergeDetachedChildWithNewParentCommitWithReadOnlyChild()
Number of AST nodes: 32 Number of AST nodes: 32
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		VersionedNode child = new VersionedNode( "child", "child" );
3
		VersionedNode child = new VersionedNode( "child", "child" );
4
		s.persist( child );
4
		s.persist( child );
5
		s.getTransaction().commit();
5
		s.getTransaction().commit();
6
		s.close();
6
		s.close();
7
		clearCounts();
7
		clearCounts();
8
		child.setName( "new child name" );
8
		child.setName( "new child name" );
9
		VersionedNode parent = new VersionedNode( "parent", "parent");
9
		VersionedNode parent = new VersionedNode( "parent", "parent");
10
		parent.addChild( child );
10
		parent.addChild( child );
11
		s = openSession();
11
		s = openSession();
12
		s.beginTransaction();
12
		s.beginTransaction();
13
		s.update( child );
13
		child = ( VersionedNode ) s.merge( child );
14
		s.setReadOnly( child, true );
14
		s.setReadOnly( child, true );
15
		s.getTransaction().commit();
15
		s.getTransaction().commit();
16
		s.close();
16
		s.close();
17
		assertUpdateCount( 0 );
17
		assertUpdateCount( 1 );
18
		assertInsertCount( 1 );
18
		assertInsertCount( 1 );
19
		s = openSession();
19
		s = openSession();
20
		s.beginTransaction();
20
		s.beginTransaction();
21
		parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
21
		parent = ( VersionedNode ) s.get( VersionedNode.class, parent.getId() );
22
		child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
22
		child = ( VersionedNode ) s.get( VersionedNode.class, child.getId() );
23
		assertEquals( child.getName(), "child" );
23
		assertEquals( child.getName(), "child" );
24
		assertNull( child.getParent() );
24
		assertNull( child.getParent() );
25
		assertEquals( 0, child.getVersion() );
25
		assertEquals( 0, child.getVersion() );
26
		assertNotNull( parent );
26
		assertNotNull( parent );
27
		assertEquals( 0, parent.getChildren().size() );
27
		assertEquals( 0, parent.getChildren().size() );
28
		assertEquals( 0, parent.getVersion() );
28
		assertEquals( 1, parent.getVersion() );	// hmmm, why is was version updated?
29
		s.delete( parent );
29
		s.delete( parent );
30
		s.delete( child );
30
		s.delete( child );
31
		s.getTransaction().commit();
31
		s.getTransaction().commit();
32
		s.close();
32
		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.0
Clones locationClones are declared in the same class
Number of node comparisons330
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements28
    Number of unmapped statements in the first code fragment4
    Number of unmapped statements in the second code fragment4
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    3
    VersionedNode child = new VersionedNode("child", "child");
    3
    VersionedNode child = new VersionedNode("child", "child");
    4
    s.persist(child);
    4
    s.persist(child);
    5
    s.getTransaction().commit();
    5
    s.getTransaction().commit();
    6
    s.close();
    6
    s.close();
    7
    clearCounts();
    7
    clearCounts();
    8
    child.setName("new child name");
    8
    child.setName("new child name");
    9
    VersionedNode parent = new VersionedNode("parent", "parent");
    9
    VersionedNode parent = new VersionedNode("parent", "parent");
    10
    parent.addChild(child);
    10
    parent.addChild(child);
    11
    s = openSession();
    11
    s = openSession();
    12
    s.beginTransaction();
    12
    s.beginTransaction();
    13
    s.update(child);
    13
    s.update(child);
    30
    s.delete(child);
    Differences
    Expression1Expression2Difference
    updatedeleteMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression s.update(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.update(child) is a void method call, and thus it cannot be parameterized
    Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    30
    s.delete(child);
    14
    s.setReadOnly(child, true);
    14
    s.setReadOnly(child, true);
    Preondition Violations
    Unmatched statement s.setReadOnly(child,true); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                
    15
    s.getTransaction().commit();
    15
    s.getTransaction().commit();
    16
    s.close();
    16
    s.close();
    17
    assertUpdateCount(0);
    17
    assertUpdateCount(0);
    17
    assertUpdateCount(1);
    Differences
    Expression1Expression2Difference
    01LITERAL_VALUE_MISMATCH
    17
    assertUpdateCount(1);
    18
    assertInsertCount(1);
    18
    assertInsertCount(1);
    19
    s = openSession();
    19
    s = openSession();
    20
    s.beginTransaction();
    20
    s.beginTransaction();
    21
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    21
    parent = (VersionedNode)s.get(VersionedNode.class, parent.getId());
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    13
    child = (VersionedNode)s.merge(child);
    Differences
    Expression1Expression2Difference
    getmergeMETHOD_INVOCATION_NAME_MISMATCH
    s.get(VersionedNode.class,child.getId())s.merge(child)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.get(VersionedNode.class,child.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.get(VersionedNode.class,child.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    child = (VersionedNode)s.merge(child);
                                                                                                                                        
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
    Preondition Violations
    Unmatched statement child=(VersionedNode)s.get(VersionedNode.class,child.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22
    child = (VersionedNode)s.get(VersionedNode.class, child.getId());
                                                                                        
    23
    assertEquals(child.getName(), "child");
    Preondition Violations
    Unmatched statement assertEquals(child.getName(),"child"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23
    assertEquals(child.getName(), "child");
    23
    assertEquals(child.getName(), "child");
    23
    assertEquals(child.getName(), "child");
    Preondition Violations
    Unmatched statement assertEquals(child.getName(),"child"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                        
                                                                        
    24
    assertNull(child.getParent());
    Preondition Violations
    Unmatched statement assertNull(child.getParent()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24
    assertNull(child.getParent());
    24
    assertNull(child.getParent());
    24
    assertNull(child.getParent());
    Preondition Violations
    Unmatched statement assertNull(child.getParent()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                        
                                                                                  
    25
    assertEquals(0, child.getVersion());
    25
    assertEquals(0, child.getVersion());
    25
    assertEquals(0, child.getVersion());
    Preondition Violations
    Unmatched statement assertEquals(0,child.getVersion()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                  
    26
    assertNotNull(parent);
    26
    assertNotNull(parent);
    27
    assertEquals(0, parent.getChildren().size());
    27
    assertEquals(0, parent.getChildren().size());
    28
    assertEquals(0, parent.getVersion());
    28
    assertEquals(0, parent.getVersion());
    28
    assertEquals(1, parent.getVersion());
    Differences
    Expression1Expression2Difference
    01LITERAL_VALUE_MISMATCH
    28
    assertEquals(1, parent.getVersion());
    29
    s.delete(parent);
    29
    s.delete(parent);
    30
    s.delete(child);
    30
    s.delete(child);
    14
    s.setReadOnly(child, true);
    Differences
    Expression1Expression2Difference
    deletesetReadOnlyMETHOD_INVOCATION_NAME_MISMATCH
    s.delete(child)s.setReadOnly(child,true)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    14
    s.setReadOnly(child, true);
    31
    s.getTransaction().commit();
    31
    s.getTransaction().commit();
    32
    s.close();
    32
    s.close();
    Precondition Violations (24)
    Row Violation
    1Expression s.update(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression s.update(child) is a void method call, and thus it cannot be parameterized
    4Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    5Unmatched statement s.setReadOnly(child,true); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Expression s.get(VersionedNode.class,child.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression s.get(VersionedNode.class,child.getId()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression s.merge(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Unmatched statement child=(VersionedNode)s.get(VersionedNode.class,child.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement assertEquals(child.getName(),"child"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement assertEquals(child.getName(),"child"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Unmatched statement assertNull(child.getParent()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Unmatched statement assertNull(child.getParent()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement assertEquals(0,child.getVersion()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    19Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    20Expression s.delete(child) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression s.setReadOnly(child,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression s.delete(child) is a void method call, and thus it cannot be parameterized
    23Expression s.setReadOnly(child,true) is a void method call, and thus it cannot be parameterized
    24Clone fragment #1 returns variables child , while Clone fragment #2 returns variables child, s