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.util.Date; import java.util.List; /** * Income generated by hbm2java */ public class Income extends DBEntity { private static final long serialVersionUID = 5248853997173009439L; private Integer incomeId; private Date date; private Material material; private double quantity; private double price; private User user; private String note; private int isDeleted; public Income() { } public Income(Date date, Material material, double quantity, double price, User user, int isDeleted) { this.date = date; this.material = material; this.quantity = quantity; this.price = price; this.user = user; this.isDeleted = isDeleted; } public Income(Date date, Material material, double quantity, double price, User user, String note, int isDeleted) { this.date = date; this.material = material; this.quantity = quantity; this.price = price; 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.defaultWriteObject(); stream.writeInt(incomeId); 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); stream.writeDouble(price); //Proc nejde "stream.writeObject(user)" ? 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 { //stream.defaultReadObject(); incomeId = stream.readInt(); date = (Date) (stream.readObject()); material = (Material) (stream.readObject()); quantity = stream.readDouble(); price = stream.readDouble(); user = (User) (stream.readObject()); note = (String) (stream.readObject()); isDeleted = stream.readInt(); } catch (Exception e) { } } public Integer getIncomeId() { return this.incomeId; } public void setIncomeId(Integer incomeId) { this.incomeId = incomeId; } 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 double getPrice() { return this.price; } public void setPrice(double price) { this.price = price; } 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; } public void create() { create(this); } public void update() { update(this); } public void delete() { delete(this); } public static Income findById(Integer id) { //return (Income) findById("Income", "incomeId", id); return (Income) findByIdNotDeleted("Income", "incomeId", id, "isDeleted", 0); } //vrati vsechny prijmy na sklad, ktere nejsou oznaceny jako smazane public static List findAll(){ return findAllNotDeleted("Income", "isDeleted", 0); } public static List findByMaterial(Integer materialId){ String query = "from Income inc where inc.material.materialId = :id1 and inc.isDeleted = :id2"; String[] paramNames = new String[] {"id1", "id2"}; String[] paramTypes = new String[] {"Integer", "Integer"}; Integer[] paramValues = new Integer[] {materialId, 0}; List res = executeQuery(query, paramNames, paramTypes, paramValues); if (res == null || res.isEmpty()) return null; return res; } public static List findByUser(Integer userId){ String query = "from Income inc where inc.user.userId = :id1 and inc.isDeleted = :id2"; String[] paramNames = new String[] {"id1", "id2"}; String[] paramTypes = new String[] {"Integer", "Integer"}; Integer[] paramValues = new Integer[] {userId, 0}; List res = executeQuery(query, paramNames, paramTypes, paramValues); if (res == null || res.isEmpty()) return null; return res; } }