package xyz.acmer.entity.user;

import javax.persistence.*;

/**
 * 用户OJ账号信息表
 * Created by hypo on 16-2-11.
 */
@Entity(name = "user_account")
public class UserAccount {

    private Integer accountId;
    private User user;

    /**
     * OJ代号
     */
    private String ojCode;

    /**
     * OJ登陆信息
     * VJ使用用户自己的账户提交程序
     */
    private String loginName;
    private String password;

    /**
     * 该OJ下的AC数目
     */
    private Integer accepted;

    /**
     * 该OJ下的提交数目
     */
    private Integer submit;

    public UserAccount(User user, String ojCode, String loginName,
                       String password,Integer accepted, Integer submit) {
        this.user = user;
        this.ojCode = ojCode;
        this.loginName = loginName;
        this.password = password;
        this.accepted = accepted;
        this.submit = submit;
    }

    @Id
    @GeneratedValue
    public Integer getAccountId() {
        return accountId;
    }

    @ManyToOne(optional = false)
    @JoinColumn(name = "user")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = "oj_code", nullable = false, length = 10)
    public String getOjCode() {
        return ojCode;
    }

    public void setOjCode(String ojCode) {
        this.ojCode = ojCode;
    }

    @Column(name = "login_name", nullable = false, unique = true, length = 20)
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    @Column(name = "password", nullable = false, length = 50)
    public String getPassword() {
        return password;
    }

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

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

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

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

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

@@ -515,16 +515,50 @@
 ubmit;%0A%0A
+    public UserAccount() %7B%0A    %7D%0A%0A
     publ
@@ -1000,16 +1000,68 @@
 nyToOne(
+cascade = %7BCascadeType.MERGE,CascadeType.REFRESH %7D, 
 optional
@@ -1063,20 +1063,19 @@
 ional = 
-fals
+tru
 e)%0A    @
@@ -1097,16 +1097,19 @@
  = %22user
+_id
 %22)%0A    p
@@ -2281,11 +2281,474 @@
 t;%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        UserAccount that = (UserAccount) o;%0A%0A        if (!user.equals(that.user)) return false;%0A        return ojCode.equals(that.ojCode);%0A%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = user.hashCode();%0A        result = 31 * result + ojCode.hashCode();%0A        return result;%0A    %7D
 %0A%7D%0A

update user account