Compo.java 6.79 KB
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fi.insomnia.bortal.model;

import java.util.Calendar;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

/**
 * Competition to be held at the event.
 */
@Entity
@Table(name = "compos")
@NamedQueries( {
        @NamedQuery(name = "Compo.findAll", query = "SELECT c FROM Compo c"),
        @NamedQuery(name = "Compo.findByName", query = "SELECT c FROM Compo c WHERE c.name = :name"),
        @NamedQuery(name = "Compo.findByStartTime", query = "SELECT c FROM Compo c WHERE c.startTime = :startTime"),
        @NamedQuery(name = "Compo.findByVoteStart", query = "SELECT c FROM Compo c WHERE c.voteStart = :voteStart"),
        @NamedQuery(name = "Compo.findByVoteEnd", query = "SELECT c FROM Compo c WHERE c.voteEnd = :voteEnd"),
        @NamedQuery(name = "Compo.findBySubmitStart", query = "SELECT c FROM Compo c WHERE c.submitStart = :submitStart"),
        @NamedQuery(name = "Compo.findBySubmitEnd", query = "SELECT c FROM Compo c WHERE c.submitEnd = :submitEnd"),
        @NamedQuery(name = "Compo.findByHoldVoting", query = "SELECT c FROM Compo c WHERE c.holdVoting = :holdVoting"),
        @NamedQuery(name = "Compo.findByDescription", query = "SELECT c FROM Compo c WHERE c.description = :description") })
public class Compo implements EventChildInterface {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    private EventPk id;

    /**
     * Name of the competition.
     */
    @Column(name = "compo_name", nullable = false)
    private String name;

    /**
     * Start time of the competition Submitting entries should be disabled after
     * this time.
     */
    @Column(name = "compo_start")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar startTime;

    /**
     * When the voting should start
     * 
     * @See {@link #holdVoting}
     */
    @Column(name = "vote_start")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar voteStart;

    @Column(name = "vote_end")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar voteEnd;

    @Column(name = "submit_start")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar submitStart;

    @Column(name = "submit_end")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar submitEnd;

    @Lob
    @Column(name = "description")
    private String description;

    @Column(name = "max_participant_count")
    private int maxParticipantCount;

    /**
     * If ( for some unimaginable reason ) compo is delayed hold voting can be
     * used to postpone the start of the voting from the time specified in
     * {@link #voteStart}
     */
    @Column(name = "hold_voting", nullable = false)
    private boolean holdVoting = true;

    /**
     * Entries submitted to participate this compo.
     */
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compo")
    private List<CompoEntry> compoEntries;

    @ManyToOne
    @JoinColumn(name = "event_id", referencedColumnName = "event_id", insertable = false, updatable = false)
    private LanEvent event;

    @Version
    @Column(nullable = false)
    private int jpaVersionField = 0;

    @Override
    public EventPk getId() {
        return id;
    }

    @Override
    public void setId(EventPk id) {
        this.id = id;
    }

    public Compo() {
    }

    public Compo(LanEvent event) {
        this.id = new EventPk(event);
    }

    public Compo(LanEvent event, String compoName, boolean holdVoting) {
        this.id = new EventPk(event);
        this.name = compoName;
        this.holdVoting = holdVoting;
    }

    public String getName() {
        return name;
    }

    public void setName(String compoName) {
        this.name = compoName;
    }

    public Calendar getStartTime() {
        return startTime;
    }

    public void setStartTime(Calendar compoStart) {
        this.startTime = compoStart;
    }

    public Calendar getVoteStart() {
        return voteStart;
    }

    public void setVoteStart(Calendar voteStart) {
        this.voteStart = voteStart;
    }

    public Calendar getVoteEnd() {
        return voteEnd;
    }

    public void setVoteEnd(Calendar voteEnd) {
        this.voteEnd = voteEnd;
    }

    public Calendar getSubmitStart() {
        return submitStart;
    }

    public void setSubmitStart(Calendar submitStart) {
        this.submitStart = submitStart;
    }

    public Calendar getSubmitEnd() {
        return submitEnd;
    }

    public void setSubmitEnd(Calendar submitEnd) {
        this.submitEnd = submitEnd;
    }

    public boolean getHoldVoting() {
        return holdVoting;
    }

    public void setHoldVoting(boolean holdVoting) {
        this.holdVoting = holdVoting;
    }

    public List<CompoEntry> getCompoEntries() {
        return compoEntries;
    }

    public void setCompoEntries(List<CompoEntry> compoEntryList) {
        this.compoEntries = compoEntryList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are
        // not set
        if (!(object instanceof Compo)) {
            return false;
        }
        Compo other = (Compo) object;
        if ((this.id == null && other.id != null)
                || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fi.insomnia.bortal.model.Compo[id=" + id + "]";
    }

    @Override
    public void setJpaVersionField(int jpaVersionField) {
        this.jpaVersionField = jpaVersionField;
    }

    @Override
    public int getJpaVersionField() {
        return jpaVersionField;
    }

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

    public String getDescription() {
        return description;
    }

    /**
     * @return the maxParticipantCount
     */
    public int getMaxParticipantCount() {
        return maxParticipantCount;
    }

    /**
     * @param maxParticipantCount
     *            the maxParticipantCount to set
     */
    public void setMaxParticipantCount(int maxParticipantCount) {
        this.maxParticipantCount = maxParticipantCount;
    }

    public LanEvent getEvent() {
        return event;
    }

}