1 package dst.ass1.jpa.model.impl;
3 import dst.ass1.jpa.model.*;
4 import dst.ass1.jpa.util.Constants;
6 import javax.persistence.*;
7 import java.math.BigDecimal;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Date;
13 @Table(name = Constants.T_COURSE)
14 @NamedQuery(name = Constants.Q_ONGOING_AND_FREE_PLATFORM_COURSES, query = "SELECT c" +
15 " FROM " + Constants.T_COURSE + " c" +
16 " JOIN c.coursePlatform cp " +
17 " WHERE cp." + Constants.M_COURSEPLATFORM_NAME + " = :platformName " +
18 " AND c." + Constants.M_COURSE_STATUS + " = dst.ass1.jpa.model.CourseStatus.ONGOING" +
19 " AND c." + Constants.M_COURSE_CAPACITY + " > (SELECT count(*) FROM " + Constants.T_ENROLLMENT +
20 " WHERE c = " + Constants.I_COURSE + " group by " + Constants.I_COURSE + ")"
22 public class Course implements ICourse {
31 private Integer capacity;
34 private Boolean premium;
37 private BigDecimal cost;
40 private CourseStatus status;
48 // , optional = false?
49 @ManyToOne(targetEntity = CoursePlatform.class)
50 private ICoursePlatform coursePlatform;
52 // , optional = false?
53 @ManyToOne(targetEntity = Lecturer.class)
54 private ILecturer lecturer;
56 @OneToMany(targetEntity = Lesson.class)
57 private Collection<ILesson> lessons = new ArrayList<>();
59 @OneToOne(targetEntity = Metadata.class, optional = false, cascade = CascadeType.ALL)
60 private IMetadata metadata;
62 @OneToMany(targetEntity = Enrollment.class)
63 private Collection<IEnrollment> enrollments = new ArrayList<>();
72 public void setId(Long id) {
77 public String getName() {
82 public void setName(String name) {
87 public Integer getCapacity() {
92 public void setCapacity(Integer capacity) {
93 this.capacity = capacity;
97 public Boolean getPremium() {
102 public void setPremium(Boolean premium) {
103 this.premium = premium;
107 public BigDecimal getCost() {
112 public void setCost(BigDecimal cost) {
117 public CourseStatus getStatus() {
122 public void setStatus(CourseStatus status) {
123 this.status = status;
127 public Date getStart() {
132 public void setStart(Date start) {
137 public Date getEnd() {
142 public void setEnd(Date end) {
147 public ICoursePlatform getCoursePlatform() {
148 return coursePlatform;
152 public void setCoursePlatform(ICoursePlatform coursePlatform) {
153 this.coursePlatform = coursePlatform;
157 public ILecturer getLecturer() {
162 public void setLecturer(ILecturer lecturer) {
163 this.lecturer = lecturer;
167 public Collection<ILesson> getLessons() {
172 public void setLessons(Collection<ILesson> lessons) {
173 this.lessons = lessons;
177 public void addLesson(ILesson lesson) {
178 this.lessons.add(lesson);
182 public IMetadata getMetadata() {
187 public void setMetadata(IMetadata metadata) {
188 this.metadata = metadata;
192 public Collection<IEnrollment> getEnrollments() {
197 public void setEnrollments(Collection<IEnrollment> enrollments) {
198 this.enrollments = enrollments;
202 public void addEnrollment(IEnrollment enrollment) {
203 this.enrollments.add(enrollment);