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/legacy/SQLLoaderTest.java | |||
Method name: void testRefreshCascade()
|
Method name: void testFindBySQLDiscriminatedDiffSession()
|
|||
Number of AST nodes: 15 | Number of AST nodes: 16 | |||
1 | Session session = openSession();↵ | 1 | Session session = openSession();↵ | |
2 | Transaction txn = session.beginTransaction();↵ | 2 | ↵ | |
3 | JobBatch batch = new JobBatch( new Date() );↵ | |||
4 | batch.createJob().setProcessingInstructions( "Just do it!" );↵ | |||
5 | batch.createJob().setProcessingInstructions( "I know you can do it!" );↵ | |||
6 | // write the stuff to the database; at this stage all job.status values are zero↵ | |||
7 | session.persist( batch ↵ | 3 | session.delete("from A");↵ | |
4 | A savedA = new A();↵ | |||
5 | session.save(savedA);↵ | |||
6 | B savedB = new B();↵ | |||
7 | session.save(savedB);↵ | |||
8 | session.flush();↵ | |||
8 | );↵ | 9 | int count = session.createQuery("from A").list().size();↵ | |
9 | session.flush();↵ | 10 | session.close();↵ | |
10 | // behind the session's back, let's modify the statuses↵ | 11 | ↵ | |
11 | updateStatuses( session.connection() );↵ | |||
12 | // Now lets refresh the persistent batch, and see if the refresh cascaded to the jobs collection elements↵ | |||
13 | session.refresh( batch ↵ | 12 | session = openSession();↵ | |
14 | );↵ | 13 | 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);↵ | |
15 | Iterator itr = batch.getJobs().iterator();↵ | 14 | List list = query.list();↵ | |
16 | while( itr.hasNext() ) {↵ | 15 | ↵ | |
17 | Job job = ( Job ) itr.next();↵ | 16 | assertNotNull(list);↵ | |
18 | assertEquals( "Jobs not refreshed!", 1, job.getStatus() );↵ | 17 | assertEquals(count, list.size());↵ | |
19 | }↵ | 18 | ↵ | |
20 | txn.rollback();↵ | 19 | session.connection().commit();↵ | |
21 | session.close(); | 20 |
| |
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 | 192 |
Number of mapped statements | 5 |
Number of unmapped statements in the first code fragment | 10 |
Number of unmapped statements in the second code fragment | 11 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Session session = openSession(); | ||||||||||||||||||||||
1 | Session session = openSession(); | | ||||||||||||||||||||||
| 2 | session.delete("from A"); | ||||||||||||||||||||||
2 | Transaction txn = session.beginTransaction(); | | ||||||||||||||||||||||
| 3 | A savedA = new A(); | ||||||||||||||||||||||
3 | JobBatch batch = new JobBatch(new Date()); | | ||||||||||||||||||||||
| 4 | session.save(savedA); | ||||||||||||||||||||||
| 5 | B savedB = new B(); | ||||||||||||||||||||||
| 6 | session.save(savedB); | ||||||||||||||||||||||
| 8 | int count = session.createQuery("from A").list().size(); | ||||||||||||||||||||||
| 9 | session.close(); | ||||||||||||||||||||||
|
| 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(); | ||||||||||||||||||||||
4 | batch.createJob().setProcessingInstructions("Just do it!"); |
| 14 | assertEquals(count, list.size()); | ||||||||||||||||||||
5 | batch.createJob().setProcessingInstructions("I know you can do it!"); | | ||||||||||||||||||||||
6 | session.persist(batch); | | ||||||||||||||||||||||
7 | session.flush(); |
| 7 | session.flush(); | ||||||||||||||||||||
8 | updateStatuses(session.connection()); |
| 15 | session.connection().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(); |
| 13 | assertNotNull(list); | ||||||||||||||||||||
15 | session.close(); |
| 16 | session.close(); |
Row | Violation |
---|---|
1 | Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized |
3 | Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized |
4 | Expression batch.createJob().setProcessingInstructions("Just do it!") is a void method call, and thus it cannot be parameterized |
5 | Expression assertEquals(count,list.size()) is a void method call, and thus it cannot be parameterized |
6 | Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable session |
7 | Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized |
8 | Expression session.connection().commit() is a void method call, and thus it cannot be parameterized |
9 | Expression updateStatuses(session.connection()) is a void method call, and thus it cannot be parameterized |
10 | Expression session.connection().commit() is a void method call, and thus it cannot be parameterized |
11 | Expression txn.rollback() is a void method call, and thus it cannot be parameterized |
12 | Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized |
13 | Expression txn.rollback() is a void method call, and thus it cannot be parameterized |
14 | Expression assertNotNull(list) is a void method call, and thus it cannot be parameterized |
15 | Type org.hibernate.Session of variable session does not match with type org.hibernate.classic.Session of variable session |