package com.plannaplan.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; /** * Entity that keeps user exchange offer. */ @Entity public class Exchange { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToOne @JoinColumn(name = "owned_id", unique = true) private Assignment ownedAssignment; @OneToOne @JoinColumn(name = "desired_id") private Groups desiredAssignment; private Long ownerId; public Exchange(){ } /** * @return Long ID of exchange trader */ public Long getOwnerId() { return ownerId; } /** * @param ownerId ID of exchange trader */ public void setOwnerId(Long ownerId) { this.ownerId = ownerId; } /** * * @param ownedAssignment Assignment which owner would like to trade * @param desiredAssignment Groups instance that trader wants */ public Exchange(Assignment ownedAssignment, Groups desiredAssignment) { this.ownedAssignment = ownedAssignment; this.desiredAssignment = desiredAssignment; this.ownerId = this.ownedAssignment.getCommision().getCommisionOwner().getId(); } /** * @return Long ID in database */ public Long getId(){ return this.id; } /** * @return Groups Target group */ public Groups getDesiredAssignment() { return desiredAssignment; } /** * @param desiredAssignment Target group */ public void setDesiredAssignment(Groups desiredAssignment) { this.desiredAssignment = desiredAssignment; } /** * @return Assignment Owned assignment */ public Assignment getOwnedAssignment() { return ownedAssignment; } /** * @param ownedAssignment Owned assignment */ public void setOwnedAssignment(Assignment ownedAssignment) { this.ownedAssignment = ownedAssignment; } }