01: package org.apache.ojb.jdo;
02:
03: /* Copyright 2004 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import junit.framework.TestCase;
19: import org.apache.ojb.otm.Person;
20:
21: import javax.jdo.JDOUserException;
22: import javax.jdo.PersistenceManager;
23: import javax.jdo.Query;
24: import javax.jdo.Transaction;
25: import java.util.Collection;
26:
27: public class TestTransactions extends TestCase {
28: /** Cheat and use our impl directly */
29: private PersistenceManagerFactoryImpl factory = new PersistenceManagerFactoryImpl();
30:
31: public void testReBeginTx() throws Exception {
32: Person person = new Person();
33: person.setFirstname("Brian");
34: person.setLastname("McCallister");
35: PersistenceManager pm = factory.getPersistenceManager();
36: Transaction tx = pm.currentTransaction();
37: tx.begin();
38: pm.makePersistent(person);
39: tx.commit();
40:
41: tx.begin();
42: Query q = pm.newQuery(Person.class);
43: Collection persons = (Collection) q.execute();
44: tx.commit();
45: assertTrue(persons.size() > 0);
46: pm.close();
47: }
48:
49: public void testExceptionOnReBegin() {
50: PersistenceManager pm = factory.getPersistenceManager();
51: Transaction tx = pm.currentTransaction();
52: tx.begin();
53: try {
54: tx.begin();
55: fail("Should have thrown an exception");
56: } catch (JDOUserException e) {
57: assertTrue("Flow passes through here", true);
58: }
59: pm.close();
60: }
61: }
|