From fded63f9d73cff5b22df6c5f765c9b105c99619f Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Wed, 26 Jun 2013 14:33:26 +0200
Subject: [PATCH] New lecture attempt

---
 ws/eclipse/Company/.gitignore            |  4 ++
 ws/eclipse/Company/Sql/200/deptCascade   | 18 +++++++++
 ws/eclipse/Company/Sql/200/schema.sql    | 35 ++++++++++++++++++
 ws/eclipse/Company/Sql/Final/data.sql    |  2 +
 ws/eclipse/Company/Sql/Final/deptCascade | 11 ++++++
 ws/eclipse/Company/Sql/Final/schema.sql  | 34 +++++++++++++++++
 ws/eclipse/Company/pom.xml               | 47 ++++++++++++++++++++++++
 ws/eclipse/Mediastore/Sql/200/schema.sql | 45 +++++++++++++++++++++++
 8 files changed, 196 insertions(+)
 create mode 100644 ws/eclipse/Company/.gitignore
 create mode 100644 ws/eclipse/Company/Sql/200/deptCascade
 create mode 100644 ws/eclipse/Company/Sql/200/schema.sql
 create mode 100644 ws/eclipse/Company/Sql/Final/data.sql
 create mode 100644 ws/eclipse/Company/Sql/Final/deptCascade
 create mode 100644 ws/eclipse/Company/Sql/Final/schema.sql
 create mode 100644 ws/eclipse/Company/pom.xml
 create mode 100644 ws/eclipse/Mediastore/Sql/200/schema.sql

