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.synth.sql;
07:
08: import java.sql.SQLException;
09: import java.util.ArrayList;
10:
11: /**
12: * Represents a connection to a simulated database.
13: */
14: public class DbState implements DbInterface {
15:
16: private TestSynth config;
17: private ArrayList tables = new ArrayList();
18: private ArrayList indexes = new ArrayList();
19: boolean connected;
20: boolean autoCommit;
21:
22: DbState(TestSynth config) {
23: this .config = config;
24: }
25:
26: public void reset() throws SQLException {
27: tables = new ArrayList();
28: indexes = new ArrayList();
29: }
30:
31: public void connect() throws SQLException {
32: connected = true;
33: }
34:
35: public void disconnect() throws SQLException {
36: connected = false;
37: }
38:
39: public void createTable(Table table) throws SQLException {
40: tables.add(table);
41: }
42:
43: public void dropTable(Table table) throws SQLException {
44: tables.remove(table);
45: }
46:
47: public void createIndex(Index index) throws SQLException {
48: indexes.add(index);
49: }
50:
51: public void dropIndex(Index index) throws SQLException {
52: indexes.remove(index);
53: }
54:
55: public Result insert(Table table, Column[] c, Value[] v)
56: throws SQLException {
57: return null;
58: }
59:
60: public Result select(String sql) throws SQLException {
61: return null;
62: }
63:
64: public Result delete(Table table, String condition)
65: throws SQLException {
66: return null;
67: }
68:
69: public Result update(Table table, Column[] columns, Value[] values,
70: String condition) {
71: return null;
72: }
73:
74: public void setAutoCommit(boolean b) throws SQLException {
75: autoCommit = b;
76: }
77:
78: public void commit() throws SQLException {
79: }
80:
81: public void rollback() throws SQLException {
82: }
83:
84: public Table randomTable() {
85: if (tables.size() == 0) {
86: return null;
87: }
88: int i = config.random().getInt(tables.size());
89: return (Table) tables.get(i);
90: }
91:
92: public void end() throws SQLException {
93: }
94:
95: }
|