Mercurial > hg > monetdb-java
comparison tests/Test_Ctransaction.java @ 0:a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Wed, 21 Sep 2016 09:34:48 +0200 (2016-09-21) |
parents | |
children | 04fbf3655452 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a5a898f6886c |
---|---|
1 /* | |
2 * This Source Code Form is subject to the terms of the Mozilla Public | |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
5 * | |
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. | |
7 */ | |
8 | |
9 import java.sql.*; | |
10 | |
11 public class Test_Ctransaction { | |
12 public static void main(String[] args) throws Exception { | |
13 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); | |
14 Connection con1 = DriverManager.getConnection(args[0]); | |
15 Statement stmt1 = con1.createStatement(); | |
16 //DatabaseMetaData dbmd = con.getMetaData(); | |
17 | |
18 // >> true: auto commit should be on by default | |
19 System.out.println("0. true\t" + con1.getAutoCommit()); | |
20 | |
21 // test commit by checking if a change is visible in another connection | |
22 try { | |
23 System.out.print("1. commit..."); | |
24 con1.commit(); | |
25 System.out.println("PASSED :("); | |
26 con1.close(); | |
27 System.exit(-1); | |
28 } catch (SQLException e) { | |
29 // this means we get what we expect | |
30 System.out.println("failed :) " + e.getMessage()); | |
31 } | |
32 | |
33 // turn off auto commit | |
34 con1.setAutoCommit(false); | |
35 | |
36 // >> false: we just disabled it | |
37 System.out.println("2. false\t" + con1.getAutoCommit()); | |
38 | |
39 // a change would not be visible now | |
40 try { | |
41 System.out.print("3. commit..."); | |
42 con1.commit(); | |
43 System.out.println("passed :)"); | |
44 System.out.print("4. commit..."); | |
45 con1.commit(); | |
46 System.out.println("passed :)"); | |
47 System.out.print("5. rollback..."); | |
48 con1.rollback(); | |
49 System.out.println("passed :)"); | |
50 } catch (SQLException e) { | |
51 // this means we failed (table not there perhaps?) | |
52 System.out.println("FAILED :( " + e.getMessage()); | |
53 System.out.println("ABORTING TEST!!!"); | |
54 con1.close(); | |
55 System.exit(-1); | |
56 } | |
57 | |
58 // turn off auto commit | |
59 con1.setAutoCommit(true); | |
60 | |
61 // >> false: we just disabled it | |
62 System.out.println("6. true\t" + con1.getAutoCommit()); | |
63 | |
64 try { | |
65 System.out.print("7. start transaction..."); | |
66 stmt1.executeUpdate("START TRANSACTION"); | |
67 System.out.println("passed :)"); | |
68 System.out.print("8. commit..."); | |
69 con1.commit(); | |
70 System.out.println("passed :)"); | |
71 System.out.println("9. true\t" + con1.getAutoCommit()); | |
72 System.out.print("10. start transaction..."); | |
73 stmt1.executeUpdate("START TRANSACTION"); | |
74 System.out.println("passed :)"); | |
75 System.out.print("11. rollback..."); | |
76 con1.rollback(); | |
77 System.out.println("passed :)"); | |
78 System.out.println("12. true\t" + con1.getAutoCommit()); | |
79 } catch (SQLException e) { | |
80 // this means we failed (table not there perhaps?) | |
81 System.out.println("FAILED :("); | |
82 System.out.println("ABORTING TEST!!!"); | |
83 } | |
84 | |
85 try { | |
86 // a commit now should fail | |
87 System.out.print("13. commit..."); | |
88 con1.commit(); | |
89 System.out.println("PASSED :("); | |
90 } catch (SQLException e) { | |
91 // this means we get what we expect | |
92 System.out.println("failed :) " + e.getMessage()); | |
93 } | |
94 | |
95 con1.close(); | |
96 } | |
97 } |