01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.kernel;
20:
21: import javax.persistence.EntityManager;
22:
23: import org.apache.openjpa.persistence.kernel.common.apps.InstanceCallbacksTest;
24: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
25: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
26:
27: public class TestEJBIncrementalFlushes extends AbstractTestCase {
28:
29: public TestEJBIncrementalFlushes(String name) {
30: super (name, "kernelcactusapp");
31: }
32:
33: public void setUp() {
34: deleteAll(RuntimeTest1.class);
35:
36: EntityManager em = currentEntityManager();
37: startTx(em);
38:
39: endTx(em);
40: endEm(em);
41: }
42:
43: // public void testBasicJdoPreStore ()
44: // {
45: // EntityManager em = getEm ();
46: // em.getTransaction ().begin ();
47: // InstanceCallbacksTest a = new InstanceCallbacksTest ("foo", 10);
48: // em.persist(a);
49: // em.flush ();
50: // assertTrue (a.preStoreCalled);
51: // em.getTransaction ().commit ();
52: // }
53:
54: public void testFlushNoChange() {
55: EntityManager em = currentEntityManager();
56: startTx(em);
57: InstanceCallbacksTest a = new InstanceCallbacksTest("foo", 10);
58: em.persist(a);
59: em.flush();
60: endTx(em);
61: //assertTrue (a.preStoreCalled);
62: assertEquals(10, a.getIntField());
63:
64: endTx(em);
65: endEm(em);
66: }
67:
68: public void testOptimisticLockGivesCorrectError() {
69: EntityManager pm1 = currentEntityManager();
70: EntityManager pm2 = currentEntityManager();
71:
72: RuntimeTest1 a1 = new RuntimeTest1("foo", 10);
73: startTx(pm1);
74: pm1.persist(a1);
75: endTx(pm1);
76:
77: RuntimeTest1 a2 = (RuntimeTest1) pm2.find(RuntimeTest1.class,
78: 10);
79: startTx(pm2);
80: a2.setStringField("foobar");
81: startTx(pm2);
82:
83: startTx(pm1);
84: a1.setStringField("foobarbaz");
85: try {
86: endTx(pm1);
87: } catch (Exception ole) {
88: // expected case
89: } finally {
90: if (pm1.getTransaction().isActive())
91: pm1.getTransaction().rollback();
92:
93: endEm(pm1);
94: endEm(pm2);
95: }
96: }
97: }
|