package xyz.acmer.entity.contest;

import xyz.acmer.entity.user.User;

import javax.persistence.*;
import java.util.Date;

/**
 * 比赛信息表
 * Created by hypo on 16-2-11.
 */
@Entity
public class ContestInfo {

    private Integer contestId;
    private User creater;
    private String title;

    /**
     * 比赛开始时间
     * 比赛长度
     * 比赛密码（如果公开则留空）
     */
    private Date beginTime;
    private Integer length;
    private String password;

    /**
     * 比赛描述
     */
    private String description;

    /**
     * 比赛类型
     * 根据比赛类型的不同划分奖励规则
     */
    private ContestType contestType;

    public ContestInfo(User creater, String title, Date beginTime, Integer length,
                       String password, String description, ContestType contestType) {
        this.creater = creater;
        this.title = title;
        this.beginTime = beginTime;
        this.length = length;
        this.password = password;
        this.description = description;
        this.contestType = contestType;
    }

    @Id
    @GeneratedValue
    public Integer getContestId() {
        return contestId;
    }

    @ManyToOne
    @JoinColumn(name = "creater")
    public User getCreaterId() {
        return creater;
    }

    public void setCreaterId(User creater) {
        this.creater = creater;
    }

    @Column(name = "title", nullable = false, length = 100)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "begin_time", nullable = false, columnDefinition = "TIMESTAMP")
    public Date getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(Date beginTime) {
        this.beginTime = beginTime;
    }

    @Column(name = "length", nullable = false)
    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = "description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @ManyToOne
    @JoinColumn(name = "contest_type")
    public ContestType getContestType() {
        return contestType;
    }

    public void setContestType(ContestType contestType) {
        this.contestType = contestType;
    }

}

@@ -114,16 +114,64 @@
 il.Date;
+%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -219,16 +219,34 @@
 %0A@Entity
+(name = %22contest%22)
 %0Apublic 
@@ -645,24 +645,246 @@
 ntestType;%0A%0A
+    /***%0A     * %E6%AF%94%E8%B5%9B%E9%A2%98%E7%9B%AE%0A     */%0A    private Set%3CContestProblem%3E problems = new HashSet%3CContestProblem%3E();%0A%0A    /**%0A     * %E6%AF%94%E8%B5%9B%E9%80%9A%E7%9F%A5%0A     */%0A    private Set%3CContestAnnouncement%3E announcements = new HashSet%3CContestAnnouncement%3E();%0A%0A
     public C
@@ -1316,16 +1316,49 @@
 edValue%0A
+    @Column(name = %22contest_id%22)%0A
     publ
@@ -1424,32 +1424,56 @@
 %0A%0A    @ManyToOne
+(fetch = FetchType.LAZY)
 %0A    @JoinColumn
@@ -1481,23 +1481,23 @@
 name = %22
-creater
+user_id
 %22)%0A    p
@@ -1517,18 +1517,16 @@
 tCreater
-Id
 () %7B%0A   
@@ -1579,18 +1579,16 @@
 tCreater
-Id
 (User cr
@@ -2666,16 +2666,41 @@
 anyToOne
+(fetch = FetchType.EAGER)
 %0A    @Jo
@@ -2913,10 +2913,537 @@
 %0A    %7D%0A%0A
+    @OneToMany(cascade = CascadeType.ALL, mappedBy = %22contest%22)%0A    public Set%3CContestProblem%3E getProblems() %7B%0A        return problems;%0A    %7D%0A%0A    public void setProblems(Set%3CContestProblem%3E problems) %7B%0A        this.problems = problems;%0A    %7D%0A%0A    @OneToMany(cascade = CascadeType.ALL, mappedBy = %22contest%22)%0A    public Set%3CContestAnnouncement%3E getAnnouncements() %7B%0A        return announcements;%0A    %7D%0A%0A    public void setAnnouncements(Set%3CContestAnnouncement%3E announcements) %7B%0A        this.announcements = announcements;%0A    %7D%0A
 %7D%0A

update contestinfo