public class TuplizerDynamicEntityTest extends FunctionalTestCase { public TuplizerDynamicEntityTest(String x) { super( x ); } public String[] getMappings() { return new String[] { "dynamicentity/tuplizer/Customer.hbm.xml" }; } public void configure(Configuration cfg) { super.configure( cfg ); cfg.setInterceptor( new EntityNameInterceptor() ); } public static TestSuite suite() { return new FunctionalTestClassTestSuite( TuplizerDynamicEntityTest.class ); } public void testIt() { // Test saving these dyna-proxies Session session = openSession(); session.beginTransaction(); Company company = ProxyHelper.newCompanyProxy(); company.setName( "acme" ); session.save( company ); Customer customer = ProxyHelper.newCustomerProxy(); customer.setName( "Steve" ); customer.setCompany( company ); Address address = ProxyHelper.newAddressProxy(); address.setStreet( "somewhere over the rainbow" ); address.setCity( "lawerence, kansas" ); address.setPostalCode( "toto"); customer.setAddress( address ); customer.setFamily( new HashSet() ); Person son = ProxyHelper.newPersonProxy(); son.setName( "son" ); customer.getFamily().add( son ); Person wife = ProxyHelper.newPersonProxy(); wife.setName( "wife" ); customer.getFamily().add( wife ); session.save( customer ); session.getTransaction().commit(); session.close(); assertNotNull( "company id not assigned", company.getId() ); assertNotNull( "customer id not assigned", customer.getId() ); assertNotNull( "address id not assigned", address.getId() ); assertNotNull( "son:Person id not assigned", son.getId() ); assertNotNull( "wife:Person id not assigned", wife.getId() ); // Test loading these dyna-proxies, along with flush processing session = openSession(); session.beginTransaction(); customer = ( Customer ) session.load( Customer.class, customer.getId() ); assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer ) ); customer.setName( "other" ); session.flush(); assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer.getCompany() ) ); session.refresh( customer ); assertEquals( "name not updated", "other", customer.getName() ); assertEquals( "company association not correct", "acme", customer.getCompany().getName() ); session.getTransaction().commit(); session.close(); // Test detached entity re-attachment with these dyna-proxies customer.setName( "Steve" ); session = openSession(); session.beginTransaction(); session.update( customer ); session.flush(); session.refresh( customer ); assertEquals( "name not updated", "Steve", customer.getName() ); session.getTransaction().commit(); session.close(); // Test querying session = openSession(); session.beginTransaction(); int count = session.createQuery( "from Customer" ).list().size(); assertEquals( "querying dynamic entity", 1, count ); session.clear(); count = session.createQuery( "from Person" ).list().size(); assertEquals( "querying dynamic entity", 3, count ); session.getTransaction().commit(); session.close(); // test deleteing session = openSession(); session.beginTransaction(); session.delete( company ); session.delete( customer ); session.getTransaction().commit(); session.close();
public class ImprovedTuplizerDynamicEntityTest extends FunctionalTestCase { public ImprovedTuplizerDynamicEntityTest(String x) { super( x ); } public String[] getMappings() { return new String[] { "dynamicentity/tuplizer2/Customer.hbm.xml" }; } public void configure(Configuration cfg) { super.configure( cfg ); cfg.getEntityTuplizerFactory().registerDefaultTuplizerClass( EntityMode.POJO, MyEntityTuplizer.class ); } public static TestSuite suite() { return new FunctionalTestClassTestSuite( ImprovedTuplizerDynamicEntityTest.class ); } public void testIt() { // Test saving these dyna-proxies Session session = openSession(); session.beginTransaction(); Company company = ProxyHelper.newCompanyProxy(); company.setName( "acme" ); session.save( company ); Customer customer = ProxyHelper.newCustomerProxy(); customer.setName( "Steve" ); customer.setCompany( company ); Address address = ProxyHelper.newAddressProxy(); address.setStreet( "somewhere over the rainbow" ); address.setCity( "lawerence, kansas" ); address.setPostalCode( "toto"); customer.setAddress( address ); customer.setFamily( new HashSet() ); Person son = ProxyHelper.newPersonProxy(); son.setName( "son" ); customer.getFamily().add( son ); Person wife = ProxyHelper.newPersonProxy(); wife.setName( "wife" ); customer.getFamily().add( wife ); session.save( customer ); session.getTransaction().commit(); session.close(); assertNotNull( "company id not assigned", company.getId() ); assertNotNull( "customer id not assigned", customer.getId() ); assertNotNull( "address id not assigned", address.getId() ); assertNotNull( "son:Person id not assigned", son.getId() ); assertNotNull( "wife:Person id not assigned", wife.getId() ); // Test loading these dyna-proxies, along with flush processing session = openSession(); session.beginTransaction(); customer = ( Customer ) session.load( Customer.class, customer.getId() ); assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer ) ); customer.setName( "other" ); session.flush(); assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer.getCompany() ) ); session.refresh( customer ); assertEquals( "name not updated", "other", customer.getName() ); assertEquals( "company association not correct", "acme", customer.getCompany().getName() ); session.getTransaction().commit(); session.close(); // Test detached entity re-attachment with these dyna-proxies customer.setName( "Steve" ); session = openSession(); session.beginTransaction(); session.update( customer ); session.flush(); session.refresh( customer ); assertEquals( "name not updated", "Steve", customer.getName() ); session.getTransaction().commit(); session.close(); // Test querying session = openSession(); session.beginTransaction(); int count = session.createQuery( "from Customer" ).list().size(); assertEquals( "querying dynamic entity", 1, count ); session.clear(); count = session.createQuery( "from Person" ).list().size(); assertEquals( "querying dynamic entity", 3, count ); session.getTransaction().commit(); session.close(); // test deleteing session = openSession(); session.beginTransaction(); session.delete( company ); session.delete( customer ); session.getTransaction().commit(); session.close();
Clone fragments detected by clone detection tool
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: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class TuplizerDynamicEntityTest extends FunctionalTestCase {
1
public class ImprovedTuplizerDynamicEntityTest extends FunctionalTestCase {
2
	public TuplizerDynamicEntityTest(String x) {
2
	public ImprovedTuplizerDynamicEntityTest(String x) {
3
		super( x );
3
		super( x );
4
	}
4
	}
5
	public String[] getMappings() {
5
	public String[] getMappings() {
6
		return new String[] { "dynamicentity/tuplizer/Customer.hbm.xml" };
6
		return new String[] { "dynamicentity/tuplizer2/Customer.hbm.xml" };
7
	}
7
	}
8
	public void configure(Configuration cfg) {
8
	public void configure(Configuration cfg) {
9
		super.configure( cfg );
9
		super.configure( cfg );
10
		cfg.setInterceptor( new EntityNameInterceptor() );
10
		cfg.getEntityTuplizerFactory().registerDefaultTuplizerClass( EntityMode.POJO, MyEntityTuplizer.class );
11
	}
11
	}
12
	public static TestSuite suite() {
12
	public static TestSuite suite() {
13
		return new FunctionalTestClassTestSuite( TuplizerDynamicEntityTest.class );
13
		return new FunctionalTestClassTestSuite( ImprovedTuplizerDynamicEntityTest.class );
14
	}
14
	}
15
	public void testIt() {
15
	public void testIt() {
16
		// Test saving these dyna-proxies
16
		// Test saving these dyna-proxies
17
		Session session = openSession();
17
		Session session = openSession();
18
		session.beginTransaction();
18
		session.beginTransaction();
19
		Company company = ProxyHelper.newCompanyProxy();
19
		Company company = ProxyHelper.newCompanyProxy();
20
		company.setName( "acme" );
20
		company.setName( "acme" );
21
		session.save( company );
21
		session.save( company );
22
		Customer customer = ProxyHelper.newCustomerProxy();
22
		Customer customer = ProxyHelper.newCustomerProxy();
23
		customer.setName( "Steve" );
23
		customer.setName( "Steve" );
24
		customer.setCompany( company );
24
		customer.setCompany( company );
25
		Address address = ProxyHelper.newAddressProxy();
25
		Address address = ProxyHelper.newAddressProxy();
26
		address.setStreet( "somewhere over the rainbow" );
26
		address.setStreet( "somewhere over the rainbow" );
27
		address.setCity( "lawerence, kansas" );
27
		address.setCity( "lawerence, kansas" );
28
		address.setPostalCode( "toto");
28
		address.setPostalCode( "toto");
29
		customer.setAddress( address );
29
		customer.setAddress( address );
30
		customer.setFamily( new HashSet() );
30
		customer.setFamily( new HashSet() );
31
		Person son = ProxyHelper.newPersonProxy();
31
		Person son = ProxyHelper.newPersonProxy();
32
		son.setName( "son" );
32
		son.setName( "son" );
33
		customer.getFamily().add( son );
33
		customer.getFamily().add( son );
34
		Person wife = ProxyHelper.newPersonProxy();
34
		Person wife = ProxyHelper.newPersonProxy();
35
		wife.setName( "wife" );
35
		wife.setName( "wife" );
36
		customer.getFamily().add( wife );
36
		customer.getFamily().add( wife );
37
		session.save( customer );
37
		session.save( customer );
38
		session.getTransaction().commit();
38
		session.getTransaction().commit();
39
		session.close();
39
		session.close();
40
		assertNotNull( "company id not assigned", company.getId() );
40
		assertNotNull( "company id not assigned", company.getId() );
41
		assertNotNull( "customer id not assigned", customer.getId() );
41
		assertNotNull( "customer id not assigned", customer.getId() );
42
		assertNotNull( "address id not assigned", address.getId() );
42
		assertNotNull( "address id not assigned", address.getId() );
43
		assertNotNull( "son:Person id not assigned", son.getId() );
43
		assertNotNull( "son:Person id not assigned", son.getId() );
44
		assertNotNull( "wife:Person id not assigned", wife.getId() );
44
		assertNotNull( "wife:Person id not assigned", wife.getId() );
45
		// Test loading these dyna-proxies, along with flush processing
45
		// Test loading these dyna-proxies, along with flush processing
46
		session = openSession();
46
		session = openSession();
47
		session.beginTransaction();
47
		session.beginTransaction();
48
		customer = ( Customer ) session.load( Customer.class, customer.getId() );
48
		customer = ( Customer ) session.load( Customer.class, customer.getId() );
49
		assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer ) );
49
		assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer ) );
50
		customer.setName( "other" );
50
		customer.setName( "other" );
51
		session.flush();
51
		session.flush();
52
		assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer.getCompany() ) );
52
		assertFalse( "should-be-proxy was initialized", Hibernate.isInitialized( customer.getCompany() ) );
53
		session.refresh( customer );
53
		session.refresh( customer );
54
		assertEquals( "name not updated", "other", customer.getName() );
54
		assertEquals( "name not updated", "other", customer.getName() );
55
		assertEquals( "company association not correct", "acme", customer.getCompany().getName() );
55
		assertEquals( "company association not correct", "acme", customer.getCompany().getName() );
56
		session.getTransaction().commit();
56
		session.getTransaction().commit();
57
		session.close();
57
		session.close();
58
		// Test detached entity re-attachment with these dyna-proxies
58
		// Test detached entity re-attachment with these dyna-proxies
59
		customer.setName( "Steve" );
59
		customer.setName( "Steve" );
60
		session = openSession();
60
		session = openSession();
61
		session.beginTransaction();
61
		session.beginTransaction();
62
		session.update( customer );
62
		session.update( customer );
63
		session.flush();
63
		session.flush();
64
		session.refresh( customer );
64
		session.refresh( customer );
65
		assertEquals( "name not updated", "Steve", customer.getName() );
65
		assertEquals( "name not updated", "Steve", customer.getName() );
66
		session.getTransaction().commit();
66
		session.getTransaction().commit();
67
		session.close();
67
		session.close();
68
		// Test querying
68
		// Test querying
69
		session = openSession();
69
		session = openSession();
70
		session.beginTransaction();
70
		session.beginTransaction();
71
		int count = session.createQuery( "from Customer" ).list().size();
71
		int count = session.createQuery( "from Customer" ).list().size();
72
		assertEquals( "querying dynamic entity", 1, count );
72
		assertEquals( "querying dynamic entity", 1, count );
73
		session.clear();
73
		session.clear();
74
		count = session.createQuery( "from Person" ).list().size();
74
		count = session.createQuery( "from Person" ).list().size();
75
		assertEquals( "querying dynamic entity", 3, count );
75
		assertEquals( "querying dynamic entity", 3, count );
76
		session.getTransaction().commit();
76
		session.getTransaction().commit();
77
		session.close();
77
		session.close();
78
		// test deleteing
78
		// test deleteing
79
		session = openSession();
79
		session = openSession();
80
		session.beginTransaction();
80
		session.beginTransaction();
81
		session.delete( company );
81
		session.delete( company );
82
		session.delete( customer );
82
		session.delete( customer );
83
		session.getTransaction().commit();
83
		session.getTransaction().commit();
84
		session.close();
84
		session.close();
85
	
85
	
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0