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 statements5
    Number of unmapped statements in the first code fragment12
    Number of unmapped statements in the second code fragment11
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                      
    1
    Session session = openSession();
    1
    final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
                                                                                                                                                          
                                                            
    2
    session.delete("from A");
    2
    Session s = openSession(statefulInterceptor);
                                                                                                
                                            
    3
    A savedA = new A();
    3
    statefulInterceptor.setSession(s);
                                                                              
                                                    
    4
    session.save(savedA);
    4
    Transaction t = s.beginTransaction();
                                                                                
                                            
    5
    B savedB = new B();
    5
    User u = new User("Gavin", "nivag");
                                                                            
                                                    
    6
    session.save(savedB);
    6
    s.persist(u);
                                    
    7
    u.setPassword("vagni");
                                                        
                                                                                                                      
    8
    int count = session.createQuery("from A").list().size();
    8
    t.commit();
    8
    t.commit();
    13
    assertNotNull(list);
    Differences
    Expression1Expression2Difference
    commitassertNotNullMETHOD_INVOCATION_NAME_MISMATCH
    t.commit()assertNotNull(list)ARGUMENT_NUMBER_MISMATCH
    tMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression t.commit() 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 t.commit() 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);
    9
    s.close();
    9
    s.close();
    9
    session.close();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable session
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    9
    session.close();
    10
    s = openSession();
    10
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
    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 logs = s.createCriteria(Log.class).list();
                                                                                                      
    13
    assertEquals(2, logs.size());
    13
    assertEquals(2, logs.size());
    7
    session.flush();
    Differences
    Expression1Expression2Difference
    assertEqualsflushMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(2,logs.size())session.flush()ARGUMENT_NUMBER_MISMATCH
    sessionMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertEquals(2,logs.size()) 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 assertEquals(2,logs.size()) 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();
                                                        
    10
    session = openSession();
    Preondition Violations
    Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    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);
                                                          
    12
    List list = query.list();
    14
    s.delete(u);
                                    
    15
    s.createQuery("delete from Log").executeUpdate();
                                                                                                              
    16
    t.commit();
    16
    t.commit();
    14
    assertEquals(count, list.size());
    Differences
    Expression1Expression2Difference
    commitassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    t.commit()assertEquals(count,list.size())ARGUMENT_NUMBER_MISMATCH
    tMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression t.commit() is a void method call, and thus it cannot be parameterized
    Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression t.commit() is a void method call, and thus it cannot be parameterized
    Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    14
    assertEquals(count, list.size());
                                                                        
    15
    session.connection().commit();
    17
    s.close();
    17
    s.close();
    16
    session.close();
    Differences
    Expression1Expression2Difference
    ssessionVARIABLE_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable session
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    16
    session.close();
    Precondition Violations (19)
    Row Violation
    1Expression t.commit() is a void method call, and thus it cannot be parameterized
    2Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    3Expression t.commit() is a void method call, and thus it cannot be parameterized
    4Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized
    5Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable session
    6Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    9Expression session.flush() is a void method call, and thus it cannot be parameterized
    10Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    11Expression session.flush() is a void method call, and thus it cannot be parameterized
    12Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression t.commit() is a void method call, and thus it cannot be parameterized
    15Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    16Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression t.commit() is a void method call, and thus it cannot be parameterized
    18Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized
    19Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable session