2 Copyright 2010 Sun Microsystems, Inc.
3 All rights reserved. Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package com.mysql.clusterj.jpatest;
21 import javax.persistence.EntityManager;
22 import javax.persistence.EntityTransaction;
25 * A base test case for a single EntityManager at any given time.
27 public abstract class SingleEMTestCase extends SingleEMFTestCase {
29 protected EntityManager em;
31 protected EntityTransaction tx;
36 em = emf.createEntityManager();
40 public void setUp(Object... props) {
42 em = emf.createEntityManager();
46 public void tearDown() throws Exception {
53 * Start a new transaction if there isn't currently one active.
54 * @return true if a transaction was started, false if one already existed
56 protected boolean begin() {
57 EntityTransaction tx = em.getTransaction();
65 * Commit the current transaction, if it is active.
66 * @return true if the transaction was committed
68 protected boolean commit() {
69 EntityTransaction tx = em.getTransaction();
78 * Roll back the current transaction, if it is active.
79 * @return true if the transaction was rolled back
81 protected boolean rollback() {
82 if (em != null && em.isOpen()) {
83 EntityTransaction tx = em.getTransaction();
96 * Closes the current EntityManager if it is open.
97 * @return false if the EntityManager was already closed
99 protected boolean close() {