Session s = openSession(); s.beginTransaction(); s.save( new Employee( "John", 'M', "john", new Date() ) ); s.save( new Employee( "Jane", 'F', "jane", new Date() ) ); s.save( new Customer( "Charlie", 'M', "charlie", "Acme" ) ); s.save( new Customer( "Wanda", 'F', "wanda", "ABC" ) ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.enableFilter( "sex" ).setParameter( "sexCode", new Character('M' ) ); int count = s.createQuery( "update User u set u.username = :un where u.name = :n" ) .setString( "un", "charlie" ) .setString( "n", "Wanda" ) .executeUpdate(); assertEquals( 0, count ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.createQuery( "delete Person" ).executeUpdate(); s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); s.save( new Employee( "John", 'M', "john", new Date() ) ); s.save( new Employee( "Jane", 'F', "jane", new Date() ) ); s.save( new Customer( "Charlie", 'M', "charlie", "Acme" ) ); s.save( new Customer( "Wanda", 'F', "wanda", "ABC" ) ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.enableFilter( "sex" ).setParameter( "sexCode", new Character('M' ) ); int count = s.createQuery( "delete User" ).executeUpdate(); assertEquals( 2, count ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.createQuery( "delete Person" ).executeUpdate(); 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/filter/hql/JoinedFilteredBulkManipulationTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/filter/hql/JoinedFilteredBulkManipulationTest.java
Method name: void testFilteredJoinedSubclassHqlUpdateNonLeaf() Method name: void testFilteredJoinedSubclassHqlDeleteNonLeaf()
Number of AST nodes: 20 Number of AST nodes: 20
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		s.save( new Employee( "John", 'M', "john", new Date() ) );
3
		s.save( new Employee( "John", 'M', "john", new Date() ) );
4
		s.save( new Employee( "Jane", 'F', "jane", new Date() ) );
4
		s.save( new Employee( "Jane", 'F', "jane", new Date() ) );
5
		s.save( new Customer( "Charlie", 'M', "charlie", "Acme" ) );
5
		s.save( new Customer( "Charlie", 'M', "charlie", "Acme" ) );
6
		s.save( new Customer( "Wanda", 'F', "wanda", "ABC" ) );
6
		s.save( new Customer( "Wanda", 'F', "wanda", "ABC" ) );
7
		s.getTransaction().commit();
7
		s.getTransaction().commit();
8
		s.close();
8
		s.close();
9
		s = openSession();
9
		s = openSession();
10
		s.beginTransaction();
10
		s.beginTransaction();
11
		s.enableFilter( "sex" ).setParameter( "sexCode", new Character('M' ) );
11
		s.enableFilter( "sex" ).setParameter( "sexCode", new Character('M' ) );
12
		int count = s.createQuery( "update User u set u.username = :un where u.name = :n" )
12
		int count = s.createQuery( "
13
				.setString( "un", "charlie" )
14
				.setString( "n", "Wanda" )
15
				.executeUpdate();
13
delete User" ).executeUpdate();
16
		assertEquals( 0, count );
14
		assertEquals( 2, count );
17
		s.getTransaction().commit();
15
		s.getTransaction().commit();
18
		s.close();
16
		s.close();
19
		s = openSession();
17
		s = openSession();
20
		s.beginTransaction();
18
		s.beginTransaction();
21
		s.createQuery( "delete Person" ).executeUpdate();
19
		s.createQuery( "delete Person" ).executeUpdate();
22
		s.getTransaction().commit();
20
		s.getTransaction().commit();
23
		s.close();
21
		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 comparisons112
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements19
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    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
    s.save(new Employee("John", 'M', "john", new Date()));
    3
    s.save(new Employee("John", 'M', "john", new Date()));
    4
    s.save(new Employee("Jane", 'F', "jane", new Date()));
    4
    s.save(new Employee("Jane", 'F', "jane", new Date()));
    5
    s.save(new Customer("Charlie", 'M', "charlie", "Acme"));
    5
    s.save(new Customer("Charlie", 'M', "charlie", "Acme"));
    6
    s.save(new Customer("Wanda", 'F', "wanda", "ABC"));
    6
    s.save(new Customer("Wanda", 'F', "wanda", "ABC"));
    7
    s.getTransaction().commit();
    7
    s.getTransaction().commit();
    8
    s.close();
    8
    s.close();
    9
    s = openSession();
    9
    s = openSession();
    10
    s.beginTransaction();
    10
    s.beginTransaction();
    11
    s.enableFilter("sex").setParameter("sexCode", new Character('M'));
    11
    s.enableFilter("sex").setParameter("sexCode", new Character('M'));
                                                                                                                          
    12
    int count = s.createQuery("delete User").executeUpdate();
    Preondition Violations
    Unmatched statement int count=s.createQuery("delete User").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    int count = s.createQuery("delete User").executeUpdate();
    12
    int count = s.createQuery("update User u set u.username = :un where u.name = :n").setString("un", "charlie").setString("n", "Wanda").executeUpdate();
    12
    int count = s.createQuery("update User u set u.username = :un where u.name = :n").setString("un", "charlie").setString("n", "Wanda").executeUpdate();
    Preondition Violations
    Unmatched statement int count=s.createQuery("update User u set u.username = :un where u.name = :n").setString("un","charlie").setString("n","Wanda").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                                                                                              
    13
    assertEquals(0, count);
    13
    assertEquals(0, count);
    13
    assertEquals(2, count);
    Differences
    Expression1Expression2Difference
    02LITERAL_VALUE_MISMATCH
    13
    assertEquals(2, count);
    14
    s.getTransaction().commit();
    14
    s.getTransaction().commit();
    15
    s.close();
    15
    s.close();
    16
    s = openSession();
    16
    s = openSession();
    17
    s.beginTransaction();
    17
    s.beginTransaction();
    18
    s.createQuery("delete Person").executeUpdate();
    18
    s.createQuery("delete Person").executeUpdate();
    19
    s.getTransaction().commit();
    19
    s.getTransaction().commit();
    20
    s.close();
    20
    s.close();
    Precondition Violations (2)
    Row Violation
    1Unmatched statement int count=s.createQuery("delete User").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement int count=s.createQuery("update User u set u.username = :un where u.name = :n").setString("un","charlie").setString("n","Wanda").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted