Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.entity.fofo;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

@Entity
@Table(name = "fofo.rating_reminder",
        uniqueConstraints = @UniqueConstraint(name = "uk_rating_reminder_fofo_week",
                columnNames = {"fofo_id", "week_start"}))
@NamedQueries({
        @NamedQuery(
                name = "RatingReminder.findByFofoIdAndWeek",
                query = "SELECT r FROM RatingReminder r WHERE r.fofoId = :fofoId AND r.weekStart = :weekStart"
        ),
        @NamedQuery(
                name = "RatingReminder.decrementRemaining",
                query = "UPDATE RatingReminder r " +
                        "SET r.attemptsRemaining = r.attemptsRemaining - 1, r.updateTimestamp = :now " +
                        "WHERE r.id = :id AND r.attemptsRemaining > 0"
        )
})
public class RatingReminder {

    public static final int MAX_ATTEMPTS_PER_WEEK = 4;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, updatable = false)
    private int id;

    @Column(name = "fofo_id")
    private int fofoId;

    @Column(name = "week_start")
    private LocalDate weekStart;

    @Column(name = "week_end")
    private LocalDate weekEnd;

    @Column(name = "attempts_remaining")
    private int attemptsRemaining;

    @Column(name = "create_timestamp")
    private LocalDateTime createTimestamp;

    @Column(name = "update_timestamp")
    private LocalDateTime updateTimestamp;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getFofoId() {
        return fofoId;
    }

    public void setFofoId(int fofoId) {
        this.fofoId = fofoId;
    }

    public LocalDate getWeekStart() {
        return weekStart;
    }

    public void setWeekStart(LocalDate weekStart) {
        this.weekStart = weekStart;
    }

    public LocalDate getWeekEnd() {
        return weekEnd;
    }

    public void setWeekEnd(LocalDate weekEnd) {
        this.weekEnd = weekEnd;
    }

    public int getAttemptsRemaining() {
        return attemptsRemaining;
    }

    public void setAttemptsRemaining(int attemptsRemaining) {
        this.attemptsRemaining = attemptsRemaining;
    }

    public LocalDateTime getCreateTimestamp() {
        return createTimestamp;
    }

    public void setCreateTimestamp(LocalDateTime createTimestamp) {
        this.createTimestamp = createTimestamp;
    }

    public LocalDateTime getUpdateTimestamp() {
        return updateTimestamp;
    }

    public void setUpdateTimestamp(LocalDateTime updateTimestamp) {
        this.updateTimestamp = updateTimestamp;
    }

    @Override
    public String toString() {
        return "RatingReminder{" +
                "id=" + id +
                ", fofoId=" + fofoId +
                ", weekStart=" + weekStart +
                ", weekEnd=" + weekEnd +
                ", attemptsRemaining=" + attemptsRemaining +
                ", createTimestamp=" + createTimestamp +
                ", updateTimestamp=" + updateTimestamp +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RatingReminder that = (RatingReminder) o;
        return id == that.id && fofoId == that.fofoId && attemptsRemaining == that.attemptsRemaining
                && Objects.equals(weekStart, that.weekStart) && Objects.equals(weekEnd, that.weekEnd)
                && Objects.equals(createTimestamp, that.createTimestamp) && Objects.equals(updateTimestamp, that.updateTimestamp);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, fofoId, weekStart, weekEnd, attemptsRemaining, createTimestamp, updateTimestamp);
    }
}