package xyz.acmer.entity.contest;

import xyz.acmer.entity.problem.Problem;

import javax.persistence.*;

/**
 * 比赛题目表
 * Created by hypo on 16-2-11.
 */
@Entity
public class ContestProblem {

    private Long problemId;
    private Problem problem;
    private ContestInfo contest;

    /**
     * 在比赛中题目使用自定义标题
     */
    private String title;

    /**
     * 本场比赛中AC数目
     */
    private Integer accepted;

    /**
     * 本场比赛中的提交数目
     */
    private Integer submit;

    public ContestProblem(Problem problem, ContestInfo contestId, String title) {
        this.problem = problem;
        this.contest = contestId;
        this.title = title;
        this.accepted = 0;
        this.submit = 0;
    }

    @Id
    @GeneratedValue
    public Long getProblemId() {
        return problemId;
    }

    @ManyToOne
    @JoinColumn(name = "problem")
    public Problem getProblem() {
        return problem;
    }

    public void setProblem(Problem problem) {
        this.problem = problem;
    }

    @ManyToOne
    @JoinColumn(name = "contest")
    public ContestInfo getContest() {
        return contest;
    }

    public void setContest(ContestInfo contest) {
        this.contest = contest;
    }

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

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

    @Column(name = "accepted")
    public Integer getAccepted() {
        return accepted;
    }

    public void setAccepted(Integer accepted) {
        this.accepted = accepted;
    }

    @Column(name = "submit")
    public Integer getSubmit() {
        return submit;
    }

    public void setSubmit(Integer submit) {
        this.submit = submit;
    }
}

@@ -530,18 +530,16 @@
  contest
-Id
 , String
@@ -540,32 +540,32 @@
 String title) %7B%0A
+
         this.pro
@@ -610,18 +610,16 @@
  contest
-Id
 ;%0A      
@@ -794,33 +794,101 @@
     %7D%0A%0A    @
-ManyToOne
+OneToOne(cascade = %7BCascadeType.MERGE,CascadeType.REFRESH %7D, optional = true)
 %0A    @JoinCo
@@ -907,16 +907,19 @@
 %22problem
+_id
 %22)%0A    p
@@ -1077,16 +1077,85 @@
 anyToOne
+(cascade = %7BCascadeType.MERGE,CascadeType.REFRESH %7D, optional = true)
 %0A    @Jo
@@ -1178,16 +1178,19 @@
 %22contest
+_id
 %22)%0A    p

update contestproblem