001: package allinone;
002:
003: import java.sql.*;
004:
005: public class MakeDB {
006: public static void main(String[] argv) throws Throwable {
007: Class.forName("org.hsqldb.jdbcDriver");
008: Connection conn = DriverManager.getConnection(
009: "jdbc:hsqldb:allinoneDB", "sa", "");
010: Statement stmt = conn.createStatement();
011: stmt
012: .execute("create table TableDCC (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftod DECIMAL (19,0) NOT NULL)");
013: stmt.close();
014: stmt = conn.createStatement();
015: stmt
016: .execute("create table TableNDCC (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftod DECIMAL (19,0) NOT NULL)");
017: stmt.close();
018: stmt = conn.createStatement();
019: stmt
020: .execute("create table TableCRC (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftoa DECIMAL (19,0))");
021: stmt.close();
022: stmt = conn.createStatement();
023: stmt
024: .execute("create table personSelfRef (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , login VARCHAR (32) NOT NULL , password VARCHAR (32) NOT NULL , firstname VARCHAR (32) NOT NULL , lastname VARCHAR (32) NOT NULL , boss DECIMAL (19,0))");
025: stmt.close();
026: stmt = conn.createStatement();
027: stmt
028: .execute("create table personT (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , login VARCHAR (32) NOT NULL , password VARCHAR (32) NOT NULL , firstname VARCHAR (32) NOT NULL , lastname VARCHAR (32) NOT NULL , favouredDisc DECIMAL (19,0))");
029: stmt.close();
030: stmt = conn.createStatement();
031: stmt
032: .execute("create table TableDCA (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftob DECIMAL (19,0) NOT NULL , reftoc DECIMAL (19,0) NOT NULL)");
033: stmt.close();
034: stmt = conn.createStatement();
035: stmt
036: .execute("create table TableNDCA (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftob DECIMAL (19,0) NOT NULL , reftoc DECIMAL (19,0) NOT NULL)");
037: stmt.close();
038: stmt = conn.createStatement();
039: stmt
040: .execute("create table TableCRA (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftob DECIMAL (19,0))");
041: stmt.close();
042: stmt = conn.createStatement();
043: stmt
044: .execute("create table discT (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , title VARCHAR (32) NOT NULL , artist VARCHAR (32) NOT NULL , genre VARCHAR (32) NOT NULL , owner DECIMAL (19,0) NOT NULL , isLiked INTEGER NOT NULL)");
045: stmt.close();
046: stmt = conn.createStatement();
047: stmt
048: .execute("create table TableCRB (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftoc DECIMAL (19,0))");
049: stmt.close();
050: stmt = conn.createStatement();
051: stmt
052: .execute("create table TableNDCB (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftod DECIMAL (19,0) NOT NULL)");
053: stmt.close();
054: stmt = conn.createStatement();
055: stmt
056: .execute("create table TableDCB (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL , reftod DECIMAL (19,0) NOT NULL)");
057: stmt.close();
058: stmt = conn.createStatement();
059: stmt
060: .execute("create table TableDCD (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL)");
061: stmt.close();
062: stmt = conn.createStatement();
063: stmt
064: .execute("create table TableNDCD (oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER , somedata VARCHAR (32) NOT NULL)");
065: stmt.close();
066: stmt = conn.createStatement();
067: stmt.execute("create table ObjectId (nextoid DECIMAL (19,0))");
068: stmt.close();
069: stmt = conn.createStatement();
070: stmt
071: .execute("create table tableA2 ( oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER NOT NULL , somedata VARCHAR (32) NOT NULL)");
072: stmt.close();
073: stmt = conn.createStatement();
074: stmt
075: .execute("create table tableC2 ( oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER NOT NULL , somedata VARCHAR (32) NOT NULL , reftoa DECIMAL (19,0), reftob DECIMAL (19,0))");
076: stmt.close();
077: stmt = conn.createStatement();
078: stmt
079: .execute("create table tableB2 ( oid DECIMAL (19,0) NOT NULL PRIMARY KEY, version INTEGER NOT NULL , somedata VARCHAR (32) NOT NULL , reftoa DECIMAL (19,0) , reftob DECIMAL (19,0));");
080: stmt.close();
081: conn.commit();
082: conn.close();
083:
084: conn = DriverManager.getConnection("jdbc:hsqldb:allinoneDB",
085: "sa", "");
086: stmt = conn.createStatement();
087: stmt
088: .execute("ALTER TABLE TableDCC ADD CONSTRAINT FK_TableDCC_1 FOREIGN KEY (reftod) REFERENCES TableDCD (oid)");
089: stmt.close();
090: stmt = conn.createStatement();
091: stmt
092: .execute("ALTER TABLE TableNDCC ADD CONSTRAINT FK_TableNDCC_1 FOREIGN KEY (reftod) REFERENCES TableNDCD (oid)");
093: stmt.close();
094: stmt = conn.createStatement();
095: stmt
096: .execute("ALTER TABLE TableCRC ADD CONSTRAINT FK_TableCRC_1 FOREIGN KEY (reftoa) REFERENCES TableCRA (oid)");
097: stmt.close();
098: stmt = conn.createStatement();
099: stmt
100: .execute("ALTER TABLE personSelfRef ADD CONSTRAINT FK_personSelfRef_1 FOREIGN KEY (boss) REFERENCES personSelfRef (oid)");
101: stmt.close();
102: stmt = conn.createStatement();
103: stmt
104: .execute("ALTER TABLE personT ADD CONSTRAINT FK_personT_1 FOREIGN KEY (favouredDisc) REFERENCES discT (oid)");
105: stmt.close();
106: stmt = conn.createStatement();
107: stmt
108: .execute("ALTER TABLE TableDCA ADD CONSTRAINT FK_TableDCA_1 FOREIGN KEY (reftob) REFERENCES TableDCB (oid)");
109: stmt.close();
110: stmt = conn.createStatement();
111: stmt
112: .execute("ALTER TABLE TableDCA ADD CONSTRAINT FK_TableDCA_2 FOREIGN KEY (reftoc) REFERENCES TableDCC (oid)");
113: stmt.close();
114: stmt = conn.createStatement();
115: stmt
116: .execute("ALTER TABLE TableNDCA ADD CONSTRAINT FK_TableNDCA_1 FOREIGN KEY (reftob) REFERENCES TableNDCB (oid)");
117: stmt.close();
118: stmt = conn.createStatement();
119: stmt
120: .execute("ALTER TABLE TableNDCA ADD CONSTRAINT FK_TableNDCA_2 FOREIGN KEY (reftoc) REFERENCES TableNDCC (oid)");
121: stmt.close();
122: stmt = conn.createStatement();
123: stmt
124: .execute("ALTER TABLE TableCRA ADD CONSTRAINT FK_TableCRA_1 FOREIGN KEY (reftob) REFERENCES TableCRB (oid)");
125: stmt.close();
126: stmt = conn.createStatement();
127: stmt
128: .execute("ALTER TABLE discT ADD CONSTRAINT FK_discT_1 FOREIGN KEY (owner) REFERENCES personT (oid)");
129: stmt.close();
130: stmt = conn.createStatement();
131: stmt
132: .execute("ALTER TABLE TableCRB ADD CONSTRAINT FK_TableCRB_1 FOREIGN KEY (reftoc) REFERENCES TableCRC (oid)");
133: stmt.close();
134: stmt = conn.createStatement();
135: stmt
136: .execute("ALTER TABLE TableNDCB ADD CONSTRAINT FK_TableNDCB_1 FOREIGN KEY (reftod) REFERENCES TableNDCD (oid)");
137: stmt.close();
138: stmt = conn.createStatement();
139: stmt
140: .execute("ALTER TABLE TableDCB ADD CONSTRAINT FK_TableDCB_1 FOREIGN KEY (reftod) REFERENCES TableDCD (oid)");
141: stmt.close();
142: stmt = conn.createStatement();
143: stmt
144: .execute("ALTER TABLE tableC2 ADD CONSTRAINT tableC2_reftoa FOREIGN KEY (reftoa) REFERENCES tableA2 (oid)");
145: stmt.close();
146: stmt = conn.createStatement();
147: stmt
148: .execute("ALTER TABLE tableC2 ADD CONSTRAINT tableC2_reftob FOREIGN KEY (reftob) REFERENCES tableB2 (oid)");
149: stmt.close();
150: stmt = conn.createStatement();
151: stmt
152: .execute("ALTER TABLE tableB2 ADD CONSTRAINT tableB2_reftoa FOREIGN KEY (reftoa) REFERENCES tableA2 (oid)");
153: stmt.close();
154: stmt = conn.createStatement();
155: stmt
156: .execute("ALTER TABLE tableB2 ADD CONSTRAINT tableB2_reftob FOREIGN KEY (reftob) REFERENCES tableB2 (oid)");
157: stmt.close();
158: conn.commit();
159: conn.close();
160: }
161: }
|