diff --git a/ws/eclipse/Company/.gitignore b/ws/eclipse/Company/.gitignore
new file mode 100644
index 000000000..968391422
--- /dev/null
+++ b/ws/eclipse/Company/.gitignore
@@ -0,0 +1,4 @@
+/target
+.classpath
+.project
+.settings
\ No newline at end of file
diff --git a/ws/eclipse/Company/Sql/200/deptCascade b/ws/eclipse/Company/Sql/200/deptCascade
new file mode 100644
index 000000000..6d75a5398
--- /dev/null
+++ b/ws/eclipse/Company/Sql/200/deptCascade
@@ -0,0 +1,18 @@
+drop table if exists Employee; 
+drop table if exists Department; 
+
+CREATE TABLE Department(  
+   id BIGINT PRIMARY KEY 
+  ,name CHAR(20) NOT NULL UNIQUE
+);
+
+CREATE TABLE Employee (
+   id BIGINT PRIMARY KEY
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL
+  ,surname CHAR(20) NOT NULL
+  ,department CHAR(20) NOT NULL REFERENCES Department(name)
+    ON UPDATE CASCADE
+  ,telephone CHAR(4) NOT NULL
+  ,fax CHAR(4) 
+);
\ No newline at end of file
diff --git a/ws/eclipse/Company/Sql/200/schema.sql b/ws/eclipse/Company/Sql/200/schema.sql
new file mode 100644
index 000000000..fe4a1282b
--- /dev/null
+++ b/ws/eclipse/Company/Sql/200/schema.sql
@@ -0,0 +1,35 @@
+drop table if exists Employee; 
+drop table if exists Project; 
+drop table if exists Department; 
+drop table if exists EmployeeProject;
+
+CREATE TABLE Department(  
+   id BIGINT PRIMARY KEY 
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL UNIQUE
+);
+
+CREATE TABLE Employee (
+   id BIGINT PRIMARY KEY
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL
+  ,surname CHAR(20) NOT NULL
+  ,department BIGINT NOT NULL REFERENCES Department    
+  ,telephone CHAR(4) NOT NULL
+  ,fax CHAR(4) 
+);
+
+CREATE TABLE Project (
+   id BIGINT PRIMARY KEY
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL UNIQUE
+  ,status SMALLINT NOT NULL
+  ,CHECK (status IN (1,2,3,3)) -- planned, active, on hold, finished --
+);
+
+CREATE TABLE EmployeeProject (
+   employee BIGINT NOT NULL REFERENCES Employee
+  ,project BIGINT NOT NULL REFERENCES Project
+  ,PRIMARY KEY(employee, project)
+  ,weeklyHours INTEGER NOT NULL
+)
\ No newline at end of file
diff --git a/ws/eclipse/Company/Sql/Final/data.sql b/ws/eclipse/Company/Sql/Final/data.sql
new file mode 100644
index 000000000..120de18e2
--- /dev/null
+++ b/ws/eclipse/Company/Sql/Final/data.sql
@@ -0,0 +1,2 @@
+INSERT INTO Department VALUES(1, 12, "Sales", NULL);
+
diff --git a/ws/eclipse/Company/Sql/Final/deptCascade b/ws/eclipse/Company/Sql/Final/deptCascade
new file mode 100644
index 000000000..0749ece5d
--- /dev/null
+++ b/ws/eclipse/Company/Sql/Final/deptCascade
@@ -0,0 +1,11 @@
+drop table if exists Department; 
+
+CREATE TABLE Department(  
+   id BIGINT PRIMARY KEY 
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL UNIQUE
+  ,parent CHAR(20) REFERENCES Department (name)
+    ON UPDATE CASCADE
+    ON DELETE SET NULL
+);  
+
diff --git a/ws/eclipse/Company/Sql/Final/schema.sql b/ws/eclipse/Company/Sql/Final/schema.sql
new file mode 100644
index 000000000..cafe92daf
--- /dev/null
+++ b/ws/eclipse/Company/Sql/Final/schema.sql
@@ -0,0 +1,34 @@
+drop table if exists Employee; 
+drop table if exists Project; 
+drop table if exists Department; 
+drop table if exists EmployeeProject;
+
+CREATE TABLE Department(  
+   id BIGINT PRIMARY KEY 
+   number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL UNIQUE
+  ,parent BIGINT REFERENCES Department
+);
+
+CREATE TABLE Project (
+   id BIGINT PRIMARY KEY
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL UNIQUE
+);
+
+CREATE TABLE Employee (
+   id BIGINT PRIMARY KEY
+  ,number INTEGER NOT NULL UNIQUE
+  ,name CHAR(20) NOT NULL
+  ,surname CHAR(20) NOT NULL
+  ,department BIGINT NOT NULL REFERENCES Department
+  ,telephone CHAR(4) NOT NULL
+  ,fax CHAR(4) 
+);
+
+CREATE TABLE EmployeeProject (
+   employee BIGINT NOT NULL REFERENCES Employee
+  ,project BIGINT NOT NULL REFERENCES Project
+  ,PRIMARY KEY(employee, project)
+  ,weeklyHours INTEGER NOT NULL
+)
\ No newline at end of file
diff --git a/ws/eclipse/Company/pom.xml b/ws/eclipse/Company/pom.xml
new file mode 100644
index 000000000..61e62a760
--- /dev/null
+++ b/ws/eclipse/Company/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>Company</groupId>
+	<artifactId>Company</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<name>de.hdm-stuttgart.mi.company</name>
+	<url>http://maven.apache.org</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+		</plugins>
+		<resources>
+			<resource>
+				<directory>src/main/java</directory>
+				<includes>
+					<include> **/*.properties</include>
+				</includes>
+			</resource>
+		</resources>
+
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>5.1.23</version>
+		</dependency>
+	</dependencies>
+</project>
diff --git a/ws/eclipse/Mediastore/Sql/200/schema.sql b/ws/eclipse/Mediastore/Sql/200/schema.sql
new file mode 100644
index 000000000..5bb0eab90
--- /dev/null
+++ b/ws/eclipse/Mediastore/Sql/200/schema.sql
@@ -0,0 +1,45 @@
+drop table if exists ArtistAlbum;
+drop table if exists Artist; 
+drop table if exists Track; 
+drop table if exists Album; 
+drop table if exists Format; 
+
+
+CREATE TABLE Format (  
+   id BIGINT PRIMARY KEY 
+  ,name CHAR(20) NOT NULL UNIQUE
+  ,format SMALLINT NOT NULL
+);
+
+CREATE TABLE Album (  
+   id BIGINT PRIMARY KEY 
+  ,name CHAR(20) NOT NULL UNIQUE
+);
+
+CREATE TABLE Track (  
+   name CHAR(20) NOT NULL UNIQUE
+  ,album BIGINT NOT NULL REFERENCES Album
+    ON DELETE CASCADE
+  ,UNIQUE (name, album)
+  ,format SMALLINT NOT NULL
+  ,CHECK (format in (1,2,3)) -- Mp3, Flac, Mp4
+);
+
+CREATE TABLE Artist (  
+   id BIGINT PRIMARY KEY 
+  ,name CHAR(20) NOT NULL
+  ,surname CHAR(20) NOT NULL
+  ,sex SMALLINT NOT NULL
+  ,CHECK (sex in (1,2))  -- female, male --
+);
+
+CREATE TABLE ArtistAlbum (  
+   artist BIGINT NOT NULL REFERENCES Artist
+  ,album BIGINT NOT NULL REFERENCES Album
+  ,PRIMARY KEY(artist, album)
+  ,name CHAR(20) NOT NULL UNIQUE
+  ,isLead BOOLEAN NOT NULL
+);
+
+
+
-- 
GitLab