【Java开源代码栏目提醒】:本文主要为网学会员提供TimestampTest.java,希望对需要TimestampTest.java网友有所帮助,学习一下!
//$Id: TimestampTest.java 8054 2005-08-31 20:12:24Z oneovthafew $
package org.hibernate.test.timestamp;
import java.util.Date;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
public class TimestampTest extends TestCase {
public TimestampTest(String str) {
super(str);
}
public void testUpdateFalse() {
getSessions().getStatistics().clear();
Session s = openSession();
Transaction t = s.beginTransaction();
User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
s.persist(u);
s.flush();
u.getPerson().setName("XXXXYYYYY");
t.commit();
s.close();
assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
s = openSession();
t = s.beginTransaction();
u = (User) s.get(User.class, "gavin");
assertEquals( u.getPerson().getName(), "Gavin King" );
s.delete(u);
t.commit();
s.close();
assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
}
public void testComponent() {
Session s = openSession();
Transaction t = s.beginTransaction();
User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
s.persist(u);
s.flush();
u.getPerson().setCurrentAddress("Peachtree Rd");
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
u = (User) s.get(User.class, "gavin");
u.setPassword("$ecret");
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
u = (User) s.get(User.class, "gavin");
assertEquals( u.getPass
word(), "$ecret" );
s.delete(u);
t.commit();
s.close();
}
protected String[] getMappings() {
return new String[] { "timestamp/User.hbm.
xml" };
}
public static Test suite() {
return new TestSuite(TimestampTest.class);
}
protected void configure(Configuration cfg) {
cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
}