package cz.cvut.fel.restauracefel.hibernate;
// Generated 16.3.2009 21:36:54 by Hibernate Tools 3.2.1.GA
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;
/**
* Expenditure generated by hbm2java
*/
public class Expenditure implements Serializable {
private static final long serialVersionUID = 4753600958074874267L;
private Integer expenditureId;
private Date date;
private Material material;
private double quantity;
private User user;
private String note;
private int isDeleted;
public Expenditure() {
}
public Expenditure(Date date, Material material, double quantity, User user, int isDeleted) {
this.date = date;
this.material = material;
this.quantity = quantity;
this.user = user;
this.isDeleted = isDeleted;
}
public Expenditure(Date date, Material material, double quantity, User user, String note, int isDeleted) {
this.date = date;
this.material = material;
this.quantity = quantity;
this.user = user;
this.note = note;
this.isDeleted = isDeleted;
}
//tato metoda zde musi byt, a to z duvodu, aby mohla probehnout spravne serializace
//zapis objektu do proudu bajtu
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.writeInt(expenditureId);
stream.writeObject(date);
Material m = new Material();
UnitType ut = new UnitType(material.getUnitType().getName(), material.getUnitType().getAbbreviation(), material.getUnitType().getTypeId(), material.getUnitType().getIsDeleted());
ut.setUnitTypeId(material.getUnitType().getUnitTypeId());
MaterialType mt = new MaterialType(material.getMaterialType().getName(), material.getMaterialType().getNote(), material.getMaterialType().getIsDeleted());
mt.setMaterialTypeId(material.getMaterialType().getMaterialTypeId());
m.setMaterialId(material.getMaterialId());
m.setUnitType(ut);
m.setMaterialType(mt);
m.setName(material.getName());
m.setCurrentQuantity(material.getCurrentQuantity());
m.setBarcode(material.getBarcode());
m.setMinimal(material.getMinimal());
m.setIsDeleted(material.getIsDeleted());
stream.writeObject(m);
stream.writeDouble(quantity);
User u = new User(user.getFirstName(), user.getLastName(), user.getPersonalIdentificationNumber(), user.getUsername(), user.getPassword(), user.getIsDeleted());
u.setUserId(user.getUserId());
stream.writeObject(u);
stream.writeObject(note);
stream.writeInt(isDeleted);
}
//tato metoda zde musi byt, a to z duvodu, aby mohla probehnout spravne serializace
//cteni a rekonstrukce objektu z proudu bajtu
private void readObject(ObjectInputStream stream) throws IOException {
try {
expenditureId = stream.readInt();
date = (Date) (stream.readObject());
material = (Material) (stream.readObject());
quantity = stream.readDouble();
user = (User) (stream.readObject());
note = (String) (stream.readObject());
isDeleted = stream.readInt();
} catch (Exception e) {
}
}
public Integer getExpenditureId() {
return this.expenditureId;
}
public void setExpenditureId(Integer expenditureId) {
this.expenditureId = expenditureId;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public Material getMaterial() {
return this.material;
}
public void setMaterial(Material material) {
this.material = material;
}
public double getQuantity() {
return this.quantity;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
public Date getDate() {
return this.date;
}
public void setDate(Date date) {
this.date = date;
}
public String getNote() {
return this.note;
}
public void setNote(String note) {
this.note = note;
}
public int getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(int isDeleted) {
this.isDeleted = isDeleted;
}
}