KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > ondelete > OnDeleteTest


1 //$Id: OnDeleteTest.java,v 1.1 2005/06/12 22:02:24 oneovthafew Exp $
2
package org.hibernate.test.ondelete;
3
4 import java.util.List JavaDoc;
5
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8
9 import org.hibernate.Session;
10 import org.hibernate.Transaction;
11 import org.hibernate.cfg.Configuration;
12 import org.hibernate.cfg.Environment;
13 import org.hibernate.dialect.MySQLDialect;
14 import org.hibernate.dialect.MySQLInnoDBDialect;
15 import org.hibernate.stat.Statistics;
16 import org.hibernate.test.TestCase;
17
18 /**
19  * @author Gavin King
20  */

21 public class OnDeleteTest extends TestCase {
22     
23     public OnDeleteTest(String JavaDoc str) {
24         super(str);
25     }
26     
27     public void testJoinedSubclass() {
28         
29         Statistics statistics = getSessions().getStatistics();
30         statistics.clear();
31         
32         Session s = openSession();
33         Transaction t = s.beginTransaction();
34         
35         Salesperson mark = new Salesperson();
36         mark.setName("Mark");
37         mark.setTitle("internal sales");
38         mark.setSex('M');
39         mark.setAddress("buckhead");
40         mark.setZip("30305");
41         mark.setCountry("USA");
42         
43         Person joe = new Person();
44         joe.setName("Joe");
45         joe.setAddress("San Francisco");
46         joe.setZip("XXXXX");
47         joe.setCountry("USA");
48         joe.setSex('M');
49         joe.setSalesperson(mark);
50         mark.getCustomers().add(joe);
51                 
52         s.save(mark);
53         
54         t.commit();
55         
56         assertEquals( statistics.getEntityInsertCount(), 2 );
57         assertEquals( statistics.getPrepareStatementCount(), 4 );
58         
59         statistics.clear();
60         
61         t = s.beginTransaction();
62         s.delete(mark);
63         t.commit();
64
65         assertEquals( statistics.getEntityDeleteCount(), 2 );
66         if ( !(getDialect() instanceof MySQLDialect) || (getDialect() instanceof MySQLInnoDBDialect) ) {
67             assertEquals( statistics.getPrepareStatementCount(), 1 );
68         }
69         
70         t = s.beginTransaction();
71         List JavaDoc names = s.createQuery("select name from Person").list();
72         assertTrue( names.isEmpty() );
73         t.commit();
74
75         s.close();
76     }
77
78     protected void configure(Configuration cfg) {
79         cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
80     }
81
82     protected String JavaDoc[] getMappings() {
83         return new String JavaDoc[] { "ondelete/Person.hbm.xml" };
84     }
85
86     public static Test suite() {
87         return new TestSuite(OnDeleteTest.class);
88     }
89
90 }
91
92
Popular Tags