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 | 3 |
Number of unmapped statements in the first code fragment | 9 |
Number of unmapped statements in the second code fragment | 13 |
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); | |||||||||||||||||||||||||
4 | batch.createJob().setProcessingInstructions("Just do it!"); | | ||||||||||||||||||||||||||
| 5 | B savedB = new B(); | ||||||||||||||||||||||||||
5 | batch.createJob().setProcessingInstructions("I know you can do it!"); | | ||||||||||||||||||||||||||
|
| 6 | session.save(savedB); | |||||||||||||||||||||||||
6 | session.persist(batch); |
| 7 | session.flush(); | ||||||||||||||||||||||||
7 | session.flush(); |
| | |||||||||||||||||||||||||
|
| 8 | int count = session.createQuery("from A").list().size(); | |||||||||||||||||||||||||
8 | updateStatuses(session.connection()); |
| | |||||||||||||||||||||||||
9 | session.refresh(batch); |
| | |||||||||||||||||||||||||
|
| 10 | session = openSession(); | |||||||||||||||||||||||||
10 | Iterator itr = batch.getJobs().iterator(); | | ||||||||||||||||||||||||||
14 | txn.rollback(); |
| | |||||||||||||||||||||||||
15 | session.close(); |
| 9 | session.close(); | ||||||||||||||||||||||||
|
| 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(); | |||||||||||||||||||||||||
| 13 | assertNotNull(list); | ||||||||||||||||||||||||||
| 14 | assertEquals(count, list.size()); | ||||||||||||||||||||||||||
| 15 | session.connection().commit(); | ||||||||||||||||||||||||||
| 16 | session.close(); |
Row | Violation |
---|---|
1 | Unmatched statement session.delete("from A"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement Transaction txn=session.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | 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 | Unmatched statement session.save(savedA); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | Unmatched statement session.save(savedB); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
6 | Expression session.persist(batch) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression session.persist(batch) is a void method call, and thus it cannot be parameterized |
9 | Expression session.flush() is a void method call, and thus it cannot be parameterized |
10 | Expression session.persist(batch) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
11 | Expression session.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression session.persist(batch) is a void method call, and thus it cannot be parameterized |
13 | Expression session.flush() is a void method call, and thus it cannot be parameterized |
14 | Unmatched statement session.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
15 | Unmatched statement int count=session.createQuery("from A").list().size(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
16 | 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 |
17 | 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 |
18 | Unmatched statement session=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
19 | Unmatched statement txn.rollback(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
20 | Unmatched statement 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); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
21 | Unmatched statement List list=query.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
22 | Clone fragment #1 returns variable session with type org.hibernate.Session , while Clone fragment #2 returns variable session with type org.hibernate.classic.Session |