File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/discriminator/DiscriminatorTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/discriminator/DiscriminatorTest.java | |||
Method name: void testLoadSuperclassProxyPolymorphicAccess()
|
Method name: void testLoadSuperclassProxyEvictPolymorphicAccess()
|
|||
Number of AST nodes: 27 | Number of AST nodes: 26 | |||
1 | Session s = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | s.beginTransaction();↵ | 2 | s.beginTransaction();↵ | |
3 | Employee e = new Employee();↵ | 3 | Employee e = new Employee();↵ | |
4 | e.setName( "Steve" );↵ | 4 | e.setName( "Steve" );↵ | |
5 | e.setSex( 'M' );↵ | 5 | e.setSex( 'M' );↵ | |
6 | e.setTitle( "grand poobah" );↵ | 6 | e.setTitle( "grand poobah" );↵ | |
7 | s.save( e );↵ | 7 | s.save( e );↵ | |
8 | s.getTransaction().commit();↵ | 8 | s.getTransaction().commit();↵ | |
9 | s.close();↵ | 9 | s.close();↵ | |
10 | s = openSession();↵ | 10 | s = openSession();↵ | |
11 | s.beginTransaction();↵ | 11 | s.beginTransaction();↵ | |
12 | // load the superclass proxy.↵ | 12 | // load the superclass proxy.↵ | |
13 | Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) );↵ | 13 | Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) );↵ | |
14 | assertTrue( pLoad instanceof HibernateProxy);↵ | 14 | assertTrue( pLoad instanceof HibernateProxy);↵ | |
15 | Person↵ | 15 | // evict the proxy↵ | |
16 | s.evict( pLoad );↵ | |||
16 | pGet = ( Person ) s.get( Person.class, new Long( e.getId() ));↵ | 17 | Employee pGet = ( Employee ) s.get( Person.class, new Long( e.getId() ));↵ | |
17 | Person pQuery = ( Person ) s.createQuery( "from Person where id = :id" )↵ | 18 | Employee pQuery = ( Employee ) s.createQuery( "from Person where id = :id" )↵ | |
18 | .setLong( "id", e.getId() )↵ | 19 | .setLong( "id", e.getId() )↵ | |
19 | .uniqueResult();↵ | 20 | .uniqueResult();↵ | |
20 | Person pCriteria = ( Person ) s.createCriteria( Person.class )↵ | 21 | Employee pCriteria = ( Employee ) s.createCriteria( Person.class )↵ | |
21 | .add( Restrictions.idEq( new Long( e.getId() ) ) )↵ | 22 | .add( Restrictions.idEq( new Long( e.getId() ) ) )↵ | |
22 | .uniqueResult();↵ | 23 | .uniqueResult();↵ | |
23 | // assert that executing the queries polymorphically returns the same proxy↵ | 24 | // assert that executing the queries polymorphically returns the same ↵ | |
24 | assertSame( pLoad, pGet );↵ | 25 | Employee instance↵ | |
25 | assertSame( pLoad, pQuery );↵ | 26 | assertSame( pGet, pQuery );↵ | |
26 | assertSame( pLoad, pCriteria );↵ | 27 | assertSame( pGet, pCriteria );↵ | |
27 | // assert that the proxy is not an instance of Employee↵ | |||
28 | assertFalse( pLoad instanceof Employee );↵ | |||
29 | s.getTransaction().commit();↵ | 28 | s.getTransaction().commit();↵ | |
30 | s.close();↵ | 29 | s.close();↵ | |
31 | s = openSession();↵ | 30 | s = openSession();↵ | |
32 | s.beginTransaction();↵ | 31 | s.beginTransaction();↵ | |
33 | s.delete( e );↵ | 32 | s.delete( e );↵ | |
34 | s.getTransaction().commit();↵ | 33 | s.getTransaction().commit();↵ | |
35 | s.close(); | 34 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 1 |
Number of non-refactorable cases | 0 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 179 |
Number of mapped statements | 25 |
Number of unmapped statements in the first code fragment | 2 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Session s = openSession(); | 1 | Session s = openSession(); | ||||||||||||||||||||||||
2 | s.beginTransaction(); | 2 | s.beginTransaction(); | ||||||||||||||||||||||||
3 | Employee e = new Employee(); | 3 | Employee e = new Employee(); | ||||||||||||||||||||||||
4 | e.setName("Steve"); | 4 | e.setName("Steve"); | ||||||||||||||||||||||||
5 | e.setSex('M'); | 5 | e.setSex('M'); | ||||||||||||||||||||||||
6 | e.setTitle("grand poobah"); | 6 | e.setTitle("grand poobah"); | ||||||||||||||||||||||||
7 | s.save(e); | 7 | s.save(e); | ||||||||||||||||||||||||
8 | s.getTransaction().commit(); | 8 | s.getTransaction().commit(); | ||||||||||||||||||||||||
9 | s.close(); | 9 | s.close(); | ||||||||||||||||||||||||
10 | s = openSession(); | 10 | s = openSession(); | ||||||||||||||||||||||||
11 | s.beginTransaction(); | 11 | s.beginTransaction(); | ||||||||||||||||||||||||
12 | Person pLoad = (Person)s.load(Person.class, new Long(e.getId())); | 12 | Person pLoad = (Person)s.load(Person.class, new Long(e.getId())); | ||||||||||||||||||||||||
13 | assertTrue(pLoad instanceof HibernateProxy); | 13 | assertTrue(pLoad instanceof HibernateProxy); | ||||||||||||||||||||||||
|
| 14 | s.evict(pLoad); | ||||||||||||||||||||||||
14 | Person pGet = (Person)s.get(Person.class, new Long(e.getId())); |
| 15 | Employee pGet = (Employee)s.get(Person.class, new Long(e.getId())); | |||||||||||||||||||||||
15 | Person pQuery = (Person)s.createQuery("from Person where id = :id").setLong("id", e.getId()).uniqueResult(); |
| 16 | Employee pQuery = (Employee)s.createQuery("from Person where id = :id").setLong("id", e.getId()).uniqueResult(); | |||||||||||||||||||||||
16 | Person pCriteria = (Person)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult(); |
| 17 | Employee pCriteria = (Employee)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult(); | |||||||||||||||||||||||
17 | assertSame(pLoad, pGet); |
| 19 | assertSame(pGet, pCriteria); | |||||||||||||||||||||||
18 | assertSame(pLoad, pQuery); |
| 18 | assertSame(pGet, pQuery); | |||||||||||||||||||||||
19 | assertSame(pLoad, pCriteria); |
| | ||||||||||||||||||||||||
20 | assertFalse(pLoad instanceof Employee); |
| | ||||||||||||||||||||||||
21 | s.getTransaction().commit(); | 20 | s.getTransaction().commit(); | ||||||||||||||||||||||||
22 | s.close(); | 21 | s.close(); | ||||||||||||||||||||||||
23 | s = openSession(); | 22 | s = openSession(); | ||||||||||||||||||||||||
24 | s.beginTransaction(); | 23 | s.beginTransaction(); | ||||||||||||||||||||||||
25 | s.delete(e); | 24 | s.delete(e); | ||||||||||||||||||||||||
26 | s.getTransaction().commit(); | 25 | s.getTransaction().commit(); | ||||||||||||||||||||||||
27 | s.close(); | 26 | s.close(); |
Row | Violation |
---|---|
1 | Unmatched statement s.evict(pLoad); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Expression (Person)s.get(Person.class,new Long(e.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | Expression (Employee)s.get(Person.class,new Long(e.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression (Person)s.createQuery("from Person where id = :id").setLong("id",e.getId()).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Expression (Employee)s.createQuery("from Person where id = :id").setLong("id",e.getId()).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression (Person)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression (Employee)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression pLoad cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted |
11 | Expression pCriteria cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression pLoad cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted |
14 | Unmatched statement assertSame(pLoad,pCriteria); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
15 | Unmatched statement assertFalse(pLoad instanceof Employee); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |