KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > legacy > IJTest


1 //$Id: IJTest.java,v 1.2 2005/06/19 02:01:05 oneovthafew Exp $
2
package org.hibernate.test.legacy;
3
4 import java.io.Serializable JavaDoc;
5
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8
9 import org.hibernate.LockMode;
10 import org.hibernate.classic.Session;
11 import org.hibernate.dialect.HSQLDialect;
12 import org.hibernate.dialect.OracleDialect;
13 import org.hibernate.test.TestCase;
14
15 /**
16  * @author Gavin King
17  */

18 public class IJTest extends TestCase {
19
20     public void testFormulaDiscriminator() throws Exception JavaDoc {
21         if ( ( getDialect() instanceof OracleDialect ) || ( getDialect() instanceof HSQLDialect ) ) return;
22         Session s = getSessions().openSession();
23         I i = new I();
24         i.setName( "i" );
25         i.setType( 'a' );
26         J j = new J();
27         j.setName( "j" );
28         j.setType( 'x' );
29         j.setAmount( 1.0f );
30         Serializable JavaDoc iid = s.save(i);
31         Serializable JavaDoc jid = s.save(j);
32         s.flush();
33         s.connection().commit();
34         s.close();
35
36         getSessions().evict(I.class);
37
38         s = getSessions().openSession();
39         j = (J) s.get(I.class, jid);
40         i = (I) s.get(I.class, iid);
41         assertTrue( i.getClass()==I.class );
42         j.setAmount( 0.5f );
43         s.lock(i, LockMode.UPGRADE);
44         s.flush();
45         s.connection().commit();
46         s.close();
47
48         s = getSessions().openSession();
49         j = (J) s.get(I.class, jid, LockMode.UPGRADE);
50         i = (I) s.get(I.class, iid, LockMode.UPGRADE);
51         s.flush();
52         s.connection().commit();
53         s.close();
54
55         s = getSessions().openSession();
56         assertTrue( s.find("from I").size()==2 );
57         assertTrue( s.find("from J").size()==1 );
58         assertTrue( s.find("from I i where i.class = 0").size()==1 );
59         assertTrue( s.find("from I i where i.class = 1").size()==1 );
60         s.connection().commit();
61         s.close();
62
63         s = getSessions().openSession();
64         j = (J) s.get(J.class, jid);
65         i = (I) s.get(I.class, iid);
66         s.delete(j);
67         s.delete(i);
68         s.flush();
69         s.connection().commit();
70         s.close();
71
72     }
73
74     protected String JavaDoc[] getMappings() {
75         return new String JavaDoc[] { "legacy/IJ.hbm.xml" };
76     }
77
78     public IJTest(String JavaDoc x) {
79         super(x);
80     }
81
82     public static Test suite() {
83         return new TestSuite(IJTest.class);
84     }
85 }
86
Popular Tags