rowidtest.java
来自「hibernate-3.0.5 中文文档」· Java 代码 · 共 95 行
JAVA
95 行
//$Id: RowIdTest.java,v 1.2 2005/04/21 08:01:29 oneovthafew Exp $package org.hibernate.test.rowid;import java.math.BigDecimal;import java.sql.DatabaseMetaData;import java.sql.ResultSet;import java.sql.Statement;import junit.framework.Test;import junit.framework.TestSuite;import org.hibernate.Session;import org.hibernate.Transaction;import org.hibernate.dialect.Oracle9Dialect;import org.hibernate.test.TestCase;/** * @author Gavin King */public class RowIdTest extends TestCase { public RowIdTest(String str) { super(str); } protected boolean recreateSchema() { return false; } public void setUp() throws Exception { super.setUp(); if ( !( getDialect() instanceof Oracle9Dialect ) ) return; Session s = openSession(); Statement st = s.connection().createStatement(); DatabaseMetaData metaData = s.connection().getMetaData(); ResultSet rs = metaData.getTables(s.connection().getCatalog(), null, "POINT", null); if ( rs.next() ) st.execute("drop table Point"); rs.close(); s.connection().commit(); st.execute("create table Point (\"x\" number(19,2) not null, \"y\" number(19,2) not null, description varchar2(255) )"); s.close(); } public void tearDown() throws Exception { /*Session s = openSession(); Statement st = s.connection().createStatement(); st.execute("drop table Point"); s.close();*/ } public void testRowId() { if ( !( getDialect() instanceof Oracle9Dialect ) ) return; Session s = openSession(); Transaction t = s.beginTransaction(); Point p = new Point( new BigDecimal(1.0), new BigDecimal(1.0) ); s.persist(p); t.commit(); s.clear(); t = s.beginTransaction(); p = (Point) s.createCriteria(Point.class).uniqueResult(); p.setDescription("new desc"); t.commit(); s.clear(); t = s.beginTransaction(); p = (Point) s.createQuery("from Point").uniqueResult(); p.setDescription("new new desc"); t.commit(); s.clear(); t = s.beginTransaction(); p = (Point) s.get(Point.class, p); p.setDescription("new new new desc"); t.commit(); s.close(); } protected String[] getMappings() { return new String[] { "rowid/Point.hbm.xml" }; } public static Test suite() { return new TestSuite(RowIdTest.class); } public String getCacheConcurrencyStrategy() { return null; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?