clearCounts(); Session s = openSession(); Transaction tx = s.beginTransaction(); NumberedNode root = new NumberedNode("root"); NumberedNode child = new NumberedNode("child"); NumberedNode grandchild = new NumberedNode("grandchild"); root.addChild(child); child.addChild(grandchild); root = (NumberedNode) s.merge(root); tx.commit(); s.close(); assertInsertCount(3); assertUpdateCount(0); clearCounts(); child = (NumberedNode) root.getChildren().iterator().next(); grandchild = (NumberedNode) child.getChildren().iterator().next(); grandchild.setDescription("the grand child"); NumberedNode grandchild2 = new NumberedNode("grandchild2"); child.addChild( grandchild2 ); s = openSession(); tx = s.beginTransaction(); root = (NumberedNode) s.merge(root); tx.commit(); s.close(); assertInsertCount(1); assertUpdateCount(1); clearCounts(); getSessions().evict(NumberedNode.class); NumberedNode child2 = new NumberedNode("child2"); NumberedNode grandchild3 = new NumberedNode("grandchild3"); child2.addChild( grandchild3 ); root.addChild(child2); s = openSession(); tx = s.beginTransaction(); root = (NumberedNode) s.merge(root); tx.commit(); s.close(); assertInsertCount(2); assertUpdateCount(0); clearCounts(); s = openSession(); tx = s.beginTransaction(); s.createQuery("delete from NumberedNode where name like 'grand%'").executeUpdate(); s.createQuery("delete from NumberedNode where name like 'child%'").executeUpdate(); s.createQuery("delete from NumberedNode").executeUpdate(); tx.commit(); s.close();
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() ); clearCounts(); Session s = openSession(); Transaction tx = s.beginTransaction(); NumberedNode root = new NumberedNode( "root" ); NumberedNode child = new NumberedNode( "child" ); NumberedNode grandchild = new NumberedNode( "grandchild" ); root.addChild( child ); child.addChild( grandchild ); s.saveOrUpdate( root ); tx.commit(); s.close(); assertInsertCount( 3 ); assertUpdateCount( 0 ); clearCounts(); child = ( NumberedNode ) root.getChildren().iterator().next(); grandchild = ( NumberedNode ) child.getChildren().iterator().next(); grandchild.setDescription( "the grand child" ); NumberedNode grandchild2 = new NumberedNode( "grandchild2" ); child.addChild( grandchild2 ); s = openSession(); tx = s.beginTransaction(); s.saveOrUpdate( root ); tx.commit(); s.close(); assertInsertCount( 1 ); assertUpdateCount( instrumented ? 1 : 3 ); clearCounts(); NumberedNode child2 = new NumberedNode( "child2" ); NumberedNode grandchild3 = new NumberedNode( "grandchild3" ); child2.addChild( grandchild3 ); root.addChild( child2 ); s = openSession(); tx = s.beginTransaction(); s.saveOrUpdate( root ); tx.commit(); s.close(); assertInsertCount( 2 ); assertUpdateCount( instrumented ? 0 : 4 ); clearCounts(); s = openSession(); tx = s.beginTransaction(); s.createQuery( "delete from NumberedNode where name like 'grand%'" ).executeUpdate(); s.createQuery( "delete from NumberedNode where name like 'child%'" ).executeUpdate(); s.createQuery( "delete from NumberedNode" ).executeUpdate(); tx.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/ops/MergeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/ops/SaveOrUpdateTest.java
Method name: void testMergeDeepTreeWithGeneratedId() Method name: void testSaveOrUpdateDeepTreeWithGeneratedId()
Number of AST nodes: 47 Number of AST nodes: 47
1
boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );
1
clearCounts();
2
		clearCounts();
2
		Session s = openSession();
3
		Session s = openSession();
3
		Transaction tx = s.beginTransaction();
4
		Transaction tx = s.beginTransaction();
4
		NumberedNode root = new NumberedNode("root");
5
		NumberedNode root = new NumberedNode( "root" );
5
		NumberedNode child = new NumberedNode("child");
6
		NumberedNode child = new NumberedNode( "child" );
6
		NumberedNode grandchild = new NumberedNode("grandchild");
7
		NumberedNode grandchild = new NumberedNode( "grandchild" );
7
		root.addChild(child);
8
		root.addChild( child );
8
		child.addChild(grandchild);
9
		child.addChild( grandchild );
9
		root = (NumberedNode) s.merge(root);
10
		s.saveOrUpdate( root );
10
		tx.commit();
11
		tx.commit();
11
		s.close();
12
		s.close();
12
		assertInsertCount(3);
13
		assertInsertCount( 3 );
13
		assertUpdateCount(0);
14
		assertUpdateCount( 0 );
14
		clearCounts();
15
		clearCounts();
15
		child = (NumberedNode) root.getChildren().iterator().next();
16
		child = ( NumberedNode ) root.getChildren().iterator().next();
16
		grandchild = (NumberedNode) child.getChildren().iterator().next();
