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 testsuite.clusterj;
21 import com.mysql.clusterj.ClusterJException;
23 public class TransactionStateTest extends AbstractClusterJModelTest {
26 public void localSetUp() {
27 createSessionFactory();
28 session = sessionFactory.getSession();
29 tx = session.currentTransaction();
34 rollbackWithoutBegin();
36 commitWithSetRollbackOnly();
40 private void beginAfterBegin() {
43 tx.begin(); // should throw exception
44 error("Begin after begin failed to throw exception.");
45 } catch (ClusterJException ex) {
47 errorIfNotEqual("Begin after begin should leave transaction active",
54 private void commitWithSetRollbackOnly() {
58 tx.commit(); // should throw exception
59 error("Commit after setRollbackOnly failed to throw exception.");
60 } catch (ClusterJException ex) {
62 errorIfNotEqual("Commit after setRollbackOnly should leave transaction not active",
63 false, tx.isActive());
67 private void commitWithoutBegin() {
69 tx.commit(); // should throw exception
70 error("Commit without begin failed to throw exception.");
71 } catch (ClusterJException ex) {
73 errorIfNotEqual("Commit without begin should leave transaction not active",
74 false, tx.isActive());
78 private void rollbackWithoutBegin() {
80 tx.rollback(); // should throw exception
81 error("Rollback without begin failed to throw exception.");
82 } catch (ClusterJException ex) {
84 errorIfNotEqual("Rollback without begin should leave transaction not active",
85 false, tx.isActive());