MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransactionStateTest.java
1 /*
2  Copyright 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
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.
8 
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.
13 
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
17 */
18 
19 package testsuite.clusterj;
20 
21 import com.mysql.clusterj.ClusterJException;
22 
24 
25  @Override
26  public void localSetUp() {
27  createSessionFactory();
28  session = sessionFactory.getSession();
29  tx = session.currentTransaction();
30  }
31 
32  public void test() {
33  beginAfterBegin();
34  rollbackWithoutBegin();
35  commitWithoutBegin();
36  commitWithSetRollbackOnly();
37  failOnError();
38  }
39 
40  private void beginAfterBegin() {
41  try {
42  tx.begin();
43  tx.begin(); // should throw exception
44  error("Begin after begin failed to throw exception.");
45  } catch (ClusterJException ex) {
46  // good catch
47  errorIfNotEqual("Begin after begin should leave transaction active",
48  true, tx.isActive());
49  } finally {
50  tx.commit();
51  }
52  }
53 
54  private void commitWithSetRollbackOnly() {
55  try {
56  tx.begin();
57  tx.setRollbackOnly();
58  tx.commit(); // should throw exception
59  error("Commit after setRollbackOnly failed to throw exception.");
60  } catch (ClusterJException ex) {
61  // good catch
62  errorIfNotEqual("Commit after setRollbackOnly should leave transaction not active",
63  false, tx.isActive());
64  }
65  }
66 
67  private void commitWithoutBegin() {
68  try {
69  tx.commit(); // should throw exception
70  error("Commit without begin failed to throw exception.");
71  } catch (ClusterJException ex) {
72  // good catch
73  errorIfNotEqual("Commit without begin should leave transaction not active",
74  false, tx.isActive());
75  }
76  }
77 
78  private void rollbackWithoutBegin() {
79  try {
80  tx.rollback(); // should throw exception
81  error("Rollback without begin failed to throw exception.");
82  } catch (ClusterJException ex) {
83  // good catch
84  errorIfNotEqual("Rollback without begin should leave transaction not active",
85  false, tx.isActive());
86  }
87  }
88 
89 }