KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > rowid > RowIdTest


1 //$Id: RowIdTest.java,v 1.2 2005/04/21 08:01:29 oneovthafew Exp $
2
package org.hibernate.test.rowid;
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.DatabaseMetaData JavaDoc;
6 import java.sql.ResultSet JavaDoc;
7 import java.sql.Statement JavaDoc;
8
9 import junit.framework.Test;
10 import junit.framework.TestSuite;
11
12 import org.hibernate.Session;
13 import org.hibernate.Transaction;
14 import org.hibernate.dialect.Oracle9Dialect;
15 import org.hibernate.test.TestCase;
16
17 /**
18  * @author Gavin King
19  */

20 public class RowIdTest extends TestCase {
21     
22     public RowIdTest(String JavaDoc str) {
23         super(str);
24     }
25     
26     protected boolean recreateSchema() {
27         return false;
28     }
29     
30     public void setUp() throws Exception JavaDoc {
31         super.setUp();
32         if ( !( getDialect() instanceof Oracle9Dialect ) ) return;
33         Session s = openSession();
34         Statement JavaDoc st = s.connection().createStatement();
35         DatabaseMetaData JavaDoc metaData = s.connection().getMetaData();
36         ResultSet JavaDoc rs = metaData.getTables(s.connection().getCatalog(), null, "POINT", null);
37         if ( rs.next() ) st.execute("drop table Point");
38         rs.close();
39         s.connection().commit();
40         st.execute("create table Point (\"x\" number(19,2) not null, \"y\" number(19,2) not null, description varchar2(255) )");
41         s.close();
42     }
43
44     public void tearDown() throws Exception JavaDoc {
45         /*Session s = openSession();
46         Statement st = s.connection().createStatement();
47         st.execute("drop table Point");
48         s.close();*/

49     }
50
51     public void testRowId() {
52         if ( !( getDialect() instanceof Oracle9Dialect ) ) return;
53         
54         Session s = openSession();
55         Transaction t = s.beginTransaction();
56         Point p = new Point( new BigDecimal JavaDoc(1.0), new BigDecimal JavaDoc(1.0) );
57         s.persist(p);
58         t.commit();
59         s.clear();
60         
61         t = s.beginTransaction();
62         p = (Point) s.createCriteria(Point.class).uniqueResult();
63         p.setDescription("new desc");
64         t.commit();
65         s.clear();
66         
67         t = s.beginTransaction();
68         p = (Point) s.createQuery("from Point").uniqueResult();
69         p.setDescription("new new desc");
70         t.commit();
71         s.clear();
72         
73         t = s.beginTransaction();
74         p = (Point) s.get(Point.class, p);
75         p.setDescription("new new new desc");
76         t.commit();
77         s.close();
78         
79     }
80     
81     protected String JavaDoc[] getMappings() {
82         return new String JavaDoc[] { "rowid/Point.hbm.xml" };
83     }
84
85     public static Test suite() {
86         return new TestSuite(RowIdTest.class);
87     }
88
89     public String JavaDoc getCacheConcurrencyStrategy() {
90         return null;
91     }
92
93 }
94
95
Popular Tags