File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java | |||
Method name: void testSelectClauseImplicitJoinWithIterate()
|
Method name: void testSelectClauseImplicitJoin()
|
|||
Number of AST nodes: 29 | Number of AST nodes: 29 | |||
1 | Session s = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | Transaction t = s.beginTransaction();↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | Zoo zoo = new Zoo();↵ | 3 | Zoo zoo = new Zoo();↵ | |
4 | zoo.setName("The Zoo");↵ | 4 | zoo.setName("The Zoo");↵ | |
5 | zoo.setMammals( new HashMap() );↵ | 5 | zoo.setMammals( new HashMap() );↵ | |
6 | zoo.setAnimals( new HashMap() );↵ | 6 | zoo.setAnimals( new HashMap() );↵ | |
7 | Mammal plat = new Mammal();↵ | 7 | Mammal plat = new Mammal();↵ | |
8 | plat.setBodyWeight( 11f );↵ | 8 | plat.setBodyWeight( 11f );↵ | |
9 | plat.setDescription( "Platypus" );↵ | 9 | plat.setDescription( "Platypus" );↵ | |
10 | plat.setZoo(zoo);↵ | 10 | plat.setZoo(zoo);↵ | |
11 | plat.setSerialNumber("plat123");↵ | 11 | plat.setSerialNumber("plat123");↵ | |
12 | zoo.getMammals().put("Platypus", plat);↵ | 12 | zoo.getMammals().put("Platypus", plat);↵ | |
13 | zoo.getAnimals().put("plat123", plat);↵ | 13 | zoo.getAnimals().put("plat123", plat);↵ | |
14 | s.persist( plat );↵ | 14 | s.persist( plat );↵ | |
15 | s.persist(zoo);↵ | 15 | s.persist(zoo);↵ | |
16 | s.flush();↵ | 16 | s.flush();↵ | |
17 | s.clear();↵ | 17 | s.clear();↵ | |
18 | Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");↵ | 18 | Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");↵ | |
19 | Type type = q.getReturnTypes()[0];↵ | 19 | Type type = q.getReturnTypes()[0];↵ | |
20 | assertTrue( type instanceof ManyToOneType );↵ | 20 | assertTrue( type instanceof ManyToOneType );↵ | |
21 | assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );↵ | 21 | assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" );↵ | |
22 | zoo = (Zoo) q↵ | 22 | zoo = (Zoo) q↵ | |
23 | .iterate().next();↵ | 23 | .list().get(0);↵ | |
24 | assertEquals( zoo.getMammals().size(), 1 );↵ | 24 | assertEquals( zoo.getMammals().size(), 1 );↵ | |
25 | assertEquals( zoo.getAnimals().size(), 1 );↵ | 25 | assertEquals( zoo.getAnimals().size(), 1 );↵ | |
26 | s.clear();↵ | 26 | s.clear();↵ | |
27 | s.delete(plat);↵ | 27 | s.delete(plat);↵ | |
28 | s.delete(zoo);↵ | 28 | s.delete(zoo);↵ | |
29 | t.commit();↵ | 29 | t.commit();↵ | |
30 | s.close(); | 30 |
| |
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 declared in the same class |
Number of node comparisons | 365 |
Number of mapped statements | 28 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 2 |
ID | Statement | ID | Statement | ||||
---|---|---|---|---|---|---|---|
1 | Session s = openSession(); | 1 | Session s = openSession(); | ||||
2 | Transaction t = s.beginTransaction(); | 2 | Transaction t = s.beginTransaction(); | ||||
3 | Zoo zoo = new Zoo(); | 3 | Zoo zoo = new Zoo(); | ||||
4 | zoo.setName("The Zoo"); | 4 | zoo.setName("The Zoo"); | ||||
5 | zoo.setMammals(new HashMap()); | 5 | zoo.setMammals(new HashMap()); | ||||
6 | zoo.setAnimals(new HashMap()); | 6 | zoo.setAnimals(new HashMap()); | ||||
7 | Mammal plat = new Mammal(); | 7 | Mammal plat = new Mammal(); | ||||
8 | plat.setBodyWeight(11f); | 8 | plat.setBodyWeight(11f); | ||||
9 | plat.setDescription("Platypus"); | 9 | plat.setDescription("Platypus"); | ||||
10 | plat.setZoo(zoo); | 10 | plat.setZoo(zoo); | ||||
11 | plat.setSerialNumber("plat123"); | 11 | plat.setSerialNumber("plat123"); | ||||
12 | zoo.getMammals().put("Platypus", plat); | 12 | zoo.getMammals().put("Platypus", plat); | ||||
13 | zoo.getAnimals().put("plat123", plat); | 13 | zoo.getAnimals().put("plat123", plat); | ||||
14 | s.persist(plat); | 14 | s.persist(plat); | ||||
15 | s.persist(zoo); | 15 | s.persist(zoo); | ||||
16 | s.flush(); | 16 | s.flush(); | ||||
17 | s.clear(); | 17 | s.clear(); | ||||
18 | Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null"); | 18 | Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null"); | ||||
19 | Type type = q.getReturnTypes()[0]; | 19 | Type type = q.getReturnTypes()[0]; | ||||
20 | assertTrue(type instanceof ManyToOneType); | 20 | assertTrue(type instanceof ManyToOneType); | ||||
21 | assertEquals(((ManyToOneType)type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo"); | 21 | assertEquals(((ManyToOneType)type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo"); | ||||
|
| 22 | zoo = (Zoo)q.list().get(0); | ||||
22 | zoo = (Zoo)q.iterate().next(); |
| | ||||
23 | assertEquals(zoo.getMammals().size(), 1); | 23 | assertEquals(zoo.getMammals().size(), 1); | ||||
24 | assertEquals(zoo.getAnimals().size(), 1); | 24 | assertEquals(zoo.getAnimals().size(), 1); | ||||
25 | s.clear(); | 25 | s.clear(); | ||||
26 | s.delete(plat); | 26 | s.delete(plat); | ||||
27 | s.delete(zoo); | 27 | s.delete(zoo); | ||||
28 | t.commit(); | 28 | t.commit(); | ||||
29 | s.close(); | 29 | s.close(); |
Row | Violation |
---|---|
1 | Unmatched statement zoo=(Zoo)q.list().get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement zoo=(Zoo)q.iterate().next(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Clone fragment #1 returns variables zoo, q , while Clone fragment #2 returns variables zoo, q |