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 statements8
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment9
    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
    2
    Session s = openSession(statefulInterceptor);
                                                                              
    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());
                                                                                          
                                                                            
    5
    User u = new User("Gavin", "nivag");
    4
    batch.createJob().setProcessingInstructions("Just do it!");
    4
    batch.createJob().setProcessingInstructions("Just do it!");
    13
    assertEquals(2, logs.size());
    Differences
    Expression1Expression2Difference
    setProcessingInstructionsassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    batch.createJob().setProcessingInstructions("Just do it!")assertEquals(2,logs.size())ARGUMENT_NUMBER_MISMATCH
    batch.createJob()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression batch.createJob().setProcessingInstructions("Just do it!") 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 batch.createJob().setProcessingInstructions("Just do it!") 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
    13
    assertEquals(2, logs.size());
    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");
    7
    session.flush();
    7
    session.flush();
    14
    s.delete(u);
    Differences
    Expression1Expression2Difference
    flushdeleteMETHOD_INVOCATION_NAME_MISMATCH
    sessionsVARIABLE_NAME_MISMATCH
    session.flush()s.delete(u)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.flush() is a void method call, and thus it cannot be parameterized
    Expression s.delete(u) is a void method call, and thus it cannot be parameterized
    Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.flush() is a void method call, and thus it cannot be parameterized
    Expression s.delete(u) is a void method call, and thus it cannot be parameterized
    14
    s.delete(u);
    8
    updateStatuses(session.connection());
    8
    updateStatuses(session.connection());
    16
    t.commit();
    Differences
    Expression1Expression2Difference
    updateStatusescommitMETHOD_INVOCATION_NAME_MISMATCH
    updateStatuses(session.connection())t.commit()ARGUMENT_NUMBER_MISMATCH
    tMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression updateStatuses(session.connection()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method updateStatuses
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression updateStatuses(session.connection()) 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 updateStatuses(session.connection()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method updateStatuses
    Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression updateStatuses(session.connection()) 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
    16
    t.commit();
    9
    session.refresh(batch);
                                                        
    10
    Iterator itr = batch.getJobs().iterator();
                                                                                            
    11
    while (itr.hasNext())
                                                    
    12
    Job job = (Job)itr.next();
                                                            
    13
    assertEquals("Jobs not refreshed!", 1, job.getStatus());
                                                                                                                        
    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();
                                                                                                              
    15
    s.createQuery("delete from Log").executeUpdate();
                                
    17
    s.close();
    Precondition Violations (26)
    Row Violation
    1Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized
    2Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    3Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized
    4Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    5Type org.hibernate.test.cascade.JobBatch of variable batch does not match with type org.hibernate.test.interceptor.User of variable u
    6Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression session.flush() is a void method call, and thus it cannot be parameterized
    8Expression s.delete(u) is a void method call, and thus it cannot be parameterized
    9Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression session.flush() is a void method call, and thus it cannot be parameterized
    11Expression s.delete(u) is a void method call, and thus it cannot be parameterized
    12Expression updateStatuses(session.connection()) cannot be parameterized, 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 updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized
    15Expression t.commit() is a void method call, and thus it cannot be parameterized
    16Expression updateStatuses(session.connection()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized
    19Expression t.commit() is a void method call, and thus it cannot be parameterized
    20Expression txn.rollback() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression txn.rollback() is a void method call, and thus it cannot be parameterized
    23Expression t.commit() is a void method call, and thus it cannot be parameterized
    24Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    25Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26Clone fragment #1 returns variables session , while Clone fragment #2 returns variables s, t