-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimexhsqldb.xml
115 lines (104 loc) · 4.12 KB
/
timexhsqldb.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?xml version="1.0"?>
<project name="timexdb">
<property name="hjar" value="../lib/hsqldb.jar"/>
<property name="hclass" value="org.hsqldb.Server"/>
<property name="hfile" value="-database.0 data/timexdb"/>
<property name="halias" value="timex"/>
<property name="hport" value="9005"/>
<target name="starthsql">
<java fork="true"
classname="${hclass}" classpath="${hjar}"
args="${hfile} -dbname.0 ${halias} -port ${hport}"/>
</target>
<target name="execddl">
<sql classpath="${hjar}"
driver="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:hsql://localhost:${hport}/${halias}"
userid="sa" password=""
print="yes">
-- SQL script for TimeX
-- Step 1: Drop objects if they exist
DROP TABLE Department IF EXISTS;
DROP TABLE Employee IF EXISTS;
DROP TABLE Timesheet IF EXISTS;
DROP INDEX TimesheetIndex IF EXISTS;
DROP INDEX DepartmentCodeIndex IF EXISTS;
DROP INDEX EmployeeIdIndex IF EXISTS;
-- Step 2: Create tables
CREATE TABLE Department
(
departmentCode CHAR(2) NOT NULL,
name VARCHAR(255) NOT NULL
);
CREATE TABLE Employee
(
employeeId INT NOT NULL,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL,
employeeCode CHAR(1) NOT NULL,
password VARCHAR(10) NOT NULL,
managerEmployeeId INT NULL
);
CREATE TABLE Timesheet
(
timesheetId IDENTITY NOT NULL,
employeeId INT NOT NULL,
statusCode CHAR(1) NOT NULL,
periodEndingDate DATE NOT NULL,
departmentCode CHAR(4) NOT NULL,
minutesMon INT NULL,
minutesTue INT NULL,
minutesWed INT NULL,
minutesThu INT NULL,
minutesFri INT NULL,
minutesSat INT NULL,
minutesSun INT NULL
);
-- Step 3: Create indexes
CREATE UNIQUE INDEX TimesheetIndex ON Timesheet (employeeId, periodEndingDate);
CREATE UNIQUE INDEX DepartmentCodeIndex ON Department (departmentCode);
CREATE UNIQUE INDEX EmployeeIdIndex ON Employee (employeeId);
-- Step 4: Insert some reference and test data
INSERT INTO Department (departmentCode, name)
VALUES ('AC', 'Accounting');
INSERT INTO Department (departmentCode, name)
VALUES ('CS', 'Customer Support');
INSERT INTO Department (departmentCode, name)
VALUES ('HR', 'Human Resources');
INSERT INTO Department (departmentCode, name)
VALUES ('IT', 'Information Technology');
INSERT INTO Employee (employeeId, name, employeeCode,
password, email, managerEmployeeId)
VALUES (1, 'Mike Dover', 'H', 'rapidjava', '[email protected]', 3);
INSERT INTO Employee (employeeId, name, employeeCode,
password, email, managerEmployeeId)
VALUES (2, 'Ajay Kumar', 'H', 'visualpatterns', '[email protected]', 3);
INSERT INTO Employee (employeeId, name, employeeCode,
password, email, managerEmployeeId)
VALUES (3, 'Teresa Walker', 'M', 'agilestuff', '[email protected]', 4);
INSERT INTO Employee (employeeId, name, employeeCode,
password, email)
VALUES (4, 'Tom Brady', 'E', 'superbowl', '[email protected]');
INSERT INTO Timesheet(timesheetId, employeeId, statusCode, periodEndingDate,
departmentCode, minutesMon, minutesTue, minutesWed,
minutesThu, minutesFri, minutesSat, minutesSun)
VALUES (1, 2, 'P', '2006-08-19', 'IT', 480, 480, 360, 480, 480, 0, 0);
INSERT INTO Timesheet(timesheetId, employeeId, statusCode, periodEndingDate,
departmentCode, minutesMon, minutesTue, minutesWed,
minutesThu, minutesFri, minutesSat, minutesSun)
VALUES (2, 1, 'A', '2006-08-19', 'HR', 0, 0, 480, 480, 480, 0, 0);
-- Step 5: Verify tables and test data look ok
SELECT * FROM Department;
SELECT * FROM Employee;
SELECT * FROM Timesheet;
</sql>
</target>
<target name="hsqldm">
<java fork="true" classpath="${hjar}"
classname="org.hsqldb.util.DatabaseManagerSwing" />
</target>
<target name="sqltool">
<java fork="true" classpath="${hjar}"
classname="org.hsqldb.util.SqlTool" args="localhost-sa"/>
</target>
</project>