public class AuctionTest extends FunctionalTestCase { public AuctionTest(String str) { super( str ); } public String[] getMappings() { return new String[] { "bidi/Auction.hbm.xml" }; } public static Test suite() { return new FunctionalTestClassTestSuite( AuctionTest.class ); } public void testLazy() { if ( getDialect() instanceof PostgreSQLDialect ) { return; //doesn't like boolean=1 } Session s = openSession(); Transaction t = s.beginTransaction(); Auction a = new Auction(); a.setDescription( "an auction for something" ); a.setEnd( new Date() ); Bid b = new Bid(); b.setAmount( new BigDecimal( 123.34 ).setScale( 19, BigDecimal.ROUND_DOWN ) ); b.setSuccessful( true ); b.setDatetime( new Date() ); b.setItem( a ); a.getBids().add( b ); a.setSuccessfulBid( b ); s.persist( b ); t.commit(); s.close(); Long aid = a.getId(); Long bid = b.getId(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); assertFalse( Hibernate.isInitialized( b ) ); a = ( Auction ) s.get( Auction.class, aid ); assertFalse( Hibernate.isInitialized( a.getBids() ) ); assertTrue( Hibernate.isInitialized( a.getSuccessfulBid() ) ); assertSame( a.getBids().iterator().next(), b ); assertSame( b, a.getSuccessfulBid() ); assertTrue( Hibernate.isInitialized( b ) ); assertTrue( b.isSuccessful() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); assertFalse( Hibernate.isInitialized( b ) ); a = ( Auction ) s.createQuery( "from Auction a left join fetch a.bids" ).uniqueResult(); assertTrue( Hibernate.isInitialized( b ) ); assertTrue( Hibernate.isInitialized( a.getBids() ) ); assertSame( b, a.getSuccessfulBid() ); assertSame( a.getBids().iterator().next(), b ); assertTrue( b.isSuccessful() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); a = ( Auction ) s.load( Auction.class, aid ); assertFalse( Hibernate.isInitialized( b ) ); assertFalse( Hibernate.isInitialized( a ) ); s.createQuery( "from Auction a left join fetch a.successfulBid" ).list(); assertTrue( Hibernate.isInitialized( b ) ); assertTrue( Hibernate.isInitialized( a ) ); assertSame( b, a.getSuccessfulBid() ); assertFalse( Hibernate.isInitialized( a.getBids() ) ); assertSame( a.getBids().iterator().next(), b ); assertTrue( b.isSuccessful() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); a = ( Auction ) s.load( Auction.class, aid ); assertFalse( Hibernate.isInitialized( b ) ); assertFalse( Hibernate.isInitialized( a ) ); assertSame( s.get( Bid.class, bid ), b ); assertTrue( Hibernate.isInitialized( b ) ); assertSame( s.get( Auction.class, aid ), a ); assertTrue( Hibernate.isInitialized( a ) ); assertSame( b, a.getSuccessfulBid() ); assertFalse( Hibernate.isInitialized( a.getBids() ) ); assertSame( a.getBids().iterator().next(), b ); assertTrue( b.isSuccessful() ); t.commit(); s.close();
public class AuctionTest2 extends FunctionalTestCase { public AuctionTest2(String str) { super( str ); } public String[] getMappings() { return new String[] { "bidi/Auction2.hbm.xml" }; } public static Test suite() { return new FunctionalTestClassTestSuite( AuctionTest2.class ); } public boolean createSchema() { return getDialect().supportsExistsInSelect(); } public void testLazy() { if ( ! getDialect().supportsExistsInSelect() ) { reportSkip( "dialect does not support exist fragments in the select clause", "bidi support" ); return; } Session s = openSession(); Transaction t = s.beginTransaction(); Auction a = new Auction(); a.setDescription( "an auction for something" ); a.setEnd( new Date() ); Bid b = new Bid(); b.setAmount( new BigDecimal( 123.34 ).setScale( 19, BigDecimal.ROUND_DOWN ) ); b.setSuccessful( true ); b.setDatetime( new Date() ); b.setItem( a ); a.getBids().add( b ); a.setSuccessfulBid( b ); s.persist( b ); t.commit(); s.close(); Long aid = a.getId(); Long bid = b.getId(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); assertFalse( Hibernate.isInitialized( b ) ); a = ( Auction ) s.get( Auction.class, aid ); assertFalse( Hibernate.isInitialized( a.getBids() ) ); assertFalse( Hibernate.isInitialized( a.getSuccessfulBid() ) ); assertSame( a.getBids().iterator().next(), b ); assertSame( b, a.getSuccessfulBid() ); assertTrue( Hibernate.isInitialized( b ) ); assertTrue( b.isSuccessful() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); assertFalse( Hibernate.isInitialized( b ) ); a = ( Auction ) s.createQuery( "from Auction a left join fetch a.bids" ).uniqueResult(); assertTrue( Hibernate.isInitialized( b ) ); assertTrue( Hibernate.isInitialized( a.getBids() ) ); assertSame( b, a.getSuccessfulBid() ); assertSame( a.getBids().iterator().next(), b ); assertTrue( b.isSuccessful() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); a = ( Auction ) s.load( Auction.class, aid ); assertFalse( Hibernate.isInitialized( b ) ); assertFalse( Hibernate.isInitialized( a ) ); s.createQuery( "from Auction a left join fetch a.successfulBid" ).list(); assertTrue( Hibernate.isInitialized( b ) ); assertTrue( Hibernate.isInitialized( a ) ); assertSame( b, a.getSuccessfulBid() ); assertFalse( Hibernate.isInitialized( a.getBids() ) ); assertSame( a.getBids().iterator().next(), b ); assertTrue( b.isSuccessful() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); b = ( Bid ) s.load( Bid.class, bid ); a = ( Auction ) s.load( Auction.class, aid ); assertFalse( Hibernate.isInitialized( b ) ); assertFalse( Hibernate.isInitialized( a ) ); assertSame( s.get( Bid.class, bid ), b ); assertTrue( Hibernate.isInitialized( b ) ); assertSame( s.get( Auction.class, aid ), a ); assertTrue( Hibernate.isInitialized( a ) ); assertSame( b, a.getSuccessfulBid() ); assertFalse( Hibernate.isInitialized( a.getBids() ) ); assertSame( a.getBids().iterator().next(), b ); assertTrue( b.isSuccessful() ); t.commit(); s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/bidi/AuctionTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/bidi/AuctionTest2.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class AuctionTest extends FunctionalTestCase {
1
public class AuctionTest2 extends FunctionalTestCase {
2
	public AuctionTest(String str) {
2
	public AuctionTest2(String str) {
3
		super( str );
3
		super( str );
4
	}
4
	}
5
	public String[] getMappings() {
5
	public String[] getMappings() {
6
		return new String[] { "bidi/Auction.hbm.xml" };
6
		return new String[] { "bidi/Auction2.hbm.xml" };
7
	}
7
	}
8
	public static Test suite() {
8
	public static Test suite() {
9
		return new FunctionalTestClassTestSuite( AuctionTest.class );
9
		return new FunctionalTestClassTestSuite( AuctionTest2.class );
10
	}
10
	}
11
	public boolean createSchema() {
12
		return getDialect().supportsExistsInSelect();
13
	}
11
	public void testLazy() {
14
	public void testLazy() {
12
		if ( getDialect() instanceof PostgreSQLDialect ) {
15
		if ( ! getDialect().supportsExistsInSelect() ) {
13
			return; //doesn't like boolean=1
16
			reportSkip( "dialect does not support exist fragments in the select clause", "bidi support" );
17
			return;
14
		}
18
		}
15
		Session s = openSession();
19
		Session s = openSession();
16
		Transaction t = s.beginTransaction();
20
		Transaction t = s.beginTransaction();
17
		Auction a = new Auction();
21
		Auction a = new Auction();
18
		a.setDescription( "an auction for something" );
22
		a.setDescription( "an auction for something" );
19
		a.setEnd( new Date() );
23
		a.setEnd( new Date() );
20
		Bid b = new Bid();
24
		Bid b = new Bid();
21
		b.setAmount( new BigDecimal( 123.34 ).setScale( 19, BigDecimal.ROUND_DOWN ) );
25
		b.setAmount( new BigDecimal( 123.34 ).setScale( 19, BigDecimal.ROUND_DOWN ) );
22
		b.setSuccessful( true );
26
		b.setSuccessful( true );
23
		b.setDatetime( new Date() );
27
		b.setDatetime( new Date() );
24
		b.setItem( a );
28
		b.setItem( a );
25
		a.getBids().add( b );
29
		a.getBids().add( b );
26
		a.setSuccessfulBid( b );
30
		a.setSuccessfulBid( b );
27
		s.persist( b );
31
		s.persist( b );
28
		t.commit();
32
		t.commit();
29
		s.close();
33
		s.close();
30
		Long aid = a.getId();
34
		Long aid = a.getId();
31
		Long bid = b.getId();
35
		Long bid = b.getId();
32
		s = openSession();
36
		s = openSession();
33
		t = s.beginTransaction();
37
		t = s.beginTransaction();
34
		b = ( Bid ) s.load( Bid.class, bid );
38
		b = ( Bid ) s.load( Bid.class, bid );
35
		assertFalse( Hibernate.isInitialized( b ) );
39
		assertFalse( Hibernate.isInitialized( b ) );
36
		a = ( Auction ) s.get( Auction.class, aid );
40
		a = ( Auction ) s.get( Auction.class, aid );
37
		assertFalse( Hibernate.isInitialized( a.getBids() ) );
41
		assertFalse( Hibernate.isInitialized( a.getBids() ) );
38
		assertTrue( Hibernate.isInitialized( a.getSuccessfulBid() ) );
42
		assertFalse( Hibernate.isInitialized( a.getSuccessfulBid() ) );
39
		assertSame( a.getBids().iterator().next(), b );
43
		assertSame( a.getBids().iterator().next(), b );
40
		assertSame( b, a.getSuccessfulBid() );
44
		assertSame( b, a.getSuccessfulBid() );
41
		assertTrue( Hibernate.isInitialized( b ) );
45
		assertTrue( Hibernate.isInitialized( b ) );
42
		assertTrue( b.isSuccessful() );
46
		assertTrue( b.isSuccessful() );
43
		t.commit();
47
		t.commit();
44
		s.close();
48
		s.close();
45
		s = openSession();
49
		s = openSession();
46
		t = s.beginTransaction();
50
		t = s.beginTransaction();
47
		b = ( Bid ) s.load( Bid.class, bid );
51
		b = ( Bid ) s.load( Bid.class, bid );
48
		assertFalse( Hibernate.isInitialized( b ) );
52
		assertFalse( Hibernate.isInitialized( b ) );
49
		a = ( Auction ) s.createQuery( "from Auction a left join fetch a.bids" ).uniqueResult();
53
		a = ( Auction ) s.createQuery( "from Auction a left join fetch a.bids" ).uniqueResult();
50
		assertTrue( Hibernate.isInitialized( b ) );
54
		assertTrue( Hibernate.isInitialized( b ) );
51
		assertTrue( Hibernate.isInitialized( a.getBids() ) );
55
		assertTrue( Hibernate.isInitialized( a.getBids() ) );
52
		assertSame( b, a.getSuccessfulBid() );
56
		assertSame( b, a.getSuccessfulBid() );
53
		assertSame( a.getBids().iterator().next(), b );
57
		assertSame( a.getBids().iterator().next(), b );
54
		assertTrue( b.isSuccessful() );
58
		assertTrue( b.isSuccessful() );
55
		t.commit();
59
		t.commit();
56
		s.close();
60
		s.close();
57
		s = openSession();
61
		s = openSession();
58
		t = s.beginTransaction();
62
		t = s.beginTransaction();
59
		b = ( Bid ) s.load( Bid.class, bid );
63
		b = ( Bid ) s.load( Bid.class, bid );
60
		a = ( Auction ) s.load( Auction.class, aid );
64
		a = ( Auction ) s.load( Auction.class, aid );
61
		assertFalse( Hibernate.isInitialized( b ) );
65
		assertFalse( Hibernate.isInitialized( b ) );
62
		assertFalse( Hibernate.isInitialized( a ) );
66
		assertFalse( Hibernate.isInitialized( a ) );
63
		s.createQuery( "from Auction a left join fetch a.successfulBid" ).list();
67
		s.createQuery( "from Auction a left join fetch a.successfulBid" ).list();
64
		assertTrue( Hibernate.isInitialized( b ) );
68
		assertTrue( Hibernate.isInitialized( b ) );
65
		assertTrue( Hibernate.isInitialized( a ) );
69
		assertTrue( Hibernate.isInitialized( a ) );
66
		assertSame( b, a.getSuccessfulBid() );
70
		assertSame( b, a.getSuccessfulBid() );
67
		assertFalse( Hibernate.isInitialized( a.getBids() ) );
71
		assertFalse( Hibernate.isInitialized( a.getBids() ) );
68
		assertSame( a.getBids().iterator().next(), b );
72
		assertSame( a.getBids().iterator().next(), b );
69
		assertTrue( b.isSuccessful() );
73
		assertTrue( b.isSuccessful() );
70
		t.commit();
74
		t.commit();
71
		s.close();
75
		s.close();
72
		s = openSession();
76
		s = openSession();
73
		t = s.beginTransaction();
77
		t = s.beginTransaction();
74
		b = ( Bid ) s.load( Bid.class, bid );
78
		b = ( Bid ) s.load( Bid.class, bid );
75
		a = ( Auction ) s.load( Auction.class, aid );
79
		a = ( Auction ) s.load( Auction.class, aid );
76
		assertFalse( Hibernate.isInitialized( b ) );
80
		assertFalse( Hibernate.isInitialized( b ) );
77
		assertFalse( Hibernate.isInitialized( a ) );
81
		assertFalse( Hibernate.isInitialized( a ) );
78
		assertSame( s.get( Bid.class, bid ), b );
82
		assertSame( s.get( Bid.class, bid ), b );
79
		assertTrue( Hibernate.isInitialized( b ) );
83
		assertTrue( Hibernate.isInitialized( b ) );
80
		assertSame( s.get( Auction.class, aid ), a );
84
		assertSame( s.get( Auction.class, aid ), a );
81
		assertTrue( Hibernate.isInitialized( a ) );
85
		assertTrue( Hibernate.isInitialized( a ) );
82
		assertSame( b, a.getSuccessfulBid() );
86
		assertSame( b, a.getSuccessfulBid() );
83
		assertFalse( Hibernate.isInitialized( a.getBids() ) );
87
		assertFalse( Hibernate.isInitialized( a.getBids() ) );
84
		assertSame( a.getBids().iterator().next(), b );
88
		assertSame( a.getBids().iterator().next(), b );
85
		assertTrue( b.isSuccessful() );
89
		assertTrue( b.isSuccessful() );
86
		t.commit();
90
		t.commit();
87
		s.close();
91
		s.close();
88
	
92
	
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