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 | 17 |
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 | SessionFactory sf = getSessions(); | ||||||||||||||||||||||||
| 2 | Statistics stats = sf.getStatistics(); | ||||||||||||||||||||||||
| 3 | boolean isStats = stats.isStatisticsEnabled(); | ||||||||||||||||||||||||
| 4 | stats.clear(); | ||||||||||||||||||||||||
| 5 | stats.setStatisticsEnabled(true); | ||||||||||||||||||||||||
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."); |
| 7 | assertEquals(1, stats.getSessionOpenCount()); | ||||||||||||||||||||||
5 | Suite suite = new Suite(); | | ||||||||||||||||||||||||
6 | address.getSuites().add(suite); | | ||||||||||||||||||||||||
| 12 | A a = new A(); | ||||||||||||||||||||||||
| 13 | a.setName("mya"); | ||||||||||||||||||||||||
7 | s.save(address); |
| 14 | s.save(a); | ||||||||||||||||||||||
| 15 | a.setName("b"); | ||||||||||||||||||||||||
8 | t.commit(); |
| 16 | tx.commit(); | ||||||||||||||||||||||
9 | s.close(); | 8 | s.close(); | |||||||||||||||||||||||
10 | s = openSession(); |
| 10 | s = sf.openSession(); | ||||||||||||||||||||||
11 | t = s.beginTransaction(); |
| | |||||||||||||||||||||||
12 | Note note = new Note(); | | ||||||||||||||||||||||||
13 | note.setDescription("a description"); |
| 9 | assertEquals(1, stats.getSessionCloseCount()); | ||||||||||||||||||||||
14 | suite.getNotes().add(note); | | ||||||||||||||||||||||||
| 21 | String hql = "from " + A.class.getName(); | ||||||||||||||||||||||||
| 22 | Query q = s.createQuery(hql); | ||||||||||||||||||||||||
| 23 | q.list(); | ||||||||||||||||||||||||
15 | address.getSuites().clear(); |
| 27 | assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount()); | ||||||||||||||||||||||
16 | s.saveOrUpdate(address); |
| 18 | assertEquals(1, stats.getFlushCount()); | ||||||||||||||||||||||
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()); |
| 26 | assertEquals(1, stats.getQueryExecutionCount()); | ||||||||||||||||||||||
23 | count = (Long)s.createQuery("select count(*) from Note").list().get(0); |
| | |||||||||||||||||||||||
24 | assertEquals(0, count.longValue()); |
| 28 | stats.setStatisticsEnabled(isStats); | ||||||||||||||||||||||
25 | s.delete(address); | | ||||||||||||||||||||||||
26 | t.commit(); | | ||||||||||||||||||||||||
27 | s.close(); | 25 | s.close(); |
Row | Violation |
---|---|
1 | Expression address.setInfo("123 Main St.") is a void method call, and thus it cannot be parameterized |
2 | Expression assertEquals(1,stats.getSessionOpenCount()) is a void method call, and thus it cannot be parameterized |
3 | Expression address.setInfo("123 Main St.") is a void method call, and thus it cannot be parameterized |
4 | Expression assertEquals(1,stats.getSessionOpenCount()) is a void method call, and thus it cannot be parameterized |
5 | Type org.hibernate.test.deletetransient.Address of variable address does not match with type org.hibernate.test.legacy.A of variable a |
6 | Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | 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 |
9 | Expression note.setDescription("a description") is a void method call, and thus it cannot be parameterized |
10 | Expression assertEquals(1,stats.getSessionCloseCount()) is a void method call, and thus it cannot be parameterized |
11 | Expression note.setDescription("a description") is a void method call, and thus it cannot be parameterized |
12 | Expression assertEquals(1,stats.getSessionCloseCount()) is a void method call, and thus it cannot be parameterized |
13 | Expression address.getSuites().clear() is a void method call, and thus it cannot be parameterized |
14 | Expression assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount()) is a void method call, and thus it cannot be parameterized |
15 | Expression address.getSuites().clear() is a void method call, and thus it cannot be parameterized |
16 | Expression assertEquals(1,stats.getQueryStatistics(hql).getExecutionCount()) is a void method call, and thus it cannot be parameterized |
17 | Expression s.saveOrUpdate(address) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
18 | Expression s.saveOrUpdate(address) is a void method call, and thus it cannot be parameterized |
19 | Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized |
20 | Expression s.saveOrUpdate(address) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
21 | Expression s.saveOrUpdate(address) is a void method call, and thus it cannot be parameterized |
22 | Expression assertEquals(1,stats.getFlushCount()) is a void method call, and thus it cannot be parameterized |
23 | Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
24 | Expression sf.openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
25 | 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 |
26 | 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 |
27 | Expression assertEquals(1,stats.getQueryExecutionCount()) is a void method call, and thus it cannot be parameterized |
28 | 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 |
29 | Expression assertEquals(0,count.longValue()) is a void method call, and thus it cannot be parameterized |
30 | Expression stats.setStatisticsEnabled(isStats) is a void method call, and thus it cannot be parameterized |
31 | Expression assertEquals(0,count.longValue()) is a void method call, and thus it cannot be parameterized |
32 | Expression stats.setStatisticsEnabled(isStats) is a void method call, and thus it cannot be parameterized |
33 | Clone fragment #1 returns variables t, s , while Clone fragment #2 returns variables s |