File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/StatisticsTest.java | |||
Method name: void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity()
|
Method name: void testSessionStats()
|
|||
Number of AST nodes: 27 | Number of AST nodes: 28 | |||
1 | Session s = openSession(); ↵ | 1 | SessionFactory sf = getSessions();↵ | |
2 | Transaction t = s.beginTransaction(); ↵ | 2 | Statistics stats = sf.getStatistics();↵ | |
3 | Address address = new Address↵ | 3 | boolean isStats = stats.isStatisticsEnabled();↵ | |
4 | (); ↵ | 4 | stats.clear();↵ | |
5 | address.setInfo( "123 Main St." ); ↵ | 5 | stats.setStatisticsEnabled(true);↵ | |
6 | Suite suite = new Suite(); ↵ | 6 | Session s = sf.openSession();↵ | |
7 | address.getSuites().add( suite );↵ | 7 | a↵ | |
8 | s.save( address ); ↵ | 8 | ssertEquals( 1, stats.getSessionOpenCount() );↵ | |
9 | t.commit(); ↵ | 9 | s.close();↵ | |
10 | s.close();↵ | 10 | ↵ | |
11 | ↵ | 11 | assertEquals( 1, stats.getSessionCloseCount() );↵ | |
12 | s = openSession(); ↵ | 12 | s = sf.openSession();↵ | |
13 | t = s.beginTransaction(); ↵ | 13 | Transaction tx = s.beginTransaction();↵ | |
14 | Note note = new Note(); ↵ | 14 | A a = new A();↵ | |
15 | note.setDescription( "a description" ); ↵ | 15 | a.setName("mya");↵ | |
16 | suite.getNotes().add( note );↵ | 16 | s↵ | |
17 | address.getSuites().clear(); ↵ | 17 | .save(a);↵ | |
18 | s.saveOrUpdate( address ); ↵ | 18 | a.setName("b");↵ | |
19 | t.commit(); ↵ | 19 | tx.commit();↵ | |
20 | s.close();↵ | 20 | s.close();↵ | |
21 | ↵ | |||
21 | assertEquals( 1, stats.getFlushCount() );↵ | |||
22 | s = openSession(); ↵ | 22 | s = sf.openSession();↵ | |
23 | t = s.beginTransaction(); ↵ | 23 | tx = s.beginTransaction();↵ | |
24 | Long count = ( Long )↵ | 24 | String hql = "from " + A.class.getName();↵ | |
25 | s.createQuery( "select count(*) from Suite" ).list().get( 0 ↵ | 25 | Query q = s.createQuery(hql);↵ | |
26 | q.list();↵ | |||
27 | tx.commit();↵ | |||
26 | ); ↵ | 28 | s.close();↵ | |
27 | assertEquals( "all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue() ); ↵ | 29 | assertEquals(1, stats.getQueryExecutionCount() );↵ | |
28 | count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0 );↵ | 30 | ↵ | |
29 | assertEquals( 0, count.longValue() ); ↵ | 31 | assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount() );↵ | |
32 | ↵ | |||
30 | s.delete( address );↵ | 33 | s↵ | |
31 | t.commit();↵ | |||
32 | s.close(); | 34 | tats.setStatisticsEnabled(isStats); | |
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 | 522 |
Number of mapped statements | 11 |
Number of unmapped statements in the first code fragment | 16 |
Number of unmapped statements in the second code fragment | 17 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | SessionFactory sf = getSessions(); | ||||||||||||||||
|
| 2 | Statistics stats = sf.getStatistics(); | |||||||||||||||
| 3 | boolean isStats = stats.isStatisticsEnabled(); | ||||||||||||||||
|
| 4 | stats.clear(); | |||||||||||||||
1 | Session s = openSession(); |
| 6 | Session s = sf.openSession(); | ||||||||||||||
2 | Transaction t = s.beginTransaction(); |
| 11 | Transaction tx = s.beginTransaction(); | ||||||||||||||
3 | Address address = new Address(); | | ||||||||||||||||
4 | address.setInfo("123 Main St."); |
| | |||||||||||||||
|
| 5 | stats.setStatisticsEnabled(true); | |||||||||||||||
5 | Suite suite = new Suite(); | | ||||||||||||||||
6 | address.getSuites().add(suite); | | ||||||||||||||||
| 7 | assertEquals(1, stats.getSessionOpenCount()); | ||||||||||||||||
7 | s.save(address); |
| | |||||||||||||||
| 9 | assertEquals(1, stats.getSessionCloseCount()); | ||||||||||||||||
8 | t.commit(); |
| 16 | tx.commit(); | ||||||||||||||
9 | s.close(); | 8 | s.close(); | |||||||||||||||
10 | s = openSession(); |
| 10 | s = sf.openSession(); | ||||||||||||||
11 | t = s.beginTransaction(); |
| | |||||||||||||||
| 12 | A a = new A(); | ||||||||||||||||
12 | Note note = new Note(); | | ||||||||||||||||
|
| 13 | a.setName("mya"); | |||||||||||||||
13 | note.setDescription("a description"); |
| | |||||||||||||||
|
| 14 | s.save(a); | |||||||||||||||
14 | suite.getNotes().add(note); | | ||||||||||||||||
|
| 15 | a.setName("b"); | |||||||||||||||
15 | address.getSuites().clear(); | | ||||||||||||||||
16 | s.saveOrUpdate(address); |
| | |||||||||||||||
| 21 | String hql = "from " + A.class.getName(); | ||||||||||||||||
|
| 22 | Query q = s.createQuery(hql); | |||||||||||||||
|
| 23 | q.list(); | |||||||||||||||
17 | t.commit(); |
| 24 | tx.commit(); | ||||||||||||||
18 | s.close(); | 17 | s.close(); | |||||||||||||||
19 | s = openSession(); |
| 19 | s = sf.openSession(); | ||||||||||||||
20 | t = s.beginTransaction(); |
| 20 | tx = s.beginTransaction(); | ||||||||||||||
21 | Long count = (Long)s.createQuery("select count(*) from Suite").list().get(0); |
| | |||||||||||||||
22 | assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities", 0, count.longValue()); |
| 18 | assertEquals(1, stats.getFlushCount()); | ||||||||||||||
23 | count = (Long)s.createQuery("select count(*) from Note").list().get(0); |
| | |||||||||||||||
24 | assertEquals(0, count.longValue()); | | ||||||||||||||||
25 | s.delete(address); |
| | |||||||||||||||
| 26 | assertEquals(1, stats.getQueryExecutionCount()); | ||||||||||||||||
26 | t.commit(); |
| | |||||||||||||||
27 | s.close(); | 25 | s.close(); | |||||||||||||||
| 27 | assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount()); | ||||||||||||||||
|
| 28 | stats.setStatisticsEnabled(isStats); |
Row | Violation |
---|---|
1 | Unmatched statement Statistics stats=sf.getStatistics(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
2 | Unmatched statement stats.clear(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
3 | Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Unmatched statement address.setInfo("123 Main St."); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
6 | Unmatched statement stats.setStatisticsEnabled(true); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
7 | Unmatched statement s.save(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
8 | Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | 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 | Unmatched statement a.setName("mya"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
12 | Unmatched statement note.setDescription("a description"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
13 | Unmatched statement s.save(a); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
14 | Unmatched statement a.setName("b"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
15 | Unmatched statement s.saveOrUpdate(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
16 | Unmatched statement Query q=s.createQuery(hql); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
17 | Unmatched statement q.list(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
18 | Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
19 | Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
20 | Unmatched statement Long count=(Long)s.createQuery("select count(*) from Suite").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
21 | Expression assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
22 | Expression assertEquals(1,stats.getFlushCount()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
23 | Expression assertEquals("all-delete-orphan not cascaded properly to cleared persistent collection entities",0,count.longValue()) is a void method call, and thus it cannot be parameterized |
24 | Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized |
25 | Unmatched statement count=(Long)s.createQuery("select count(*) from Note").list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
26 | Unmatched statement s.delete(address); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
27 | Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
28 | Unmatched statement stats.setStatisticsEnabled(isStats); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
29 | Clone fragment #1 returns variables s, t , while Clone fragment #2 returns variables s |