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 | 8 |
Number of unmapped statements in the first code fragment | 7 |
Number of unmapped statements in the second code fragment | 9 |
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()); | | ||||||||||||||||||||||||||
| 5 | User u = new User("Gavin", "nivag"); | ||||||||||||||||||||||||||
4 | batch.createJob().setProcessingInstructions("Just do it!"); |
| 13 | assertEquals(2, logs.size()); | ||||||||||||||||||||||||
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(); |
| 14 | s.delete(u); | ||||||||||||||||||||||||
8 | updateStatuses(session.connection()); |
| 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(); |
| 8 | t.commit(); | ||||||||||||||||||||||||
15 | session.close(); |
| 9 | s.close(); | ||||||||||||||||||||||||
|
| 10 | s = openSession(); | |||||||||||||||||||||||||
|
| 11 | t = s.beginTransaction(); | |||||||||||||||||||||||||
| 12 | List logs = s.createCriteria(Log.class).list(); | ||||||||||||||||||||||||||
| 15 | s.createQuery("delete from Log").executeUpdate(); | ||||||||||||||||||||||||||
| 17 | s.close(); |
Row | Violation |
---|---|
1 | Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized |
2 | Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized |
3 | Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized |
4 | Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized |
5 | Type org.hibernate.test.cascade.JobBatch of variable batch does not match with type org.hibernate.test.interceptor.User of variable u |
6 | Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression session.flush() is a void method call, and thus it cannot be parameterized |
8 | Expression s.delete(u) is a void method call, and thus it cannot be parameterized |
9 | Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | Expression session.flush() is a void method call, and thus it cannot be parameterized |
11 | Expression s.delete(u) is a void method call, and thus it cannot be parameterized |
12 | Expression updateStatuses(session.connection()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
14 | Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized |
15 | Expression t.commit() is a void method call, and thus it cannot be parameterized |
16 | Expression updateStatuses(session.connection()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
17 | Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
18 | Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized |
19 | Expression t.commit() is a void method call, and thus it cannot be parameterized |
20 | Expression txn.rollback() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
21 | Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
22 | Expression txn.rollback() is a void method call, and thus it cannot be parameterized |
23 | Expression t.commit() is a void method call, and thus it cannot be parameterized |
24 | Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
25 | 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 |
26 | Clone fragment #1 returns variables session , while Clone fragment #2 returns variables s, t |