Vote.java 3.04 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fi.codecrew.moya.model;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

/**
 * A vote for a compo entry
 */
@Entity
@Table(name = "compo_votes", uniqueConstraints = { @UniqueConstraint(columnNames = { Vote.ENTRY_ID, Vote.VOTER_USER_ID }) })
public class Vote extends GenericEntity {

    protected static final String VOTER_USER_ID = "voter_userevent_id";
    protected static final String ENTRY_ID = "entry_id";

    private static final long serialVersionUID = 2L;

    @Column(name = "score")
    private Integer score;

    @Lob
    private String message;

    @Column(name = "vote_time", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar time;

    @JoinColumn(name = ENTRY_ID, referencedColumnName = CompoEntry.ID_COLUMN, nullable = false)
    @ManyToOne(optional = false)
    private CompoEntry compoEntry;

    @JoinColumn(name = VOTER_USER_ID, referencedColumnName = EventUser.ID_COLUMN, nullable = false)
    @ManyToOne(optional = false)
    private EventUser voter;

    public Vote(LanEvent event, Calendar voteTime) {
        super();
        this.time = voteTime;
    }

    public Vote() {
        super();
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Calendar getTime() {
        return time;
    }

    public void setTime(Calendar voteTime) {
        this.time = voteTime;
    }

    /**
     * @return the compoEntry
     */
    public CompoEntry getCompoEntry() {
        return compoEntry;
    }

    /**
     * @param compoEntry
     *            the compoEntry to set
     */
    public void setCompoEntry(CompoEntry compoEntry) {
        this.compoEntry = compoEntry;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public EventUser getVoter() {
        return voter;
    }

    public void setVoter(EventUser voter) {
        this.voter = voter;
    }

}