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.eclipselink;
18:
19: import java.util.HashMap;
20: import javax.persistence.EntityManager;
21: import javax.persistence.EntityManagerFactory;
22: import javax.persistence.EntityTransaction;
23:
24: import org.compass.core.CompassSession;
25: import org.compass.core.CompassTransaction;
26: import org.compass.gps.device.jpa.AbstractSimpleJpaGpsDeviceTests;
27: import org.compass.gps.device.jpa.model.Simple;
28: import org.eclipse.persistence.jpa.PersistenceProvider;
29:
30: /**
31: * Performs JPA tests using EclipseLink specific support.
32: *
33: * @author kimchy
34: */
35: public class EmbeddedEclipseLinkSimpleJpaGpsDeviceTests extends
36: AbstractSimpleJpaGpsDeviceTests {
37:
38: protected void setUpCompass() {
39: compass = EclipseLinkHelper.getCompass(entityManagerFactory);
40: assertNotNull(compass);
41: }
42:
43: protected void setUpGps() {
44: compassGps = EclipseLinkHelper
45: .getCompassGps(entityManagerFactory);
46: assertNotNull(compass);
47: }
48:
49: protected EntityManagerFactory doSetUpEntityManagerFactory() {
50: return new PersistenceProvider().createEntityManagerFactory(
51: "embeddedeclipselink", new HashMap());
52: }
53:
54: public void testRollbackTransaction() throws Exception {
55: compassGps.index();
56:
57: EntityManager entityManager = entityManagerFactory
58: .createEntityManager();
59: EntityTransaction entityTransaction = entityManager
60: .getTransaction();
61: entityTransaction.begin();
62:
63: // insert a new one
64: Simple simple = new Simple();
65: simple.setId(4);
66: simple.setValue("value4");
67: entityManager.persist(simple);
68: entityManager.flush();
69:
70: CompassSession compassSession = EclipseLinkHelper
71: .getCurrentCompassSession(entityManager);
72: simple = compassSession.get(Simple.class, 4);
73: assertNotNull(simple);
74:
75: CompassSession otherCompassSession = EclipseLinkHelper
76: .getCurrentCompassSession(entityManager);
77: assertSame(compassSession, otherCompassSession);
78:
79: entityTransaction.rollback();
80: entityManager.close();
81:
82: CompassSession sess = compass.openSession();
83: CompassTransaction tr = sess.beginTransaction();
84:
85: simple = sess.get(Simple.class, 4);
86: assertNull(simple);
87:
88: tr.commit();
89: sess.close();
90: }
91:
92: }
|