package org.apache.ojb.jdo;
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import junit.framework.TestCase;
import org.apache.ojb.otm.Person;
import javax.jdo.JDOUserException;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;
import java.util.Collection;
public class TestTransactions extends TestCase
{
/** Cheat and use our impl directly */
private PersistenceManagerFactoryImpl factory = new PersistenceManagerFactoryImpl();
public void testReBeginTx() throws Exception
{
Person person = new Person();
person.setFirstname("Brian");
person.setLastname("McCallister");
PersistenceManager pm = factory.getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.begin();
pm.makePersistent(person);
tx.commit();
tx.begin();
Query q = pm.newQuery(Person.class);
Collection persons = (Collection) q.execute();
tx.commit();
assertTrue(persons.size() > 0);
pm.close();
}
public void testExceptionOnReBegin()
{
PersistenceManager pm = factory.getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.begin();
try
{
tx.begin();
fail("Should have thrown an exception");
}
catch (JDOUserException e)
{
assertTrue("Flow passes through here", true);
}
pm.close();
}
}