17
		grandchild = ( NumberedNode ) child.getChildren().iterator().next();
17
		grandchild.setDescription("the grand child");
18
		grandchild.setDescription( "the grand child" );
18
		NumberedNode grandchild2 = new NumberedNode("grandchild2");
19
		NumberedNode grandchild2 = new NumberedNode( "grandchild2" );
19
		child.addChild( grandchild2 );
20
		child.addChild( grandchild2 );
20
		s = openSession();
21
		s = openSession();
21
		tx = s.beginTransaction();
22
		tx = s.beginTransaction();
22
		root = (NumberedNode) s.merge(root);
23
		s.saveOrUpdate( root );
23
		tx.commit();
24
		tx.commit();
24
		s.close();
25
		s.close();
25
		assertInsertCount(1);
26
		assertInsertCount( 1 );
26
		assertUpdateCount(1);
27
		assertUpdateCount( instrumented ? 1 : 3 );
27
		clearCounts();
28
		clearCounts();
28
		getSessions().evict(NumberedNode.class);
29
		NumberedNode child2 = new NumberedNode("child2");
29
		NumberedNode child2 = new NumberedNode( "child2" );
30
		NumberedNode grandchild3 = new NumberedNode("grandchild3");
30
		NumberedNode grandchild3 = new NumberedNode( "grandchild3" );
31
		child2.addChild( grandchild3 );
31
		child2.addChild( grandchild3 );
32
		root.addChild(child2);
32
		root.addChild( child2 );
33
		s = openSession();
33
		s = openSession();
34
		tx = s.beginTransaction();
34
		tx = s.beginTransaction();
35
		root = (NumberedNode) s.merge(root);
35
		s.saveOrUpdate( root );
36
		tx.commit();
36
		tx.commit();
37
		s.close();
37
		s.close();
38
		assertInsertCount(2);
38
		assertInsertCount( 2 );
39
		assertUpdateCount(0);
39
		assertUpdateCount( instrumented ? 0 : 4 );
40
		clearCounts();
40
		clearCounts();
41
		s = openSession();
41
		s = openSession();
42
		tx = s.beginTransaction();
42
		tx = s.beginTransaction();
43
		s.createQuery("delete from NumberedNode where name like 'grand%'").executeUpdate();
43
		s.createQuery( "delete from NumberedNode where name like 'grand%'" ).executeUpdate();
44
		s.createQuery("delete from NumberedNode where name like 'child%'").executeUpdate();
44
		s.createQuery( "delete from NumberedNode where name like 'child%'" ).executeUpdate();
45
		s.createQuery("delete from NumberedNode").executeUpdate();
45
		s.createQuery( "delete from NumberedNode" ).executeUpdate();
46
		tx.commit();
46
		tx.commit();
47
		s.close();
47
		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 in different classes having the same super class
