01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.gps.device.jpa.embedded.toplink;
18:
19: import java.util.HashMap;
20: import javax.persistence.EntityManager;
21: import javax.persistence.EntityManagerFactory;
22: import javax.persistence.EntityTransaction;
23:
24: import oracle.toplink.essentials.PersistenceProvider;
25: import org.compass.core.CompassSession;
26: import org.compass.core.CompassTransaction;
27: import org.compass.gps.device.jpa.AbstractSimpleJpaGpsDeviceTests;
28: import org.compass.gps.device.jpa.model.Simple;
29:
30: /**
31: * Performs JPA tests using TopLink specific support.
32: *
33: * @author kimchy
34: */
35: public class EmbeddedToplinkSimpleJpaGpsDeviceTests extends
36: AbstractSimpleJpaGpsDeviceTests {
37:
38: protected void setUpCompass() {
39: compass = TopLinkHelper.getCompass(entityManagerFactory);
40: assertNotNull(compass);
41: }
42:
43: protected void setUpGps() {
44: compassGps = TopLinkHelper.getCompassGps(entityManagerFactory);
45: assertNotNull(compass);
46: }
47:
48: protected EntityManagerFactory doSetUpEntityManagerFactory() {
49: return new PersistenceProvider().createEntityManagerFactory(
50: "embeddedtoplink", new HashMap());
51: }
52:
53: public void testRollbackTransaction() throws Exception {
54: compassGps.index();
55:
56: EntityManager entityManager = entityManagerFactory
57: .createEntityManager();
58: EntityTransaction entityTransaction = entityManager
59: .getTransaction();
60: entityTransaction.begin();
61:
62: // insert a new one
63: Simple simple = new Simple();
64: simple.setId(4);
65: simple.setValue("value4");
66: entityManager.persist(simple);
67: entityManager.flush();
68:
69: CompassSession compassSession = TopLinkHelper
70: .getCurrentCompassSession(entityManager);
71: simple = compassSession.get(Simple.class, 4);
72: assertNotNull(simple);
73:
74: CompassSession otherCompassSession = TopLinkHelper
75: .getCurrentCompassSession(entityManager);
76: assertSame(compassSession, otherCompassSession);
77:
78: entityTransaction.rollback();
79: entityManager.close();
80:
81: CompassSession sess = compass.openSession();
82: CompassTransaction tr = sess.beginTransaction();
83:
84: simple = sess.get(Simple.class, 4);
85: assertNull(simple);
86:
87: tr.commit();
88: sess.close();
89: }
90:
91: }
|