Reader.java 5.58 KB
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fi.insomnia.bortal.model;

import static javax.persistence.CascadeType.DETACH;
import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST;
import static javax.persistence.CascadeType.REFRESH;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;

import fi.insomnia.bortal.model.salespoint.SalesEntity;

/**
 * 
 */
@Entity
@Table(name = "readers", uniqueConstraints = { @UniqueConstraint(columnNames = { "reader_ident", "event_id" }) })
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Reader extends GenericEntity {

    public Reader(LanEvent ev, String ident) {
        this(ev);
        this.identification = ident;
    }

    public Reader() {
        super();
    }

    public Reader(LanEvent ev) {
        super();
        this.setEvent(ev);
    }

    @Column(nullable = false, name = "type")
    @Enumerated(EnumType.STRING)
    private ReaderType type = ReaderType.RFID;

    public static final String EVENT_ID_COLUMN = "event_id";
    @ManyToOne()
    @JoinColumn(name = EVENT_ID_COLUMN, nullable = false)
    private LanEvent event;

    @Column(nullable = false)
    private Integer gamepoints = 0;
    @Column(nullable = false)
    private Integer maxEvents = 0;

    @OneToOne(mappedBy = "reader")
    private SalesEntity salesEntity;

    @ManyToOne
    @JoinColumn(name = "automatic_product_id")
    private Product automaticProduct;

    @Column(precision = 25, scale = 4, name = "automatic_product_count")
    private BigDecimal automaticProductCount;

    private static final long serialVersionUID = 616803985117256035L;

    @Column(name = "reader_ident")
    private String identification;

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

    @JoinColumn(name = "location_id", referencedColumnName = "id")
    @ManyToOne
    private Location location;

    @ManyToOne
    @JoinColumn(name = "map_id", referencedColumnName = "id")
    private EventMap eventMap;

    @Column(name = "map_x")
    private Integer mapX;
    @Column(name = "map_y")
    private Integer mapY;

    @OneToMany(mappedBy = "reader", cascade = { PERSIST, MERGE, REFRESH, DETACH })
    private List<ReaderEvent> events = new ArrayList<ReaderEvent>();

    public String getIdentification() {
        return identification;
    }

    public void setIdentification(String readerId) {
        this.identification = readerId;
    }

    public String getDescription() {
        return description;
    }

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

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location locationsId) {
        this.location = locationsId;
    }

    /**
     * @return the mapX
     */
    public Integer getMapX() {
        return mapX;
    }

    /**
     * @param mapX
     *            the mapX to set
     */
    public void setMapX(Integer mapX) {
        this.mapX = mapX;
    }

    /**
     * @return the mapY
     */
    public Integer getMapY() {
        return mapY;
    }

    /**
     * @param mapY
     *            the mapY to set
     */
    public void setMapY(Integer mapY) {
        this.mapY = mapY;
    }

    /**
     * @return the eventMap
     */
    public EventMap getEventMap() {
        return eventMap;
    }

    /**
     * @param eventMap
     *            the eventMap to set
     */
    public void setEventMap(EventMap eventMap) {
        this.eventMap = eventMap;
    }

    public void setGamepoints(Integer gamepoints) {
        this.gamepoints = gamepoints;
    }

    public Integer getGamepoints() {
        return gamepoints;
    }

    public void setMaxEvents(Integer maxEvents) {
        this.maxEvents = maxEvents;
    }

    public Integer getMaxEvents() {
        return maxEvents;
    }

    public void setEvents(List<ReaderEvent> events) {
        this.events = events;
    }

    public List<ReaderEvent> getEvents() {
        return events;
    }

    public LanEvent getEvent() {
        return event;
    }

    public void setEvent(LanEvent event) {
        this.event = event;
    }

    public SalesEntity getSalesEntity() {
        return salesEntity;
    }

    public void setSalesEntity(SalesEntity salesEntity) {
        this.salesEntity = salesEntity;
    }

    public boolean isAutoproduct() {
        return (automaticProduct != null && automaticProductCount != null);
    }

    public ReaderType getType() {
        return type;
    }

    public void setType(ReaderType type) {
        this.type = type;
    }

    public Product getAutomaticProduct() {
        return automaticProduct;
    }

    public void setAutomaticProduct(Product automaticProduct) {
        this.automaticProduct = automaticProduct;
    }

    public BigDecimal getAutomaticProductCount() {
        return automaticProductCount;
    }

    public void setAutomaticProductCount(BigDecimal automaticProductCount) {
        this.automaticProductCount = automaticProductCount;
    }

}