Mercurial > hg > monetdb-java
comparison tests/Test_Sbatching.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_Sbatching { | |
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 try { | |
23 System.out.print("1. create..."); | |
24 if (stmt.executeUpdate("CREATE TABLE table_Test_Sbatching ( id int )") != Statement.SUCCESS_NO_INFO) | |
25 throw new SQLException("Wrong return status"); | |
26 System.out.println("passed :)"); | |
27 | |
28 // start batching a large amount of inserts | |
29 for (int i = 1; i <= 30000; i++) { | |
30 stmt.addBatch("INSERT INTO table_Test_Sbatching VALUES (" + i + ")"); | |
31 if (i % 400 == 0) { | |
32 System.out.print("2. executing batch (400 inserts)..."); | |
33 int[] cnts = stmt.executeBatch(); | |
34 System.out.println("passed :)"); | |
35 System.out.print("3. checking number of update counts..."); | |
36 if (cnts.length != 400) throw new SQLException("Invalid size: " + cnts.length); | |
37 System.out.println(cnts.length + " passed :)"); | |
38 System.out.print("4. checking update counts (should all be 1)..."); | |
39 for (int j = 0; j < cnts.length; j++) { | |
40 if (cnts[j] != 1) throw new SQLException("Unexpected value: " + cnts[j]); | |
41 } | |
42 System.out.println("passed :)"); | |
43 System.out.print("5. clearing the batch..."); | |
44 stmt.clearBatch(); | |
45 System.out.println("passed :)"); | |
46 } | |
47 } | |
48 System.out.print("6. executing batch..."); | |
49 stmt.executeBatch(); | |
50 System.out.println("passed :)"); | |
51 | |
52 System.out.print("7. checking table count..."); | |
53 rs = stmt.executeQuery("SELECT COUNT(*) FROM table_Test_Sbatching"); | |
54 rs.next(); | |
55 System.out.println(rs.getInt(1) + " passed :)"); | |
56 | |
57 System.out.print("8. clean up mess we made..."); | |
58 if (stmt.executeUpdate("DROP TABLE table_Test_Sbatching") != Statement.SUCCESS_NO_INFO) | |
59 throw new SQLException("Wrong return status"); | |
60 System.out.println("passed :)"); | |
61 } catch (SQLException e) { | |
62 // this means we failed (table not there perhaps?) | |
63 System.out.println("FAILED :( " + e.getMessage()); | |
64 System.out.println("ABORTING TEST!!!"); | |
65 } | |
66 | |
67 if (rs != null) rs.close(); | |
68 | |
69 con.close(); | |
70 } | |
71 } |