1 package org.hibernate.test.rowid; 3 4 import java.math.BigDecimal ; 5 import java.sql.DatabaseMetaData ; 6 import java.sql.ResultSet ; 7 import java.sql.Statement ; 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 20 public class RowIdTest extends TestCase { 21 22 public RowIdTest(String str) { 23 super(str); 24 } 25 26 protected boolean recreateSchema() { 27 return false; 28 } 29 30 public void setUp() throws Exception { 31 super.setUp(); 32 if ( !( getDialect() instanceof Oracle9Dialect ) ) return; 33 Session s = openSession(); 34 Statement st = s.connection().createStatement(); 35 DatabaseMetaData metaData = s.connection().getMetaData(); 36 ResultSet 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 { 45 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 (1.0), new BigDecimal (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 [] getMappings() { 82 return new String [] { "rowid/Point.hbm.xml" }; 83 } 84 85 public static Test suite() { 86 return new TestSuite(RowIdTest.class); 87 } 88 89 public String getCacheConcurrencyStrategy() { 90 return null; 91 } 92 93 } 94 95 | Popular Tags |