01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.mvcc;
07:
08: import java.sql.Connection;
09: import java.sql.Statement;
10:
11: import org.h2.test.TestBase;
12:
13: /**
14: * Additional MVCC (multi version concurrency) test cases.
15: */
16: public class TestMvcc2 extends TestBase {
17:
18: private static final String DROP_TABLE = "DROP TABLE IF EXISTS EMPLOYEE";
19: private static final String CREATE_TABLE = "CREATE TABLE EMPLOYEE (id BIGINT, version BIGINT, NAME VARCHAR(255))";
20: private static final String INSERT = "INSERT INTO EMPLOYEE (id, version, NAME) VALUES (1, 1, 'Jones')";
21: private static final String UPDATE = "UPDATE EMPLOYEE SET NAME = 'Miller' WHERE version = 1";
22:
23: public void test() throws Exception {
24: if (!config.mvcc) {
25: return;
26: }
27: deleteDb("mvcc2");
28: testInsertUpdateRollback();
29: testInsertRollback();
30: }
31:
32: Connection getConnection() throws Exception {
33: return getConnection("mvcc2");
34: }
35:
36: public void testInsertUpdateRollback() throws Exception {
37: Connection conn = getConnection();
38: conn.setAutoCommit(false);
39: Statement stmt = conn.createStatement();
40: stmt.execute(DROP_TABLE);
41: stmt.execute(CREATE_TABLE);
42: conn.commit();
43: stmt.execute(INSERT);
44: stmt.execute(UPDATE);
45: conn.rollback();
46: conn.close();
47: }
48:
49: public void testInsertRollback() throws Exception {
50: Connection conn = getConnection();
51: conn.setAutoCommit(false);
52: Statement stmt = conn.createStatement();
53: stmt.execute(DROP_TABLE);
54: stmt.execute(CREATE_TABLE);
55: conn.commit();
56: stmt.execute(INSERT);
57: conn.rollback();
58: conn.close();
59: }
60:
61: }
|