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(); | |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 164 |
Number of mapped statements | 5 |
Number of unmapped statements in the first code fragment | 7 |
Number of unmapped statements in the second code fragment | 12 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | final StatefulInterceptor statefulInterceptor = new StatefulInterceptor(); | |||||||||||||||||||
1 | Session session = openSession(); |
| 2 | Session s = openSession(statefulInterceptor); | |||||||||||||||||
|
| 3 | statefulInterceptor.setSession(s); | ||||||||||||||||||
2 | Transaction txn = session.beginTransaction(); |
| 4 | Transaction t = s.beginTransaction(); | |||||||||||||||||
3 | JobBatch batch = new JobBatch(new Date()); |
| | ||||||||||||||||||
4 | batch.createJob().setProcessingInstructions("Just do it!"); | | |||||||||||||||||||
|
| 5 | User u = new User("Gavin", "nivag"); | ||||||||||||||||||
5 | batch.createJob().setProcessingInstructions("I know you can do it!"); | | |||||||||||||||||||
6 | session.persist(batch); |
| 6 | s.persist(u); | |||||||||||||||||
|
| 7 | u.setPassword("vagni"); | ||||||||||||||||||
7 | session.flush(); |
| | ||||||||||||||||||
8 | updateStatuses(session.connection()); |
| | ||||||||||||||||||
9 | session.refresh(batch); |
| | ||||||||||||||||||
10 | Iterator itr = batch.getJobs().iterator(); | | |||||||||||||||||||
14 | txn.rollback(); |
| 8 | t.commit(); | |||||||||||||||||
15 | session.close(); |
| 9 | s.close(); | |||||||||||||||||
|
| 10 | s = openSession(); | ||||||||||||||||||
|
| 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(); | ||||||||||||||||||
| 17 | s.close(); |
Row | Violation |
---|---|
1 | Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
2 | Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | 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 | 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 |
5 | 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 | Type org.hibernate.test.cascade.JobBatch of variable batch does not match with type org.hibernate.test.interceptor.User of variable u |
7 | Unmatched statement u.setPassword("vagni"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
8 | Unmatched statement session.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
9 | 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 |
10 | 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 |
11 | Expression txn.rollback() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Expression txn.rollback() is a void method call, and thus it cannot be parameterized |
14 | Expression t.commit() is a void method call, and thus it cannot be parameterized |
15 | Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
16 | 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 |
17 | Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
18 | Clone fragment #1 returns variables session , while Clone fragment #2 returns variables s, t |