01: package org.compass.gps.device.hibernate.simple.embedded;
02:
03: import org.compass.core.CompassSession;
04: import org.compass.core.CompassTransaction;
05: import org.compass.gps.device.hibernate.embedded.HibernateHelper;
06: import org.compass.gps.device.hibernate.simple.ScrollableSimpleHibernateGpsDeviceTests;
07: import org.compass.gps.device.hibernate.simple.Simple;
08: import org.hibernate.Session;
09: import org.hibernate.Transaction;
10:
11: /**
12: * @author kimchy
13: */
14: public class EmbeddedHibernateTests extends
15: ScrollableSimpleHibernateGpsDeviceTests {
16:
17: protected String getHiberanteCfgLocation() {
18: return "/org/compass/gps/device/hibernate/simple/embedded/hibernate.cfg.xml";
19: }
20:
21: protected void setUpCompass() {
22: compass = HibernateHelper.getCompass(sessionFactory);
23: compass.getSearchEngineIndexManager().deleteIndex();
24: compass.getSearchEngineIndexManager().verifyIndex();
25: }
26:
27: protected void setUpGpsDevice() {
28: super .setUpGpsDevice();
29: // disable mirroring since we work in embedded mode
30: hibernateGpsDevice.setMirrorDataChanges(false);
31: }
32:
33: public void testMirrorWithRollback() throws Exception {
34: compassGps.index();
35:
36: Session session = sessionFactory.openSession();
37: Transaction tr = session.beginTransaction();
38:
39: // insert a new one
40: Simple simple = new Simple();
41: simple.setId(4);
42: simple.setValue("value4");
43: session.save(simple);
44:
45: // delete the second one
46: simple = (Simple) session.load(Simple.class, 2);
47: session.delete(simple);
48:
49: // update the first one
50: simple = (Simple) session.load(Simple.class, 1);
51: simple.setValue("updatedValue1");
52: session.save(simple);
53:
54: session.flush();
55:
56: tr.rollback();
57: session.close();
58:
59: CompassSession sess = compass.openSession();
60: CompassTransaction compassTransaction = sess.beginTransaction();
61:
62: simple = sess.get(Simple.class, 4);
63: assertNull(simple);
64:
65: simple = sess.get(Simple.class, 2);
66: assertNotNull(simple);
67:
68: simple = sess.load(Simple.class, 1);
69: assertEquals("value1", simple.getValue());
70:
71: compassTransaction.commit();
72: sess.close();
73: }
74: }
|