/*
* Copyright 2011, MyCellar
*
* This file is part of MyCellar.
*
* MyCellar is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* MyCellar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MyCellar. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.mycellar.domain.stock;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.Valid;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import fr.mycellar.domain.shared.IdentifiedEntity;
/**
* @author speralta
*/
@Entity
@Table(name = "MOVEMENT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "WAY", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("N")
@SequenceGenerator(name = "MOVEMENT_ID_GENERATOR", allocationSize = 1)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({ @JsonSubTypes.Type(value = Input.class, name = "I"), @JsonSubTypes.Type(value = Output.class, name = "O") })
public abstract class Movement extends IdentifiedEntity {
private static final long serialVersionUID = 201111181451L;
@Embedded
@Valid
private Bottle bottle;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "CELLAR", nullable = false)
private Cellar cellar;
@Id
@GeneratedValue(generator = "MOVEMENT_ID_GENERATOR")
@Column(name = "ID", nullable = false)
private Integer id;
@Column(name = "NUMBER")
private int number;
@Column(name = "DATE")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate date;
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public Bottle getBottle() {
return bottle;
}
public void setBottle(Bottle bottle) {
this.bottle = bottle;
}
public Cellar getCellar() {
return cellar;
}
public void setCellar(Cellar cellar) {
this.cellar = cellar;
}
@Override
public Integer getId() {
return id;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return new ToStringBuilder(this).appendSuper(super.toString()).append("bottle", bottle).append("cellar", cellar).append("date", date).append("number", number).build();
}
}