Skip to content

Commit cb39550

Browse files
author
Ferenc Hammerl
committed
Add poll and participant DAL classes
Beware the two-way mapping between the two. I had to use @JsonIgnore to avoid the JS infinite loop.
1 parent cf39aff commit cb39550

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.fhammerl.polls.models;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.FetchType;
5+
import javax.persistence.Id;
6+
import javax.persistence.JoinColumn;
7+
import javax.persistence.ManyToOne;
8+
9+
import com.fasterxml.jackson.annotation.JsonIgnore;
10+
11+
@Entity(name = "participant")
12+
public class Participant {
13+
@Id
14+
private Integer id;
15+
private String name;
16+
private String email;
17+
18+
@ManyToOne(fetch = FetchType.LAZY)
19+
@JoinColumn(name = "poll_id")
20+
private Poll poll;
21+
22+
public Integer getId() {
23+
return this.id;
24+
}
25+
26+
public void setId(Integer id) {
27+
this.id = id;
28+
}
29+
30+
public String getName() {
31+
return this.name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
public String getEmail() {
39+
return this.email;
40+
}
41+
42+
public void setEmail(String email) {
43+
this.email = email;
44+
}
45+
46+
@JsonIgnore
47+
public Poll getPoll() {
48+
return this.poll;
49+
}
50+
51+
public void setPoll(Poll poll) {
52+
this.poll = poll;
53+
}
54+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.fhammerl.polls.models;
2+
3+
import java.util.Date;
4+
import java.util.List;
5+
6+
import javax.persistence.CascadeType;
7+
import javax.persistence.Column;
8+
import javax.persistence.Entity;
9+
import javax.persistence.FetchType;
10+
import javax.persistence.Id;
11+
import javax.persistence.OneToMany;
12+
13+
@Entity(name = "poll")
14+
public class Poll {
15+
@Id
16+
@Column(name = "id")
17+
private String id;
18+
@Column(name = "latest_change")
19+
private Date latestChange;
20+
private Date initiated;
21+
private boolean hidden;
22+
private String preferencesType;
23+
private String state;
24+
private String title;
25+
26+
@OneToMany(mappedBy = "poll", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
27+
private List<Participant> participants;
28+
29+
public String getId() {
30+
return this.id;
31+
}
32+
33+
public void setId(String id) {
34+
this.id = id;
35+
}
36+
37+
public Date getLatestChange() {
38+
return this.latestChange;
39+
}
40+
41+
public void setLatestChange(Date latestChange) {
42+
this.latestChange = latestChange;
43+
}
44+
45+
public Date getInitiated() {
46+
return this.initiated;
47+
}
48+
49+
public void setInitiated(Date initiated) {
50+
this.initiated = initiated;
51+
}
52+
53+
public boolean getHidden() {
54+
return this.hidden;
55+
}
56+
57+
public void setHidden(boolean hidden) {
58+
this.hidden = hidden;
59+
}
60+
61+
public String getPreferencesType() {
62+
return this.preferencesType;
63+
}
64+
65+
public void setPreferencesType(String preferencesType) {
66+
this.preferencesType = preferencesType;
67+
}
68+
69+
public String getState() {
70+
return this.state;
71+
}
72+
73+
public void setState(String state) {
74+
this.state = state;
75+
}
76+
77+
public String getTitle() {
78+
return this.title;
79+
}
80+
81+
public void setTitle(String title) {
82+
this.title = title;
83+
}
84+
85+
public List<Participant> getParticipants() {
86+
return this.participants;
87+
}
88+
89+
public void setParticipants(List<Participant> participant) {
90+
this.participants = participant;
91+
}
92+
93+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.fhammerl.polls.repositories;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import com.fhammerl.polls.models.Poll;
5+
6+
public interface PollRepository extends JpaRepository<Poll, Long> {
7+
}

0 commit comments

Comments
 (0)