Last active
February 16, 2018 00:34
-
-
Save ajfmo/0ca285e1e755f3178c1d32b4600d56fe to your computer and use it in GitHub Desktop.
Entity with annotations and JavaFX Properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ajfmo.inventario.entities; | |
import javax.persistence.CascadeType; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.FetchType; | |
import javax.persistence.Id; | |
import javax.persistence.JoinColumn; | |
import javax.persistence.ManyToOne; | |
import javax.persistence.Table; | |
import javax.persistence.UniqueConstraint; | |
import javafx.beans.property.DoubleProperty; | |
import javafx.beans.property.ObjectProperty; | |
import javafx.beans.property.SimpleDoubleProperty; | |
import javafx.beans.property.SimpleObjectProperty; | |
import javafx.beans.property.SimpleStringProperty; | |
import javafx.beans.property.StringProperty; | |
@Entity | |
@Table(name = "productos", catalog = "inventario", uniqueConstraints = @UniqueConstraint(columnNames = "descripcion_producto")) | |
public class Productos implements java.io.Serializable { | |
private static final long serialVersionUID = -1590791253567033829L; | |
public Productos() { | |
} | |
public Productos(String idProductos, String descripcionProducto, Double costoProducto, Double utilidadProducto, | |
Double precioProducto, Double existenciaProducto, ObjectProperty<Deposito> depositoProducto) { | |
this.idProductos = new SimpleStringProperty(idProductos); | |
this.descripcionProducto = new SimpleStringProperty(descripcionProducto); | |
this.costoProducto = new SimpleDoubleProperty(costoProducto); | |
this.utilidadProducto = new SimpleDoubleProperty(utilidadProducto); | |
this.precioProducto = new SimpleDoubleProperty(precioProducto); | |
// Magia | |
this.precioProducto | |
.bind(this.costoProducto.multiply(this.costoProducto.subtract(this.utilidadProducto).divide(100))); | |
this.existenciaProducto = new SimpleDoubleProperty(existenciaProducto); | |
this.deposito = depositoProducto; | |
} | |
private StringProperty idProductos; | |
private String _idProductos; | |
@Id | |
@Column(name = "idProductos", unique = true, nullable = false) | |
public String getIdProductos() { | |
if (idProductos == null) { | |
return _idProductos; | |
} else { | |
return idProductos.get(); | |
} | |
} | |
public void setIdProductos(String idProductos) { | |
if (this.idProductos == null) { | |
_idProductos = idProductos; | |
} else { | |
this.idProductos.set(idProductos); | |
} | |
} | |
public StringProperty IdProductosProperty() { | |
if (idProductos == null) { | |
idProductos = new SimpleStringProperty(this, "idProductos", _idProductos); | |
} | |
return idProductos; | |
} | |
private StringProperty descripcionProducto; | |
private String _descripcionProducto; | |
@Column(name = "descripcion_producto", unique = true, nullable = false, length = 45) | |
public String getDescripcionProducto() { | |
if (descripcionProducto == null) { | |
return _descripcionProducto; | |
} else { | |
return descripcionProducto.get(); | |
} | |
} | |
public void setDescripcionProducto(String descripcionProducto) { | |
if (this.descripcionProducto == null) { | |
_descripcionProducto = descripcionProducto; | |
} else { | |
this.descripcionProducto.set(descripcionProducto); | |
} | |
} | |
public StringProperty DescripcionProductoProperty() { | |
if (descripcionProducto == null) { | |
descripcionProducto = new SimpleStringProperty(this, "descripcionProducto", _descripcionProducto); | |
} | |
return descripcionProducto; | |
} | |
private DoubleProperty costoProducto; | |
private double _costoProducto; | |
@Column(name = "costo_producto", precision = 22, scale = 0) | |
public Double getCostoProducto() { | |
if (costoProducto == null) { | |
return _costoProducto; | |
} else { | |
return costoProducto.get(); | |
} | |
} | |
public void setCostoProducto(Double costoProducto) { | |
if (this.costoProducto == null) { | |
_costoProducto = costoProducto; | |
} else { | |
this.costoProducto.set(costoProducto); | |
} | |
} | |
public DoubleProperty CostoProductoProperty() { | |
if (costoProducto == null) { | |
costoProducto = new SimpleDoubleProperty(this, "costoProducto", _costoProducto); | |
} | |
return costoProducto; | |
} | |
private DoubleProperty utilidadProducto; | |
private double _utilidadProducto; | |
@Column(name = "utilidad_producto", precision = 22, scale = 0) | |
public Double getUtilidadProducto() { | |
if (utilidadProducto == null) { | |
return _utilidadProducto; | |
} else { | |
return utilidadProducto.get(); | |
} | |
} | |
public void setUtilidadProducto(Double utilidadProducto) { | |
if (this.utilidadProducto == null) { | |
_utilidadProducto = utilidadProducto; | |
} else { | |
this.utilidadProducto.set(utilidadProducto); | |
} | |
} | |
public DoubleProperty UtilidadProductoProperty() { | |
if (utilidadProducto == null) { | |
utilidadProducto = new SimpleDoubleProperty(this, "utilidadProducto", _utilidadProducto); | |
} | |
return utilidadProducto; | |
} | |
private DoubleProperty precioProducto; | |
private double _precioProducto; | |
@Column(name = "precio_producto", precision = 22, scale = 0) | |
public Double getPrecioProducto() { | |
if (precioProducto == null) { | |
return _utilidadProducto; | |
} else { | |
return precioProducto.get(); | |
} | |
} | |
public void setPrecioProducto(Double precioProducto) { | |
if (this.precioProducto == null) { | |
_precioProducto = precioProducto; | |
} else { | |
this.precioProducto.set(precioProducto); | |
} | |
} | |
public DoubleProperty PrecioProductoProperty() { | |
if (precioProducto == null) { | |
precioProducto = new SimpleDoubleProperty(this, "precioProducto", _precioProducto); | |
} | |
return precioProducto; | |
} | |
private DoubleProperty existenciaProducto; | |
private double _existenciaProducto; | |
@Column(name = "existencia_producto", precision = 22, scale = 0) | |
public Double getExistenciaProducto() { | |
if (existenciaProducto == null) { | |
return _existenciaProducto; | |
} else { | |
return existenciaProducto.get(); | |
} | |
} | |
public void setExistenciaProducto(Double existenciaProducto) { | |
if (this.existenciaProducto == null) { | |
_existenciaProducto = existenciaProducto; | |
} else { | |
this.existenciaProducto.set(existenciaProducto); | |
} | |
} | |
public DoubleProperty ExistenciaProductoProperty() { | |
if (existenciaProducto == null) { | |
existenciaProducto = new SimpleDoubleProperty(this, "existenciaProducto", _existenciaProducto); | |
} | |
return existenciaProducto; | |
} | |
private ObjectProperty<Deposito> deposito; | |
private Deposito _deposito; | |
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) | |
@JoinColumn(name = "deposito_producto", referencedColumnName = "descripcion_deposito", nullable = false) | |
public Deposito getDeposito() { | |
if (deposito == null) { | |
return _deposito; | |
} else { | |
return deposito.get(); | |
} | |
} | |
public void setDeposito(Deposito deposito) { | |
if (this.deposito == null) { | |
_deposito = deposito; | |
} else { | |
this.deposito.set(deposito); | |
} | |
} | |
public ObjectProperty<Deposito> depositoProperty() { | |
if (deposito == null) { | |
deposito = new SimpleObjectProperty<>(this, "deposito", _deposito); | |
} | |
return deposito; | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see java.lang.Object#toString() | |
*/ | |
@Override | |
public String toString() { | |
return "Productos [idProductos=" + idProductos + ", descripcionProducto=" + descripcionProducto | |
+ ", costoProducto=" + costoProducto + ", precioProducto=" + precioProducto + ", existenciaProducto=" | |
+ existenciaProducto + ", deposito=" + deposito + "]"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment