Mercurial > hg > monetdb-java
comparison tests/Test_Csavepoints.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_Csavepoints { | |
12 public static void main(String[] args) throws Exception { | |
13 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); | |
14 Connection con = DriverManager.getConnection(args[0]); | |
15 Statement stmt = con.createStatement(); | |
16 ResultSet rs = null; | |
17 //DatabaseMetaData dbmd = con.getMetaData(); | |
18 | |
19 // >> true: auto commit should be on by default | |
20 System.out.println("0. true\t" + con.getAutoCommit()); | |
21 | |
22 // savepoints require a non-autocommit connection | |
23 try { | |
24 System.out.print("1. savepoint..."); | |
25 con.setSavepoint(); | |
26 System.out.println("PASSED :("); | |
27 System.out.println("ABORTING TEST!!!"); | |
28 con.close(); | |
29 System.exit(-1); | |
30 } catch (SQLException e) { | |
31 System.out.println("failed :) " + e.getMessage()); | |
32 } | |
33 | |
34 con.setAutoCommit(false); | |
35 // >> true: auto commit should be on by default | |
36 System.out.println("0. false\t" + con.getAutoCommit()); | |
37 | |
38 try { | |
39 System.out.print("2. savepoint..."); | |
40 /* make a savepoint, and discard it */ | |
41 con.setSavepoint(); | |
42 System.out.println("passed :)"); | |
43 | |
44 stmt.executeUpdate("CREATE TABLE table_Test_Csavepoints ( id int, PRIMARY KEY (id) )"); | |
45 | |
46 System.out.print("3. savepoint..."); | |
47 Savepoint sp2 = con.setSavepoint("empty table"); | |
48 System.out.println("passed :)"); | |
49 | |
50 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); | |
51 int i = 0; | |
52 int items = 0; | |
53 System.out.print("4. table " + items + " items"); | |
54 while (rs.next()) { | |
55 System.out.print(", " + rs.getString("id")); | |
56 i++; | |
57 } | |
58 if (i != items) { | |
59 System.out.println(" FAILED (" + i + ") :("); | |
60 System.out.println("ABORTING TEST!!!"); | |
61 con.close(); | |
62 System.exit(-1); | |
63 } | |
64 System.out.println(" passed :)"); | |
65 | |
66 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (1)"); | |
67 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (2)"); | |
68 stmt.executeUpdate("INSERT INTO table_Test_Csavepoints VALUES (3)"); | |
69 | |
70 System.out.print("5. savepoint..."); | |
71 Savepoint sp3 = con.setSavepoint("three values"); | |
72 System.out.println("passed :)"); | |
73 | |
74 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); | |
75 i = 0; | |
76 items = 3; | |
77 System.out.print("6. table " + items + " items"); | |
78 while (rs.next()) { | |
79 System.out.print(", " + rs.getString("id")); | |
80 i++; | |
81 } | |
82 if (i != items) { | |
83 System.out.println(" FAILED (" + i + ") :("); | |
84 System.out.println("ABORTING TEST!!!"); | |
85 con.close(); | |
86 System.exit(-1); | |
87 } | |
88 System.out.println(" passed :)"); | |
89 | |
90 System.out.print("7. release..."); | |
91 con.releaseSavepoint(sp3); | |
92 System.out.println("passed :)"); | |
93 | |
94 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); | |
95 i = 0; | |
96 items = 3; | |
97 System.out.print("8. table " + items + " items"); | |
98 while (rs.next()) { | |
99 System.out.print(", " + rs.getString("id")); | |
100 i++; | |
101 } | |
102 if (i != items) { | |
103 System.out.println(" FAILED (" + i + ") :("); | |
104 System.out.println("ABORTING TEST!!!"); | |
105 con.close(); | |
106 System.exit(-1); | |
107 } | |
108 System.out.println(" passed :)"); | |
109 | |
110 System.out.print("9. rollback..."); | |
111 con.rollback(sp2); | |
112 System.out.println("passed :)"); | |
113 | |
114 rs = stmt.executeQuery("SELECT id FROM table_Test_Csavepoints"); | |
115 i = 0; | |
116 items = 0; | |
117 System.out.print("10. table " + items + " items"); | |
118 while (rs.next()) { | |
119 System.out.print(", " + rs.getString("id")); | |
120 i++; | |
121 } | |
122 if (i != items) { | |
123 System.out.println(" FAILED (" + i + ") :("); | |
124 System.out.println("ABORTING TEST!!!"); | |
125 con.close(); | |
126 System.exit(-1); | |
127 } | |
128 System.out.println(" passed :)"); | |
129 | |
130 con.rollback(); | |
131 } catch (SQLException e) { | |
132 System.out.println("FAILED :( "+ e.getMessage()); | |
133 System.out.println("ABORTING TEST!!!"); | |
134 } | |
135 | |
136 con.close(); | |
137 } | |
138 } |