File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/dynamicentity/tuplizer/TuplizerDynamicEntityTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/dynamicentity/tuplizer2/ImprovedTuplizerDynamicEntityTest.java | |||
Method name: void testIt()
|
Method name: void testIt()
|
|||
Number of AST nodes: 64 | Number of AST nodes: 64 | |||
1 | Session session = openSession();↵ | 1 | Session session = openSession();↵ | |
2 | session.beginTransaction();↵ | 2 | session.beginTransaction();↵ | |
3 | Company company = ProxyHelper.newCompanyProxy();↵ | 3 | Company company = ProxyHelper.newCompanyProxy();↵ | |
4 | company.setName( "acme" );↵ | 4 | company.setName( "acme" );↵ | |
5 | session.save( company );↵ | 5 | session.save( company );↵ | |
6 | Customer customer = ProxyHelper.newCustomerProxy();↵ | 6 | Customer customer = ProxyHelper.newCustomerProxy();↵ | |
7 | customer.setName( "Steve" );↵ | 7 | customer.setName( "Steve" );↵ | |
8 | customer.setCompany( company );↵ | 8 | customer.setCompany( company );↵ | |
9 | Address address = ProxyHelper.newAddressProxy();↵ | 9 | Address address = ProxyHelper.newAddressProxy();↵ | |
10 | address.setStreet( "somewhere over the rainbow" );↵ | 10 | address.setStreet( "somewhere over the rainbow" );↵ | |
11 | address.setCity( "lawerence, kansas" );↵ | 11 | address.setCity( "lawerence, kansas" );↵ | |
12 | address.setPostalCode( "toto");↵ | 12 | address.setPostalCode( "toto");↵ | |
13 | customer.setAddress( address );↵ | 13 | customer.setAddress( address );↵ | |
14 | customer.setFamily( new HashSet() );↵ | 14 | customer.setFamily( new HashSet() );↵ | |
15 | Person son = ProxyHelper.newPersonProxy();↵ | 15 | Person son = ProxyHelper.newPersonProxy();↵ | |
16 | son.setName( "son" );↵ | 16 | son.setName( "son" );↵ | |
17 | customer.getFamily().add( son );↵ | 17 | customer.getFamily().add( son );↵ | |
18 | Person wife = ProxyHelper.newPersonProxy();↵ | 18 | Person wife = ProxyHelper.newPersonProxy();↵ | |
19 | wife.setName( "wife" );↵ | 19 | wife.setName( "wife" );↵ | |
20 | customer.getFamily().add( wife );↵ | 20 | customer.getFamily().add( wife );↵ | |
21 | session.save( customer );↵ | 21 | session.save( customer );↵ | |
22 | session.getTransaction().commit();↵ | 22 | session.getTransaction().commit();↵ | |
23 | session.close();↵ | 23 | session.close();↵ | |
24 | assertNotNull( "company id not assigned", company.getId() );↵ | 24 | assertNotNull( "company id not assigned", company.getId() );↵ | |
25 | assertNotNull( "customer id not assigned", customer.getId() );↵ | 25 | assertNotNull( "customer id not assigned", customer.getId() );↵ | |
26 | assertNotNull( "address id not assigned", address.getId() );↵ | 26 | assertNotNull( "address id not assigned", address.getId() );↵ | |
27 | assertNotNull( "son:Person id not assigned", son.getId() );↵ | 27 | assertNotNull( "son:Person id not assigned", son.getId() );↵ | |
28 | assertNotNull( "wife:Person id not assigned", wife.getId() );↵ | 28 | assertNotNull( "wife:Person id not assigned", wife.getId() );↵ | |
29 | // Test loading these dyna-proxies, along with flush processing↵ | 29 | // Test loading these dyna-proxies, along with flush processing↵ | |
30 | session = openSession();↵ | 30 | session = openSession();↵ | |
31 | session.beginTransaction();↵ | 31 | session.beginTransaction();↵ | |
32 | customer = ( Customer ) session.load( Customer.class, customer.getId() );↵ | 32 | customer = ( Customer ) session.load( Customer.class, customer.getId() );↵ | |
33 | assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer ) );↵ | 33 | assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer ) );↵ | |
34 | customer.setName( "other" );↵ | 34 | customer.setName( "other" );↵ | |
35 | session.flush();↵ | 35 | session.flush();↵ | |
36 | assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer.getCompany() ) );↵ | 36 | assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer.getCompany() ) );↵ | |
37 | session.refresh( customer );↵ | 37 | session.refresh( customer );↵ | |
38 | assertEquals( "name not updated", "other", customer.getName() );↵ | 38 | assertEquals( "name not updated", "other", customer.getName() );↵ | |
39 | assertEquals( "company association not correct", "acme", customer.getCompany().getName() );↵ | 39 | assertEquals( "company association not correct", "acme", customer.getCompany().getName() );↵ | |
40 | session.getTransaction().commit();↵ | 40 | session.getTransaction().commit();↵ | |
41 | session.close();↵ | 41 | session.close();↵ | |
42 | // Test detached entity re-attachment with these dyna-proxies↵ | 42 | // Test detached entity re-attachment with these dyna-proxies↵ | |
43 | customer.setName( "Steve" );↵ | 43 | customer.setName( "Steve" );↵ | |
44 | session = openSession();↵ | 44 | session = openSession();↵ | |
45 | session.beginTransaction();↵ | 45 | session.beginTransaction();↵ | |
46 | session.update( customer );↵ | 46 | session.update( customer );↵ | |
47 | session.flush();↵ | 47 | session.flush();↵ | |
48 | session.refresh( customer );↵ | 48 | session.refresh( customer );↵ | |
49 | assertEquals( "name not updated", "Steve", customer.getName() );↵ | 49 | assertEquals( "name not updated", "Steve", customer.getName() );↵ | |
50 | session.getTransaction().commit();↵ | 50 | session.getTransaction().commit();↵ | |
51 | session.close();↵ | 51 | session.close();↵ | |
52 | // Test querying↵ | 52 | // Test querying↵ | |
53 | session = openSession();↵ | 53 | session = openSession();↵ | |
54 | session.beginTransaction();↵ | 54 | session.beginTransaction();↵ | |
55 | int count = session.createQuery( "from Customer" ).list().size();↵ | 55 | int count = session.createQuery( "from Customer" ).list().size();↵ | |
56 | assertEquals( "querying dynamic entity", 1, count );↵ | 56 | assertEquals( "querying dynamic entity", 1, count );↵ | |
57 | session.clear();↵ | 57 | session.clear();↵ | |
58 | count = session.createQuery( "from Person" ).list().size();↵ | 58 | count = session.createQuery( "from Person" ).list().size();↵ | |
59 | assertEquals( "querying dynamic entity", 3, count );↵ | 59 | assertEquals( "querying dynamic entity", 3, count );↵ | |
60 | session.getTransaction().commit();↵ | 60 | session.getTransaction().commit();↵ | |
61 | session.close();↵ | 61 | session.close();↵ | |
62 | // test deleteing↵ | 62 | // test deleteing↵ | |
63 | session = openSession();↵ | 63 | session = openSession();↵ | |
64 | session.beginTransaction();↵ | 64 | session.beginTransaction();↵ | |
65 | session.delete( company );↵ | 65 | session.delete( company );↵ | |
66 | session.delete( customer );↵ | 66 | session.delete( customer );↵ | |
67 | session.getTransaction().commit();↵ | 67 | session.getTransaction().commit();↵ | |
68 | session.close(); | 68 |
| |
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 in different classes having the same super class |
Number of node comparisons | 1624 |
Number of mapped statements | 64 |
Number of unmapped statements in the first code fragment | 0 |
Number of unmapped statements in the second code fragment | 0 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 1 |
ID | Statement | ID | Statement | |
---|---|---|---|---|
1 | Session session = openSession(); | 1 | Session session = openSession(); | |
2 | session.beginTransaction(); | 2 | session.beginTransaction(); | |
3 | Company company = ProxyHelper.newCompanyProxy(); | 3 | Company company = ProxyHelper.newCompanyProxy(); | |
4 | company.setName("acme"); | 4 | company.setName("acme"); | |
5 | session.save(company); | 5 | session.save(company); | |
6 | Customer customer = ProxyHelper.newCustomerProxy(); | 6 | Customer customer = ProxyHelper.newCustomerProxy(); | |
7 | customer.setName("Steve"); | 7 | customer.setName("Steve"); | |
8 | customer.setCompany(company); | 8 | customer.setCompany(company); | |
9 | Address address = ProxyHelper.newAddressProxy(); | 9 | Address address = ProxyHelper.newAddressProxy(); | |
10 | address.setStreet("somewhere over the rainbow"); | 10 | address.setStreet("somewhere over the rainbow"); | |
11 | address.setCity("lawerence, kansas"); | 11 | address.setCity("lawerence, kansas"); | |
12 | address.setPostalCode("toto"); | 12 | address.setPostalCode("toto"); | |
13 | customer.setAddress(address); | 13 | customer.setAddress(address); | |
14 | customer.setFamily(new HashSet()); | 14 | customer.setFamily(new HashSet()); | |
15 | Person son = ProxyHelper.newPersonProxy(); | 15 | Person son = ProxyHelper.newPersonProxy(); | |
16 | son.setName("son"); | 16 | son.setName("son"); | |
17 | customer.getFamily().add(son); | 17 | customer.getFamily().add(son); | |
18 | Person wife = ProxyHelper.newPersonProxy(); | 18 | Person wife = ProxyHelper.newPersonProxy(); | |
19 | wife.setName("wife"); | 19 | wife.setName("wife"); | |
20 | customer.getFamily().add(wife); | 20 | customer.getFamily().add(wife); | |
21 | session.save(customer); | 21 | session.save(customer); | |
22 | session.getTransaction().commit(); | 22 | session.getTransaction().commit(); | |
23 | session.close(); | 23 | session.close(); | |
24 | assertNotNull("company id not assigned", company.getId()); | 24 | assertNotNull("company id not assigned", company.getId()); | |
25 | assertNotNull("customer id not assigned", customer.getId()); | 25 | assertNotNull("customer id not assigned", customer.getId()); | |
26 | assertNotNull("address id not assigned", address.getId()); | 26 | assertNotNull("address id not assigned", address.getId()); | |
27 | assertNotNull("son:Person id not assigned", son.getId()); | 27 | assertNotNull("son:Person id not assigned", son.getId()); | |
28 | assertNotNull("wife:Person id not assigned", wife.getId()); | 28 | assertNotNull("wife:Person id not assigned", wife.getId()); | |
29 | session = openSession(); | 29 | session = openSession(); | |
30 | session.beginTransaction(); | 30 | session.beginTransaction(); | |
31 | customer = (Customer)session.load(Customer.class, customer.getId()); | 31 | customer = (Customer)session.load(Customer.class, customer.getId()); | |
32 | assertFalse("should-be-proxy was initialized", Hibernate.isInitialized(customer)); | 32 | assertFalse("should-be-proxy was initialized", Hibernate.isInitialized(customer)); | |
33 | customer.setName("other"); | 33 | customer.setName("other"); | |
34 | session.flush(); | 34 | session.flush(); | |
35 | assertFalse("should-be-proxy was initialized", Hibernate.isInitialized(customer.getCompany())); | 35 | assertFalse("should-be-proxy was initialized", Hibernate.isInitialized(customer.getCompany())); | |
36 | session.refresh(customer); | 36 | session.refresh(customer); | |
37 | assertEquals("name not updated", "other", customer.getName()); | 37 | assertEquals("name not updated", "other", customer.getName()); | |
38 | assertEquals("company association not correct", "acme", customer.getCompany().getName()); | 38 | assertEquals("company association not correct", "acme", customer.getCompany().getName()); | |
39 | session.getTransaction().commit(); | 39 | session.getTransaction().commit(); | |
40 | session.close(); | 40 | session.close(); | |
41 | customer.setName("Steve"); | 41 | customer.setName("Steve"); | |
42 | session = openSession(); | 42 | session = openSession(); | |
43 | session.beginTransaction(); | 43 | session.beginTransaction(); | |
44 | session.update(customer); | 44 | session.update(customer); | |
45 | session.flush(); | 45 | session.flush(); | |
46 | session.refresh(customer); | 46 | session.refresh(customer); | |
47 | assertEquals("name not updated", "Steve", customer.getName()); | 47 | assertEquals("name not updated", "Steve", customer.getName()); | |
48 | session.getTransaction().commit(); | 48 | session.getTransaction().commit(); | |
49 | session.close(); | 49 | session.close(); | |
50 | session = openSession(); | 50 | session = openSession(); | |
51 | session.beginTransaction(); | 51 | session.beginTransaction(); | |
52 | int count = session.createQuery("from Customer").list().size(); | 52 | int count = session.createQuery("from Customer").list().size(); | |
53 | assertEquals("querying dynamic entity", 1, count); | 53 | assertEquals("querying dynamic entity", 1, count); | |
54 | session.clear(); | 54 | session.clear(); | |
55 | count = session.createQuery("from Person").list().size(); | 55 | count = session.createQuery("from Person").list().size(); | |
56 | assertEquals("querying dynamic entity", 3, count); | 56 | assertEquals("querying dynamic entity", 3, count); | |
57 | session.getTransaction().commit(); | 57 | session.getTransaction().commit(); | |
58 | session.close(); | 58 | session.close(); | |
59 | session = openSession(); | 59 | session = openSession(); | |
60 | session.beginTransaction(); | 60 | session.beginTransaction(); | |
61 | session.delete(company); | 61 | session.delete(company); | |
62 | session.delete(customer); | 62 | session.delete(customer); | |
63 | session.getTransaction().commit(); | 63 | session.getTransaction().commit(); | |
64 | session.close(); | 64 | session.close(); |
Row | Violation |
---|