#9 Brandon Defrancis JPA

Avoinna
BDefrancis haluaa yhdistää 1 committia lähteestä BDefrancis/CR-MacroLab-Spring-MovieDatabase.SQL.JDBC.JPA:master kohteeseen master

+ 76
- 0
src/main/java/domain/Person.java Näytä tiedosto

@@ -0,0 +1,76 @@
1
+package domain;
2
+
3
+import javax.persistence.Column;
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+import javax.persistence.Id;
7
+
8
+@Entity
9
+public class Person {
10
+
11
+    @Id
12
+    @GeneratedValue
13
+    private Integer id;
14
+
15
+    @Column(name = "FIRST_NAME")
16
+    private String firstName;
17
+
18
+    @Column(name = "LAST_NAME")
19
+    private String lastName;
20
+
21
+    @Column(name = "BIRTHDAY")
22
+    private String birthDate;
23
+
24
+    @Column(name = "MOBILE_NUMBER")
25
+    private String mobileNumber;
26
+
27
+    public Person() {
28
+    }
29
+
30
+    public Person(String firstName, String lastName, String birthDate, String mobileNumber) {
31
+        this.firstName = firstName;
32
+        this.lastName = lastName;
33
+        this.birthDate = birthDate;
34
+        this.mobileNumber = mobileNumber;
35
+    }
36
+
37
+    public Integer getId() {
38
+        return id;
39
+    }
40
+
41
+    public void setId(Integer id) {
42
+        this.id = id;
43
+    }
44
+
45
+    public String getFirstName() {
46
+        return firstName;
47
+    }
48
+
49
+    public void setFirstName(String firstName) {
50
+        this.firstName = firstName;
51
+    }
52
+
53
+    public String getLastName() {
54
+        return lastName;
55
+    }
56
+
57
+    public void setLastName(String lastName) {
58
+        this.lastName = lastName;
59
+    }
60
+
61
+    public String getBirthDate() {
62
+        return birthDate;
63
+    }
64
+
65
+    public void setBirthDate(String birthDate) {
66
+        this.birthDate = birthDate;
67
+    }
68
+
69
+    public String getMobileNumber() {
70
+        return mobileNumber;
71
+    }
72
+
73
+    public void setMobileNumber(String mobileNumber) {
74
+        this.mobileNumber = mobileNumber;
75
+    }
76
+}

+ 12
- 0
src/main/java/io/zipcoder/persistenceapp/PersonService.java Näytä tiedosto

@@ -0,0 +1,12 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+import org.springframework.jdbc.core.JdbcTemplate;
4
+import org.springframework.stereotype.Service;
5
+
6
+@Service
7
+public class PersonService {
8
+
9
+    private JdbcTemplate jdbcTemplate;
10
+
11
+
12
+}

+ 9
- 0
src/main/java/repositories/PersonRepository.java Näytä tiedosto

@@ -0,0 +1,9 @@
1
+package repositories;
2
+
3
+import domain.Person;
4
+import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.stereotype.Repository;
6
+
7
+@Repository
8
+public interface PersonRepository extends CrudRepository<Person, Long> {
9
+}

+ 22
- 0
src/main/resources/script.sql Näytä tiedosto

@@ -0,0 +1,22 @@
1
+INSERT INTO MOVIES (ID, TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES (1, 'Howard the Duck', '110', 'Sci-Fi', '4.6', 'PG');
2
+INSERT INTO MOVIES (ID, TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES (2, 'Lavalantula', '83', 'Horror', '4.7', 'TV-14');
3
+INSERT INTO MOVIES (ID, TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES (3, 'Starship Troopers', '129', 'Sci-Fi', '7.2', 'PG-13');
4
+INSERT INTO MOVIES (ID, TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES (4, 'Waltz With Bashir', '90', 'Documentary', '8.0', 'R');
5
+INSERT INTO MOVIES (ID, TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES (5, 'Spaceballs', '96', 'Comedy', '7.1', 'PG');
6
+INSERT INTO MOVIES (ID, TITLE, RUNTIME, GENRE, IMDB_SCORE, RATING) VALUES (6, 'Monsters Inc.', '92', 'Animation', '8.1', 'G');
7
+
8
+SELECT * FROM MOVIES WHERE GENRE = 'Sci-Fi';
9
+
10
+SELECT * FROM MOVIES WHERE IMDB_SCORE > 6.5;
11
+
12
+SELECT * FROM MOVIES WHERE RATING = 'G' OR RATING = 'PG' AND RUNTIME < 100;
13
+
14
+SELECT AVG(RUNTIME) FROM MOVIES WHERE IMDB_SCORE < 7.5 GROUP BY GENRE;
15
+
16
+UPDATE MOVIES SET RATING = 'R' WHERE TITLE = 'Starship Troopers';
17
+
18
+SELECT ID, RATING FROM MOVIES WHERE GENRE = 'Horror' OR GENRE = 'Documentary';
19
+
20
+SELECT AVG(IMDB_SCORE), MAX(IMDB_SCORE), MIN(IMDB_SCORE) FROM MOVIES HAVING COUNT(*) > 1;
21
+
22
+DELETE FROM MOVIES WHERE RATING = 'R';