From 2e39428a74fb75388b5df444533515fcd82d8761 Mon Sep 17 00:00:00 2001 From: vijaya27022001 Date: Fri, 1 Nov 2024 16:20:19 +0530 Subject: [PATCH] all the entities added --- pom.xml | 1 + .../wellsfargo/counselor/entity/Advisor.java | 65 ++++++---- .../wellsfargo/counselor/entity/Client.java | 112 ++++++++++++++++++ .../counselor/entity/Protfolio.java | 64 ++++++++++ .../wellsfargo/counselor/entity/Security.java | 94 +++++++++++++++ 5 files changed, 313 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/wellsfargo/counselor/entity/Client.java create mode 100644 src/main/java/com/wellsfargo/counselor/entity/Protfolio.java create mode 100644 src/main/java/com/wellsfargo/counselor/entity/Security.java diff --git a/pom.xml b/pom.xml index d36f4967..09c1883b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ org.springframework.boot spring-boot-starter-web + com.h2database h2 diff --git a/src/main/java/com/wellsfargo/counselor/entity/Advisor.java b/src/main/java/com/wellsfargo/counselor/entity/Advisor.java index 1a6861ec..0e170e3d 100644 --- a/src/main/java/com/wellsfargo/counselor/entity/Advisor.java +++ b/src/main/java/com/wellsfargo/counselor/entity/Advisor.java @@ -1,16 +1,16 @@ package com.wellsfargo.counselor.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; +import jakarta.persistence.*; + +import java.lang.reflect.GenericArrayType; +import java.util.List; @Entity public class Advisor { @Id - @GeneratedValue() + @GeneratedValue(strategy= GenerationType.IDENTITY) private long advisorId; @Column(nullable = false) @@ -25,22 +25,29 @@ public class Advisor { @Column(nullable = false) private String phone; + @Column(nullable = false) private String email; + @OneToMany(mappedBy = "advisor", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List clients; + + protected Advisor() { } - public Advisor(String firstName, String lastName, String address, String phone, String email) { + public Advisor(long advisorId, String firstName, String lastName, String address, String phone, String email, List clients) { + this.advisorId = advisorId; this.firstName = firstName; this.lastName = lastName; this.address = address; this.phone = phone; this.email = email; + this.clients = clients; } - public Long getAdvisorId() { + public long getAdvisorId() { return advisorId; } @@ -48,39 +55,51 @@ public String getFirstName() { return firstName; } - public void setFirstName(String firstName) { - this.firstName = firstName; - } - public String getLastName() { return lastName; } - public void setLastName(String lastName) { - this.lastName = lastName; - } - public String getAddress() { return address; } - public void setAddress(String address) { - this.address = address; - } - public String getPhone() { return phone; } - public void setPhone(String phone) { - this.phone = phone; - } - public String getEmail() { return email; } + public List getClients() { + return clients; + } + + public void setAdvisorId(long advisorId) { + this.advisorId = advisorId; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setPhone(String phone) { + this.phone = phone; + } + public void setEmail(String email) { this.email = email; } + + public void setClients(List clients) { + this.clients = clients; + } } diff --git a/src/main/java/com/wellsfargo/counselor/entity/Client.java b/src/main/java/com/wellsfargo/counselor/entity/Client.java new file mode 100644 index 00000000..de05ae88 --- /dev/null +++ b/src/main/java/com/wellsfargo/counselor/entity/Client.java @@ -0,0 +1,112 @@ +package com.wellsfargo.counselor.entity; + +import jakarta.persistence.*; +import org.hibernate.engine.internal.Cascade; + +@Entity +public class Client { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private long clientId; + + + @ManyToOne + @JoinColumn(name = "advisor_id", nullable = false) + private Advisor advisor; + + @Column(nullable = false) + private String firstName; + + @Column(nullable = false) + private String lastName; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + private String phone; + + @Column(nullable = false) + private String email; + @OneToOne(mappedBy = "protofolio", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private Protfolio protfolioId; + + public Client() { + } + + public Client(long clientId, Advisor advisor, String firstName, String lastName, String address, String phone, String email, Protfolio protfolioId) { + this.clientId = clientId; + this.advisor = advisor; + this.firstName = firstName; + this.lastName = lastName; + this.address = address; + this.phone = phone; + this.email = email; + this.protfolioId = protfolioId; + } + + public long getClientId() { + return clientId; + } + + public Advisor getAdvisor() { + return advisor; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getAddress() { + return address; + } + + public String getPhone() { + return phone; + } + + public String getEmail() { + return email; + } + + public Protfolio getProtfolioId() { + return protfolioId; + } + + public void setClientId(long clientId) { + this.clientId = clientId; + } + + public void setAdvisor(Advisor advisor) { + this.advisor = advisor; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setProtfolioId(Protfolio protfolioId) { + this.protfolioId = protfolioId; + } +} diff --git a/src/main/java/com/wellsfargo/counselor/entity/Protfolio.java b/src/main/java/com/wellsfargo/counselor/entity/Protfolio.java new file mode 100644 index 00000000..5e0d6c98 --- /dev/null +++ b/src/main/java/com/wellsfargo/counselor/entity/Protfolio.java @@ -0,0 +1,64 @@ +package com.wellsfargo.counselor.entity; + +import jakarta.persistence.*; + +import java.util.Date; +import java.util.List; + +@Entity +public class Protfolio { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int protfolioId; + + @OneToOne + @JoinColumn(name="client_id",nullable = false) + private Client clientId; + + @Column(nullable = false) + private Date creationDate; + @OneToMany(mappedBy="security",cascade = CascadeType.ALL,fetch = FetchType.LAZY) + private List securities; + + public Protfolio() { + } + + public Protfolio(int protfolioId, Client clientId, Date creationDate, List securities) { + this.protfolioId = protfolioId; + this.clientId = clientId; + this.creationDate = creationDate; + this.securities = securities; + } + + public int getProtfolioId() { + return protfolioId; + } + + public Client getClientId() { + return clientId; + } + + public Date getCreationDate() { + return creationDate; + } + + public List getSecurities() { + return securities; + } + + public void setProtfolioId(int protfolioId) { + this.protfolioId = protfolioId; + } + + public void setClientId(Client clientId) { + this.clientId = clientId; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public void setSecurities(List securities) { + this.securities = securities; + } +} diff --git a/src/main/java/com/wellsfargo/counselor/entity/Security.java b/src/main/java/com/wellsfargo/counselor/entity/Security.java new file mode 100644 index 00000000..536a0e83 --- /dev/null +++ b/src/main/java/com/wellsfargo/counselor/entity/Security.java @@ -0,0 +1,94 @@ +package com.wellsfargo.counselor.entity; + +import jakarta.persistence.*; + +import java.util.Date; + +@Entity +public class Security { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int security_id; + @OneToMany + @JoinColumn(name="protofolio_id",nullable = false) + private int protofolio_id; + @Column(nullable = false) + private String name; + @Column(nullable = false) + private String category; + @Column(nullable = false) + private float purchasePrice; + @Column(nullable = false) + private Date purchaseDate; + @Column(nullable = false) + private long qunatity; + + public Security() { + } + + public Security(int security_id, int protofolio_id, String name, String category, float purchasePrice, Date purchaseDate, long qunatity) { + this.security_id = security_id; + this.protofolio_id = protofolio_id; + this.name = name; + this.category = category; + this.purchasePrice = purchasePrice; + this.purchaseDate = purchaseDate; + this.qunatity = qunatity; + } + + public int getSecurity_id() { + return security_id; + } + + public int getProtofolio_id() { + return protofolio_id; + } + + public String getName() { + return name; + } + + public String getCategory() { + return category; + } + + public float getPurchasePrice() { + return purchasePrice; + } + + public Date getPurchaseDate() { + return purchaseDate; + } + + public long getQunatity() { + return qunatity; + } + + public void setSecurity_id(int security_id) { + this.security_id = security_id; + } + + public void setProtofolio_id(int protofolio_id) { + this.protofolio_id = protofolio_id; + } + + public void setName(String name) { + this.name = name; + } + + public void setCategory(String category) { + this.category = category; + } + + public void setPurchasePrice(float purchasePrice) { + this.purchasePrice = purchasePrice; + } + + public void setPurchaseDate(Date purchaseDate) { + this.purchaseDate = purchaseDate; + } + + public void setQunatity(long qunatity) { + this.qunatity = qunatity; + } +}