KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > optlock > OptimisticLockTest


1 //$Id: OptimisticLockTest.java,v 1.2 2005/07/19 18:45:59 oneovthafew Exp $
2
package org.hibernate.test.optlock;
3
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import org.hibernate.Session;
8 import org.hibernate.Transaction;
9 import org.hibernate.test.TestCase;
10
11 /**
12  * @author Gavin King
13  */

14 public class OptimisticLockTest extends TestCase {
15     
16     public OptimisticLockTest(String JavaDoc str) {
17         super(str);
18     }
19     
20     public void testOptimisticLockDirty() {
21         Session s = openSession();
22         Transaction t = s.beginTransaction();
23         Document doc = new Document();
24         doc.setTitle("Hibernate in Action");
25         doc.setAuthor("Bauer et al");
26         doc.setSummary("Very boring book about persistence");
27         doc.setText("blah blah yada yada yada");
28         doc.setPubDate( new PublicationDate(2004) );
29         s.save("Dirty", doc);
30         s.flush();
31         doc.setSummary("A modern classic");
32         s.flush();
33         doc.getPubDate().setMonth( new Integer JavaDoc(3) );
34         s.flush();
35         s.delete(doc);
36         t.commit();
37         s.close();
38     }
39
40     public void testOptimisticLockAll() {
41         Session s = openSession();
42         Transaction t = s.beginTransaction();
43         Document doc = new Document();
44         doc.setTitle("Hibernate in Action");
45         doc.setAuthor("Bauer et al");
46         doc.setSummary("Very boring book about persistence");
47         doc.setText("blah blah yada yada yada");
48         doc.setPubDate( new PublicationDate(2004) );
49         s.save("All", doc);
50         s.flush();
51         doc.setSummary("A modern classic");
52         s.flush();
53         doc.getPubDate().setMonth( new Integer JavaDoc(3) );
54         s.flush();
55         s.delete(doc);
56         t.commit();
57         s.close();
58     }
59
60     
61     protected String JavaDoc[] getMappings() {
62         return new String JavaDoc[] { "optlock/Document.hbm.xml" };
63     }
64
65     public static Test suite() {
66         return new TestSuite(OptimisticLockTest.class);
67     }
68
69 }
70
71
Popular Tags