~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/legacy/IJTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: IJTest.java 10976 2006-12-12 23:22:26Z steve.ebersole@jboss.com $
 
2
package org.hibernate.test.legacy;
 
3
 
 
4
import java.io.Serializable;
 
5
 
 
6
import junit.framework.Test;
 
7
 
 
8
import org.hibernate.LockMode;
 
9
import org.hibernate.classic.Session;
 
10
import org.hibernate.dialect.HSQLDialect;
 
11
import org.hibernate.dialect.OracleDialect;
 
12
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
13
 
 
14
/**
 
15
 * @author Gavin King
 
16
 */
 
17
public class IJTest extends LegacyTestCase {
 
18
 
 
19
        public IJTest(String x) {
 
20
                super(x);
 
21
        }
 
22
 
 
23
        public String[] getMappings() {
 
24
                return new String[] { "legacy/IJ.hbm.xml" };
 
25
        }
 
26
 
 
27
        public static Test suite() {
 
28
                return new FunctionalTestClassTestSuite( IJTest.class );
 
29
        }
 
30
 
 
31
        public void testFormulaDiscriminator() throws Exception {
 
32
                if ( ( getDialect() instanceof OracleDialect ) || ( getDialect() instanceof HSQLDialect ) ) return;
 
33
                Session s = getSessions().openSession();
 
34
                I i = new I();
 
35
                i.setName( "i" );
 
36
                i.setType( 'a' );
 
37
                J j = new J();
 
38
                j.setName( "j" );
 
39
                j.setType( 'x' );
 
40
                j.setAmount( 1.0f );
 
41
                Serializable iid = s.save(i);
 
42
                Serializable jid = s.save(j);
 
43
                s.flush();
 
44
                s.connection().commit();
 
45
                s.close();
 
46
 
 
47
                getSessions().evict(I.class);
 
48
 
 
49
                s = getSessions().openSession();
 
50
                j = (J) s.get(I.class, jid);
 
51
                i = (I) s.get(I.class, iid);
 
52
                assertTrue( i.getClass()==I.class );
 
53
                j.setAmount( 0.5f );
 
54
                s.lock(i, LockMode.UPGRADE);
 
55
                s.flush();
 
56
                s.connection().commit();
 
57
                s.close();
 
58
 
 
59
                s = getSessions().openSession();
 
60
                j = (J) s.get(I.class, jid, LockMode.UPGRADE);
 
61
                i = (I) s.get(I.class, iid, LockMode.UPGRADE);
 
62
                s.flush();
 
63
                s.connection().commit();
 
64
                s.close();
 
65
 
 
66
                s = getSessions().openSession();
 
67
                assertTrue( s.find("from I").size()==2 );
 
68
                assertTrue( s.find("from J").size()==1 );
 
69
                assertTrue( s.find("from I i where i.class = 0").size()==1 );
 
70
                assertTrue( s.find("from I i where i.class = 1").size()==1 );
 
71
                s.connection().commit();
 
72
                s.close();
 
73
 
 
74
                s = getSessions().openSession();
 
75
                j = (J) s.get(J.class, jid);
 
76
                i = (I) s.get(I.class, iid);
 
77
                s.delete(j);
 
78
                s.delete(i);
 
79
                s.flush();
 
80
                s.connection().commit();
 
81
                s.close();
 
82
 
 
83
        }
 
84
}