Session session = openSession(); Transaction txn = session.beginTransaction(); JobBatch batch = new JobBatch( new Date() ); batch.createJob().setProcessingInstructions( "Just do it!" ); batch.createJob().setProcessingInstructions( "I know you can do it!" ); // write the stuff to the database; at this stage all job.status values are zero session.persist( batch ); session.flush(); // behind the session's back, let's modify the statuses updateStatuses( session.connection() ); // Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements session.refresh( batch ); Iterator itr = batch.getJobs().iterator(); while( itr.hasNext() ) { Job job = ( Job ) itr.next(); assertEquals( "Jobs not refreshed!", 1, job.getStatus() ); } txn.rollback(); session.close();
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();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/RefreshTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/interceptor/InterceptorTest.java
Method name: void testRefreshCascade() Method name: void testStatefulIntercept()
Number of AST nodes: 15 Number of AST nodes: 17
1
Session session = openSession();
2
		Transaction txn = session.beginTransaction();
3
		JobBatch batch = new JobBatch( new Date() );
4
		batch.createJob().setProcessingInstructions( "Just do it!" );
5
		batch.createJob().setProcessingInstructions( "I know you can do it!" 
1
final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
2
		Session s = openSession( statefulInterceptor );
3
		statefulInterceptor.setSession(s);
6
);
4
		Transaction t = s.beginTransaction();
7
		// write the stuff to the database; at this stage all job.status values are zero
5
		
8
		session
6
User u = new User("Gavin", "nivag");
9
.persist( batch );
7
		s.persist(
10
		session.flush(
8
u);
11
);
9
		u.setPassword("vagni");
12
		// behind the session's back, let's modify the statuses
10
		
13
		updateStatuses( session.connection() );
14
		// Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements
15
		session.refresh( batch );
16
		Iterator itr = batch.getJobs().iterator();
17
		while( itr.hasNext
11
t.commit();
12
		s.close();
13
		s = openSession();
14
		t = s.beginTransaction();
15
		List logs = s.createCriteria(Log.class).list();
18
() ) {
16
		assertEquals( 2, logs.size() );
19
			Job job = ( Job ) itr.next();
17
		
20
			assertEquals( "Jobs not refreshed!", 1, job.getStatus() );
21
		}
22
		txn.rollback
18
s.delete(u);
19
		s.createQuery( "delete from Log" ).executeUpdate();
23
();
20
		t.commit();
24
		session.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 in different classes having the same super class
Number of node comparisons164
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment12
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                                                                                          
    1
    final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
    1
    Session session = openSession();
    1
    Session session = openSession();
    2
    Session s = openSession(statefulInterceptor);
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    openSession()openSession(statefulInterceptor)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2
    Session s = openSession(statefulInterceptor);
                                                                              
    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
    3
    statefulInterceptor.setSession(s);
    2
    Transaction txn = session.beginTransaction();
    2
    Transaction txn = session.beginTransaction();
    4
    Transaction t = s.beginTransaction();
    Differences
    Expression1Expression2Difference
    txntVARIABLE_NAME_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    4
    Transaction t = s.beginTransaction();
    3
    JobBatch batch = new JobBatch(new Date());
    3
    JobBatch batch = new JobBatch(new Date());
    Preondition Violations
    Unmatched statement JobBatch batch=new JobBatch(new Date()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                          
    4
    batch.createJob().setProcessingInstructions("Just do it!");
                                                                                                                                
                                                                            
    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
    5
    User u = new User("Gavin", "nivag");
    5
    batch.createJob().setProcessingInstructions("I know you can do it!");
                                                                                                                                                    
    6
    session.persist(batch);
    6
    session.persist(batch);
    6
    s.persist(u);
    Differences
    Expression1Expression2Difference
    batchuVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.JobBatchorg.hibernate.test.interceptor.UserVARIABLE_TYPE_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.JobBatch of variable batch does not match with type org.hibernate.test.interceptor.User of variable u
    • Make classes org.hibernate.test.cascade.JobBatch and org.hibernate.test.interceptor.User extend a common superclass
    6
    s.persist(u);
                                                        
    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
    7
    u.setPassword("vagni");
    7
    session.flush();
    7
    session.flush();
    Preondition Violations
    Unmatched statement session.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
    8
    updateStatuses(session.connection());
    8
    updateStatuses(session.connection());
    Preondition Violations
    Unmatched statement updateStatuses(session.connection()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                    
    9
    session.refresh(batch);
    9
    session.refresh(batch);
    Preondition Violations
    Unmatched statement session.refresh(batch); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                        
    10
    Iterator itr = batch.getJobs().iterator();
                                                                                            
    14
    txn.rollback();
    14
    txn.rollback();
    8
    t.commit();
    Differences
    Expression1Expression2Difference
    rollbackcommitMETHOD_INVOCATION_NAME_MISMATCH
    txntVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression txn.rollback() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression txn.rollback() 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
    8
    t.commit();
    15
    session.close();
    15
    session.close();
    9
    s.close();
    Differences
    Expression1Expression2Difference
    sessionsVARIABLE_NAME_MISMATCH
    9
    s.close();
                                            
    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
    10
    s = openSession();
                                                          
    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
    11
    t = s.beginTransaction();
                                                                                                      
    12
    List logs = s.createCriteria(Log.class).list();
                                                                    
    13
    assertEquals(2, logs.size());
                                    
    14
    s.delete(u);
                                                                                                              
    15
    s.createQuery("delete from Log").executeUpdate();
                                  
    16
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    t.commit();
                                
    17
    s.close();
    Precondition Violations (18)
    Row Violation
    1Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement statefulInterceptor.setSession(s); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement JobBatch batch=new JobBatch(new Date()); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched 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
    6Type org.hibernate.test.cascade.JobBatch of variable batch does not match with type org.hibernate.test.interceptor.User of variable u
    7Unmatched statement u.setPassword("vagni"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched statement session.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement updateStatuses(session.connection()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement session.refresh(batch); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Expression txn.rollback() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression txn.rollback() is a void method call, and thus it cannot be parameterized
    14Expression t.commit() is a void method call, and thus it cannot be parameterized
    15Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Clone fragment #1 returns variables session , while Clone fragment #2 returns variables s, t