Number of node comparisons476
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements42
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
                                                                                                                                                                          
    1
    boolean instrumented = FieldInterceptionHelper.isInstrumented(new NumberedNode());
    1
    clearCounts();
    2
    clearCounts();
    2
    Session s = openSession();
    3
    Session s = openSession();
    3
    Transaction tx = s.beginTransaction();
    4
    Transaction tx = s.beginTransaction();
    4
    NumberedNode root = new NumberedNode("root");
    5
    NumberedNode root = new NumberedNode("root");
    5
    NumberedNode child = new NumberedNode("child");
    6
    NumberedNode child = new NumberedNode("child");
    6
    NumberedNode grandchild = new NumberedNode("grandchild");
    7
    NumberedNode grandchild = new NumberedNode("grandchild");
    7
    root.addChild(child);
    8
    root.addChild(child);
    8
    child.addChild(grandchild);
    9
    child.addChild(grandchild);
    9
    root = (NumberedNode)s.merge(root);
    9
    root = (NumberedNode)s.merge(root);
    Preondition Violations
    Unmatched statement root=(NumberedNode)s.merge(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                            
                                                      
    10
    s.saveOrUpdate(root);
    Preondition Violations
    Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    s.saveOrUpdate(root);
    10
    tx.commit();
    11
    tx.commit();
    11
    s.close();
    12
    s.close();
    12
    assertInsertCount(3);
    13
    assertInsertCount(3);
    13
    assertUpdateCount(0);
    14
    assertUpdateCount(0);
    14
    clearCounts();
    15
    clearCounts();
    15
    child = (NumberedNode)root.getChildren().iterator().next();
    16
    child = (NumberedNode)root.getChildren().iterator().next();
    16
    grandchild = (NumberedNode)child.getChildren().iterator().next();
    17
    grandchild = (NumberedNode)child.getChildren().iterator().next();
    17
    grandchild.setDescription("the grand child");
    18
    grandchild.setDescription("the grand child");
    18
    NumberedNode grandchild2 = new NumberedNode("grandchild2");
    19
    NumberedNode grandchild2 = new NumberedNode("grandchild2");
    19
    child.addChild(grandchild2);
    20
    child.addChild(grandchild2);
    20
    s = openSession();
    21
    s = openSession();
    21
    tx = s.beginTransaction();
    22
    tx = s.beginTransaction();
    22
    root = (NumberedNode)s.merge(root);
    22
    root = (NumberedNode)s.merge(root);
    Preondition Violations
    Unmatched statement root=(NumberedNode)s.merge(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                              
                                                      
    23
    s.saveOrUpdate(root);
    Preondition Violations
    Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    23
    s.saveOrUpdate(root);
    23
    tx.commit();
    24
    tx.commit();
    24
    s.close();
    25
    s.close();
    25
    assertInsertCount(1);
    26
    assertInsertCount(1);
    26
    assertUpdateCount(1);
    26
    assertUpdateCount(1);
    38
    assertInsertCount(2);
    Differences
    Expression1Expression2Difference
    assertUpdateCountassertInsertCountMETHOD_INVOCATION_NAME_MISMATCH
    12LITERAL_VALUE_MISMATCH
    Preondition Violations
    Expression assertUpdateCount(1) is a void method call, and thus it cannot be parameterized
    Expression assertInsertCount(2) is a void method call, and thus it cannot be parameterized
    38
    assertInsertCount(2);
    27
    clearCounts();
    28
    clearCounts();
    28
    getSessions().evict(NumberedNode.class);
    28
    getSessions().evict(NumberedNode.class);
    27
    assertUpdateCount(instrumented ? 1 : 3);
    Differences
    Expression1Expression2Difference
    evictassertUpdateCountMETHOD_INVOCATION_NAME_MISMATCH
    getSessions()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression getSessions().evict(NumberedNode.class) is a void method call, and thus it cannot be parameterized
    Expression assertUpdateCount(instrumented ? 1 : 3) is a void method call, and thus it cannot be parameterized
    Expression getSessions().evict(NumberedNode.class) is a void method call, and thus it cannot be parameterized
    Expression assertUpdateCount(instrumented ? 1 : 3) is a void method call, and thus it cannot be parameterized
    27
    assertUpdateCount(instrumented ? 1 : 3);
    29
    NumberedNode child2 = new NumberedNode("child2");
    29
    NumberedNode child2 = new NumberedNode("child2");
    30
    NumberedNode grandchild3 = new NumberedNode("grandchild3");
    30
    NumberedNode grandchild3 = new NumberedNode("grandchild3");
    31
    child2.addChild(grandchild3);
    31
    child2.addChild(grandchild3);
    32
    root.addChild(child2);
    32
    root.addChild(child2);
    33
    s = openSession();
    33
    s = openSession();
    34
    tx = s.beginTransaction();
    34
    tx = s.beginTransaction();
                                                      
    35
    s.saveOrUpdate(root);
    Preondition Violations
    Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    35
    s.saveOrUpdate(root);
    35
    root = (NumberedNode)s.merge(root);
    35
    root = (NumberedNode)s.merge(root);
    Preondition Violations
    Unmatched statement root=(NumberedNode)s.merge(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                              
    36
    tx.commit();
    36
    tx.commit();
    37
    s.close();
    37
    s.close();
    38
    assertInsertCount(2);
                                                      
                                                                                            
    39
    assertUpdateCount(instrumented ? 0 : 4);
    39
    assertUpdateCount(0);
                                                      
    40
    clearCounts();
    40
    clearCounts();
    41
    s = openSession();
    41
    s = openSession();
    42
    tx = s.beginTransaction();
    42
    tx = s.beginTransaction();
    43
    s.createQuery("delete from NumberedNode where name like 'grand%'").executeUpdate();
    43
    s.createQuery("delete from NumberedNode where name like 'grand%'").executeUpdate();
    44
    s.createQuery("delete from NumberedNode where name like 'child%'").executeUpdate();
    44
    s.createQuery("delete from NumberedNode where name like 'child%'").executeUpdate();
    45
    s.createQuery("delete from NumberedNode").executeUpdate();
    45
    s.createQuery("delete from NumberedNode").executeUpdate();
    46
    tx.commit();
    46
    tx.commit();
    47
    s.close();
    47
    s.close();
    Precondition Violations (13)
    Row Violation
    1Unmatched statement root=(NumberedNode)s.merge(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement root=(NumberedNode)s.merge(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Expression assertUpdateCount(1) is a void method call, and thus it cannot be parameterized
    6Expression assertInsertCount(2) is a void method call, and thus it cannot be parameterized
    7Expression getSessions().evict(NumberedNode.class) is a void method call, and thus it cannot be parameterized
    8Expression assertUpdateCount(instrumented ? 1 : 3) is a void method call, and thus it cannot be parameterized
    9Expression getSessions().evict(NumberedNode.class) is a void method call, and thus it cannot be parameterized
    10Expression assertUpdateCount(instrumented ? 1 : 3) is a void method call, and thus it cannot be parameterized
    11Unmatched statement s.saveOrUpdate(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement root=(NumberedNode)s.merge(root); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Clone fragment #1 returns variables s, root , while Clone fragment #2 returns variables s, root