final StatefulInterceptor statefulInterceptor = new StatefulInterceptor(); Session s = openSession( statefulInterceptor ); statefulInterceptor.setSession(s); Transaction t = s.beginTransaction(); User u = new User("Gavin", "nivag"); s.persist(u); u.setPassword("vagni"); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); List logs = s.createCriteria(Log.class).list(); assertEquals( 2, logs.size() ); s.delete(u); s.createQuery( "delete from Log" ).executeUpdate(); t.commit(); s.close();
Session session = openSession(); session.delete("from A"); A savedA = new A(); session.save(savedA); B savedB = new B(); session.save(savedB); session.flush(); int count = session.createQuery("from A").list().size(); session.close(); session = openSession(); Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class); List list = query.list(); assertNotNull(list); assertEquals(count, list.size()); session.connection().commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/interceptor/InterceptorTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java
Method name: void testStatefulIntercept() Method name: void testFindBySQLDiscriminatedDiffSession()
Number of AST nodes: 17 Number of AST nodes: 16
1
final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
2
		Session s = openSession( statefulInterceptor );
1
Session session = openSession(
3
		statefulInterceptor.setSession(s);
4
		Transaction t = s.beginTransaction
2
);
3
		session.delete("from A");
4
		A savedA = new A();
5
		session.save(savedA);
5
();
6
		B savedB = new B();
6
		User u = new User("Gavin", "nivag");
7
		se
7
		s.persist(u
8
ssion.save(savedB);
8
);
9
		session.flush();
9
		u.setPassword("vagni");
10
		
10
		t.commit();
11
int count = session.createQuery("from A").list().size();
11
		s.close();
12
		session.close();
12
		s = openSession();
13
		session = openSession();
13
		t = s.beginTransaction();
14
		
14
		List logs = s.createCriteria(Log.class).
15
Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class);
16
		List list = query.list();
15
list();
17
		assertNotNull(list);
16
		assertEquals( 2, logs.size() );
18
		assertEquals(count, list.size());
17
		s.delete(u);
19
		s
18
		s.createQuery( "delete from Log" ).executeUpdate();
19
		t.commit();
20
ession.connection().commit();
20
		s.close();
21
		session.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 comparisons272
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment11
    Number of unmapped statements in the second code fragment10
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
                                                                                                                                                          
    2
    Session s = openSession(statefulInterceptor);
    2
    Session s = openSession(statefulInterceptor);
    1
    Session session = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    openSession(statefulInterceptor)openSession()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    1
    Session session = openSession();
                                                            
    2
    session.delete("from A");
    Preondition Violations
    Unmatched statement session.delete("from A"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2
    session.delete("from A");
                                            
    3
    A savedA = new A();
    3
    statefulInterceptor.setSession(s);
    3
    statefulInterceptor.setSession(s);
    Preondition Violations
    Unmatched statement statefulInterceptor.setSession(s); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                              
                                                    
    4
    session.save(savedA);
    Preondition Violations
    Unmatched statement session.save(savedA); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4
    session.save(savedA);
    4
    Transaction t = s.beginTransaction();
    4
    Transaction t = s.beginTransaction();
    Preondition Violations
    Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                
                                            
    5
    B savedB = new B();
    5
    User u = new User("Gavin", "nivag");
    5
    User u = new User("Gavin", "nivag");
    Preondition Violations
    Unmatched statement User u=new User("Gavin","nivag"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                            
                                                    
    6
    session.save(savedB);
    Preondition Violations
    Unmatched statement session.save(savedB); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    session.save(savedB);
    6
    s.persist(u);
    6
    s.persist(u);
    7
    session.flush();
    Differences
    Expression1Expression2Difference
    persistflushMETHOD_INVOCATION_NAME_MISMATCH
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    s.persist(u)session.flush()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.persist(u) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.persist(u) is a void method call, and thus it cannot be parameterized
    Expression session.flush() is a void method call, and thus it cannot be parameterized
    Expression s.persist(u) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.persist(u) is a void method call, and thus it cannot be parameterized
    Expression session.flush() is a void method call, and thus it cannot be parameterized
    7
    session.flush();
    7
    u.setPassword("vagni");
    7
    u.setPassword("vagni");
    Preondition Violations
    Unmatched statement u.setPassword("vagni"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                        
                                                                                                                      
    8
    int count = session.createQuery("from A").list().size();
    Preondition Violations
    Unmatched statement int count=session.createQuery("from A").list().size(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    int count = session.createQuery("from A").list().size();
    8
    t.commit();
    8
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                
    9
    s.close();
    9
    s.close();
    9
    session.close();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    9
    session.close();
    10
    s = openSession();
    10
    s = openSession();
    10
    session = openSession();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    10
    session = openSession();
                                                                                                                                                                                                                                                                                                                                                      
    11
    Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class);
    Preondition Violations
    Unmatched statement Query query=session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA","a",A.class); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    Query query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA", "a", A.class);
    11
    t = s.beginTransaction();
    11
    t = s.beginTransaction();
    Preondition Violations
    Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                          
                                                          
    12
    List list = query.list();
    Preondition Violations
    Unmatched statement List list=query.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12
    List list = query.list();
    12
    List logs = s.createCriteria(Log.class).list();
    12
    List logs = s.createCriteria(Log.class).list();
    Preondition Violations
    Unmatched statement List logs=s.createCriteria(Log.class).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                      
    13
    assertEquals(2, logs.size());
    13
    assertEquals(2, logs.size());
    13
    assertNotNull(list);
    Differences
    Expression1Expression2Difference
    assertEqualsassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(2,logs.size())assertNotNull(list)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(list) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNotNull(list) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    13
    assertNotNull(list);
                                                                            
    14
    assertEquals(count, list.size());
    14
    s.delete(u);
    14
    s.delete(u);
    Preondition Violations
    Unmatched statement s.delete(u); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                    
                                                                        
    15
    session.connection().commit();
    Preondition Violations
    Unmatched statement session.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    session.connection().commit();
    15
    s.createQuery("delete from Log").executeUpdate();
    15
    s.createQuery("delete from Log").executeUpdate();
    Preondition Violations
    Unmatched statement s.createQuery("delete from Log").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                              
    16
    t.commit();
    16
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                  
    17
    s.close();
    17
    s.close();
    16
    session.close();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    16
    session.close();
    Precondition Violations (36)
    Row Violation
    1Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement session.delete("from A"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement statefulInterceptor.setSession(s); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement session.save(savedA); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement Transaction t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement User u=new User("Gavin","nivag"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched statement session.save(savedB); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Expression s.persist(u) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression s.persist(u) is a void method call, and thus it cannot be parameterized
    12Expression session.flush() is a void method call, and thus it cannot be parameterized
    13Expression s.persist(u) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression s.persist(u) is a void method call, and thus it cannot be parameterized
    16Expression session.flush() is a void method call, and thus it cannot be parameterized
    17Unmatched statement u.setPassword("vagni"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    18Unmatched statement int count=session.createQuery("from A").list().size(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    20Unmatched statement Query query=session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA","a",A.class); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22Unmatched statement List list=query.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    23Unmatched statement List logs=s.createCriteria(Log.class).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression assertNotNull(list) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    27Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    28Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    29Expression assertNotNull(list) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    30Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    31Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    32Unmatched statement s.delete(u); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    33Unmatched statement session.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    34Unmatched statement s.createQuery("delete from Log").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    35Unmatched statement t.commit(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    36Clone fragment #1 returns variable s with type org.hibernate.Session , while Clone fragment #2 returns variable session with type org.hibernate.classic.Session