Nick Satinover 5 years ago
parent
commit
137b00fdf1

+ 0
- 1
data-h2.sql View File

@@ -12,4 +12,3 @@ INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('S
12 12
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
13 13
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);
14 14
 
15
-

+ 66
- 0
src/main/java/io/zipcoder/persistenceapp/Movie.java View File

@@ -0,0 +1,66 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.Id;
6
+
7
+@Entity
8
+public class Movie {
9
+
10
+    @Id
11
+    @GeneratedValue
12
+    private int id;
13
+    private String title;
14
+    private int runtime;
15
+    private String genre;
16
+    private double IMDB_Score;
17
+    private MovieRating rating;
18
+
19
+    public Movie(String title, int runtime, String genre, double IMDB_Score, MovieRating rating) {
20
+        this.title = title;
21
+        this.runtime = runtime;
22
+        this.genre = genre;
23
+        this.IMDB_Score = IMDB_Score;
24
+        this.rating = rating;
25
+    }
26
+
27
+    public String getTitle() {
28
+        return title;
29
+    }
30
+
31
+    public void setTitle(String title) {
32
+        this.title = title;
33
+    }
34
+
35
+    public int getRuntime() {
36
+        return runtime;
37
+    }
38
+
39
+    public void setRuntime(int runtime) {
40
+        this.runtime = runtime;
41
+    }
42
+
43
+    public String getGenre() {
44
+        return genre;
45
+    }
46
+
47
+    public void setGenre(String genre) {
48
+        this.genre = genre;
49
+    }
50
+
51
+    public double getIMDB_Score() {
52
+        return IMDB_Score;
53
+    }
54
+
55
+    public void setIMDB_Score(double IMDB_Score) {
56
+        this.IMDB_Score = IMDB_Score;
57
+    }
58
+
59
+    public MovieRating getRating() {
60
+        return rating;
61
+    }
62
+
63
+    public void setRating(MovieRating rating) {
64
+        this.rating = rating;
65
+    }
66
+}

+ 21
- 0
src/main/java/io/zipcoder/persistenceapp/MovieRating.java View File

@@ -0,0 +1,21 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+public enum MovieRating {
4
+
5
+    G("G"),
6
+    PG("PG"),
7
+    TV14("TV-14"),
8
+    PG13("PG-13"),
9
+    R("R");
10
+
11
+    private String rating;
12
+
13
+    private MovieRating(String s){
14
+        this.rating = s;
15
+    }
16
+
17
+    public String getRating(){
18
+        return rating;
19
+    }
20
+
21
+}

+ 8
- 0
src/main/resources/data.sql View File

@@ -0,0 +1,8 @@
1
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Howard the Duck', 110, 'Sci-Fi', 4.6, 'PG');
2
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Lavalantula', 83, 'Horror', 4.7, 'TV-14');
3
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Starship Troopers', 129, 'Sci-Fi', 7.2, 'PG-13');
4
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Waltz With Bashir', 90, 'Documentary', 8.0, 'R');
5
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Spaceballs', 96, 'Comedy', 7.1, 'PG');
6
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Monsters Inc.', 92, 'Animation', 8.1, 'G');
7
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Infinity War', 149, 'Action', 8.5, 'PG-13');
8
+

+ 1
- 0
src/main/resources/schema-h2.sql View File

@@ -64,3 +64,4 @@ CREATE TABLE auto_prices (
64 64
 DROP SEQUENCE hibernate_sequence;
65 65
 
66 66
 CREATE SEQUENCE hibernate_sequence;
67
+

+ 18
- 0
src/main/resources/script.sql View File

@@ -0,0 +1,18 @@
1
+CREATE TABLE MOVIES
2
+(
3
+  ID INT PRIMARY KEY,
4
+  Title VARCHAR,
5
+  Runtime NUMBER,
6
+  Genre VARCHAR ,
7
+  IMDB_Score DOUBLE ,
8
+  RATING VARCHAR
9
+  );
10
+
11
+INSERT INTO MOVIES ( TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES ('Infinity War', 149, 'Action', 8.5, 'PG-13');
12
+
13
+SELECT * FROM MOVIES WHERE GENRE='Sci-Fi';
14
+
15
+SELECT * FROM MOVIES WHERE IMDB_SCORE >= 6.5;
16
+
17
+SELECT * FROM MOVIES WHERE
18
+RUNTIME < 100 AND RATING = 'G' OR RATING = 'PG';