From fb98162460790b795ff2fcf84c3df80d778caad1 Mon Sep 17 00:00:00 2001 From: Daniel Mallorga Date: Fri, 27 Dec 2024 15:09:13 -0300 Subject: [PATCH] - Lombok dependency added. - Getter and setter methods replaced by Lombok annotations. --- pom.xml | 7 +++ .../com/example/ejb3/auction/AuctionInfo.java | 41 ++---------- .../com/example/ejb3/auction/AuctionItem.java | 62 +++++-------------- .../com/example/ejb3/auction/AuditedItem.java | 20 ++---- .../java/com/example/ejb3/auction/Bid.java | 27 +++----- .../com/example/ejb3/auction/FirstTable.java | 27 ++------ .../java/com/example/ejb3/auction/Item.java | 20 ++---- .../java/com/example/ejb3/auction/Name.java | 28 ++------- .../com/example/ejb3/auction/Persistent.java | 7 +-- .../com/example/ejb3/auction/SecondTable.java | 11 ++-- .../java/com/example/ejb3/auction/User.java | 47 +++----------- .../com/example/pojo/auction/AuctionInfo.java | 19 +----- .../com/example/pojo/auction/AuctionItem.java | 61 ++---------------- .../java/com/example/pojo/auction/Bid.java | 37 ++--------- .../java/com/example/pojo/auction/Name.java | 29 ++------- .../com/example/pojo/auction/Persistent.java | 13 ++-- .../java/com/example/pojo/auction/User.java | 53 ++-------------- src/test/java/com/example/timezone/Item.java | 44 ++----------- 18 files changed, 97 insertions(+), 456 deletions(-) diff --git a/pom.xml b/pom.xml index 68720773..b588147c 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,7 @@ 6.3.1.Final 6.2.1 4.30.0 + 1.18.36 11 11 @@ -151,6 +152,12 @@ postgresql test + + org.projectlombok + lombok + ${lombok.version} + provided + diff --git a/src/test/java/com/example/ejb3/auction/AuctionInfo.java b/src/test/java/com/example/ejb3/auction/AuctionInfo.java index fe749c66..4dc65818 100644 --- a/src/test/java/com/example/ejb3/auction/AuctionInfo.java +++ b/src/test/java/com/example/ejb3/auction/AuctionInfo.java @@ -5,49 +5,20 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import lombok.Getter; +import lombok.Setter; +@Getter +@Setter @Entity public class AuctionInfo { + @Id private String id; + @Column(length = 1000) private String description; private Date ends; private Float maxAmount; - @Column(length = 1000) - public String getDescription() { - return description; - } - - public Date getEnds() { - return ends; - } - - @Id - public String getId() { - return id; - } - - - public Float getMaxAmount() { - return maxAmount; - } - - public void setId(String id) { - this.id = id; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setEnds(Date ends) { - this.ends = ends; - } - - public void setMaxAmount(Float maxAmount) { - this.maxAmount = maxAmount; - } - public AuctionInfo(String id, String description, Date ends, Float maxAmount) { this.id = id; this.description = description; diff --git a/src/test/java/com/example/ejb3/auction/AuctionItem.java b/src/test/java/com/example/ejb3/auction/AuctionItem.java index 4f669998..32a9b882 100644 --- a/src/test/java/com/example/ejb3/auction/AuctionItem.java +++ b/src/test/java/com/example/ejb3/auction/AuctionItem.java @@ -8,15 +8,30 @@ import jakarta.persistence.Entity; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; +import lombok.Getter; +import lombok.Setter; @Entity public class AuctionItem extends Persistent { + @Column(length = 1000) + @Getter + @Setter private String description; + @Column(length = 200) + @Getter + @Setter private String shortDescription; + @Setter private List bids; + @Setter private Bid successfulBid; + @Setter private User seller; + @Getter + @Setter private Date ends; + @Getter + @Setter private int condition; @OneToMany(mappedBy = "item", cascade = CascadeType.ALL) @@ -24,11 +39,6 @@ public List getBids() { return bids; } - @Column(length = 1000) - public String getDescription() { - return description; - } - @ManyToOne public User getSeller() { return seller; @@ -39,51 +49,9 @@ public Bid getSuccessfulBid() { return successfulBid; } - public void setBids(List bids) { - this.bids = bids; - } - - public void setDescription(String string) { - description = string; - } - - public void setSeller(User user) { - seller = user; - } - - public void setSuccessfulBid(Bid bid) { - successfulBid = bid; - } - - public Date getEnds() { - return ends; - } - - public void setEnds(Date date) { - ends = date; - } - - public int getCondition() { - return condition; - } - - public void setCondition(int i) { - condition = i; - } - public String toString() { return shortDescription + " (" + description + ": " + condition + "/10)"; } - @Column(length = 200) - public String getShortDescription() { - return shortDescription; - } - - public void setShortDescription(String shortDescription) { - this.shortDescription = shortDescription; - } - - } diff --git a/src/test/java/com/example/ejb3/auction/AuditedItem.java b/src/test/java/com/example/ejb3/auction/AuditedItem.java index 8eef37df..fc0dadf1 100755 --- a/src/test/java/com/example/ejb3/auction/AuditedItem.java +++ b/src/test/java/com/example/ejb3/auction/AuditedItem.java @@ -1,5 +1,7 @@ package com.example.ejb3.auction; +import lombok.Getter; +import lombok.Setter; import org.hibernate.envers.Audited; import jakarta.persistence.Column; @@ -11,6 +13,8 @@ @Audited @Entity +@Getter +@Setter public class AuditedItem { @Id @@ -20,20 +24,4 @@ public class AuditedItem { @Column(unique = true) private String name; - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } diff --git a/src/test/java/com/example/ejb3/auction/Bid.java b/src/test/java/com/example/ejb3/auction/Bid.java index b61a7ae4..c5b534f7 100644 --- a/src/test/java/com/example/ejb3/auction/Bid.java +++ b/src/test/java/com/example/ejb3/auction/Bid.java @@ -2,6 +2,8 @@ import java.util.Date; +import lombok.Getter; +import lombok.Setter; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; @@ -18,9 +20,14 @@ @DiscriminatorValue("Y") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class Bid extends Persistent { + @Setter private AuctionItem item; + @Setter + @Getter private float amount; + @Setter private Date datetime; + @Setter private User bidder; @ManyToOne @@ -28,36 +35,16 @@ public AuctionItem getItem() { return item; } - public void setItem(AuctionItem item) { - this.item = item; - } - - public float getAmount() { - return amount; - } - @Column(nullable = false, name = "datetime") public Date getDatetime() { return datetime; } - public void setAmount(float f) { - amount = f; - } - - public void setDatetime(Date date) { - datetime = date; - } - @ManyToOne(optional = false) public User getBidder() { return bidder; } - public void setBidder(User user) { - bidder = user; - } - public String toString() { return bidder.getUserName() + " $" + amount; } diff --git a/src/test/java/com/example/ejb3/auction/FirstTable.java b/src/test/java/com/example/ejb3/auction/FirstTable.java index b6209706..5464b4d9 100644 --- a/src/test/java/com/example/ejb3/auction/FirstTable.java +++ b/src/test/java/com/example/ejb3/auction/FirstTable.java @@ -1,7 +1,11 @@ package com.example.ejb3.auction; import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter @Entity @SecondaryTable(name = "second_table", pkJoinColumns = @PrimaryKeyJoinColumn(name = "first_table_id")) public class FirstTable { @@ -14,27 +18,4 @@ public class FirstTable { @Embedded private SecondTable secondTable; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public SecondTable getSecondTable() { - return secondTable; - } - - public void setSecondTable(SecondTable secondTable) { - this.secondTable = secondTable; - } } diff --git a/src/test/java/com/example/ejb3/auction/Item.java b/src/test/java/com/example/ejb3/auction/Item.java index 06267480..02a23776 100644 --- a/src/test/java/com/example/ejb3/auction/Item.java +++ b/src/test/java/com/example/ejb3/auction/Item.java @@ -6,7 +6,11 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.SequenceGenerator; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter @Entity public class Item { @@ -17,20 +21,4 @@ public class Item { @Column(unique = true) private String name; - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } diff --git a/src/test/java/com/example/ejb3/auction/Name.java b/src/test/java/com/example/ejb3/auction/Name.java index 96c69b80..c0fde3a5 100644 --- a/src/test/java/com/example/ejb3/auction/Name.java +++ b/src/test/java/com/example/ejb3/auction/Name.java @@ -1,7 +1,11 @@ package com.example.ejb3.auction; import jakarta.persistence.Embeddable; +import lombok.Getter; +import lombok.Setter; +@Setter +@Getter @Embeddable public class Name { private String firstName; @@ -14,30 +18,6 @@ public Name(String first, Character middle, String last) { lastName = last; } - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public Character getInitial() { - return initial; - } - - public void setInitial(Character initial) { - this.initial = initial; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - public String toString() { StringBuffer buf = new StringBuffer().append(firstName).append(' '); if (initial != null) diff --git a/src/test/java/com/example/ejb3/auction/Persistent.java b/src/test/java/com/example/ejb3/auction/Persistent.java index 8ac7a8e3..8aed43f4 100644 --- a/src/test/java/com/example/ejb3/auction/Persistent.java +++ b/src/test/java/com/example/ejb3/auction/Persistent.java @@ -3,9 +3,12 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import lombok.Setter; @MappedSuperclass public class Persistent { + @Setter private Long id; @Id @@ -14,8 +17,4 @@ public Long getId() { return id; } - public void setId(Long long1) { - id = long1; - } - } diff --git a/src/test/java/com/example/ejb3/auction/SecondTable.java b/src/test/java/com/example/ejb3/auction/SecondTable.java index 9bc408d5..60b1b686 100644 --- a/src/test/java/com/example/ejb3/auction/SecondTable.java +++ b/src/test/java/com/example/ejb3/auction/SecondTable.java @@ -2,18 +2,15 @@ import jakarta.persistence.Column; import jakarta.persistence.Embeddable; +import lombok.Getter; +import lombok.Setter; @Embeddable public class SecondTable { @Column(table = "second_table") + @Getter + @Setter private String secondName; - public String getSecondName() { - return secondName; - } - - public void setSecondName(String secondName) { - this.secondName = secondName; - } } diff --git a/src/test/java/com/example/ejb3/auction/User.java b/src/test/java/com/example/ejb3/auction/User.java index 45360fb7..614b5af2 100644 --- a/src/test/java/com/example/ejb3/auction/User.java +++ b/src/test/java/com/example/ejb3/auction/User.java @@ -5,40 +5,23 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.OneToMany; +import lombok.Getter; +import lombok.Setter; +@Setter @Entity public class User extends Persistent { + @Getter private String userName; + @Getter private String password; + @Getter private String email; + @Getter private Name name; private List bids; private List auctions; - public String getEmail() { - return email; - } - - public String getPassword() { - return password; - } - - public String getUserName() { - return userName; - } - - public void setEmail(String string) { - email = string; - } - - public void setPassword(String string) { - password = string; - } - - public void setUserName(String string) { - userName = string; - } - @OneToMany(mappedBy = "seller", cascade = CascadeType.ALL) public List getAuctions() { return auctions; @@ -49,24 +32,8 @@ public List getBids() { return bids; } - public void setAuctions(List list) { - auctions = list; - } - - public void setBids(List list) { - bids = list; - } - public String toString() { return userName; } - public Name getName() { - return name; - } - - public void setName(Name name) { - this.name = name; - } - } diff --git a/src/test/java/com/example/pojo/auction/AuctionInfo.java b/src/test/java/com/example/pojo/auction/AuctionInfo.java index 69a93ace..59c26b7f 100644 --- a/src/test/java/com/example/pojo/auction/AuctionInfo.java +++ b/src/test/java/com/example/pojo/auction/AuctionInfo.java @@ -1,29 +1,16 @@ package com.example.pojo.auction; +import lombok.Getter; + import java.util.Date; +@Getter public class AuctionInfo { private long id; private String description; private Date ends; private Float maxAmount; - public String getDescription() { - return description; - } - - public Date getEnds() { - return ends; - } - - public long getId() { - return id; - } - - public Float getMaxAmount() { - return maxAmount; - } - public AuctionInfo(long id, String description, Date ends, Float maxAmount) { this.id = id; this.description = description; diff --git a/src/test/java/com/example/pojo/auction/AuctionItem.java b/src/test/java/com/example/pojo/auction/AuctionItem.java index 9ce2ad16..a3b5fca8 100644 --- a/src/test/java/com/example/pojo/auction/AuctionItem.java +++ b/src/test/java/com/example/pojo/auction/AuctionItem.java @@ -1,8 +1,13 @@ package com.example.pojo.auction; +import lombok.Getter; +import lombok.Setter; + import java.util.Date; import java.util.List; +@Getter +@Setter public class AuctionItem extends Persistent { private String description; private String shortDescription; @@ -12,64 +17,8 @@ public class AuctionItem extends Persistent { private Date ends; private int condition; - public List getBids() { - return bids; - } - - public String getDescription() { - return description; - } - - public User getSeller() { - return seller; - } - - public Bid getSuccessfulBid() { - return successfulBid; - } - - public void setBids(List bids) { - this.bids = bids; - } - - public void setDescription(String string) { - description = string; - } - - public void setSeller(User user) { - seller = user; - } - - public void setSuccessfulBid(Bid bid) { - successfulBid = bid; - } - - public Date getEnds() { - return ends; - } - - public void setEnds(Date date) { - ends = date; - } - - public int getCondition() { - return condition; - } - - public void setCondition(int i) { - condition = i; - } - public String toString() { return shortDescription + " (" + description + ": " + condition + "/10)"; } - public String getShortDescription() { - return shortDescription; - } - - public void setShortDescription(String shortDescription) { - this.shortDescription = shortDescription; - } - } diff --git a/src/test/java/com/example/pojo/auction/Bid.java b/src/test/java/com/example/pojo/auction/Bid.java index 31eed93a..ef3772a6 100644 --- a/src/test/java/com/example/pojo/auction/Bid.java +++ b/src/test/java/com/example/pojo/auction/Bid.java @@ -1,45 +1,18 @@ package com.example.pojo.auction; +import lombok.Getter; +import lombok.Setter; + import java.util.Date; +@Getter +@Setter public class Bid extends Persistent { private AuctionItem item; private float amount; private Date datetime; private User bidder; - public AuctionItem getItem() { - return item; - } - - public void setItem(AuctionItem item) { - this.item = item; - } - - public float getAmount() { - return amount; - } - - public Date getDatetime() { - return datetime; - } - - public void setAmount(float f) { - amount = f; - } - - public void setDatetime(Date date) { - datetime = date; - } - - public User getBidder() { - return bidder; - } - - public void setBidder(User user) { - bidder = user; - } - public String toString() { return bidder.getUserName() + " $" + amount; } diff --git a/src/test/java/com/example/pojo/auction/Name.java b/src/test/java/com/example/pojo/auction/Name.java index f00115d7..bca2b6f1 100644 --- a/src/test/java/com/example/pojo/auction/Name.java +++ b/src/test/java/com/example/pojo/auction/Name.java @@ -1,5 +1,10 @@ package com.example.pojo.auction; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter public class Name { private String firstName; private String lastName; @@ -11,30 +16,6 @@ public Name(String first, Character middle, String last) { lastName = last; } - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public Character getInitial() { - return initial; - } - - public void setInitial(Character initial) { - this.initial = initial; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - public String toString() { StringBuffer buf = new StringBuffer().append(firstName).append(' '); if (initial != null) diff --git a/src/test/java/com/example/pojo/auction/Persistent.java b/src/test/java/com/example/pojo/auction/Persistent.java index df65016f..d423ccc1 100644 --- a/src/test/java/com/example/pojo/auction/Persistent.java +++ b/src/test/java/com/example/pojo/auction/Persistent.java @@ -1,14 +1,11 @@ package com.example.pojo.auction; +import lombok.Getter; +import lombok.Setter; + public class Persistent { + @Setter + @Getter private Long id; - public Long getId() { - return id; - } - - public void setId(Long long1) { - id = long1; - } - } diff --git a/src/test/java/com/example/pojo/auction/User.java b/src/test/java/com/example/pojo/auction/User.java index 2baa1b92..c9ec4371 100644 --- a/src/test/java/com/example/pojo/auction/User.java +++ b/src/test/java/com/example/pojo/auction/User.java @@ -1,7 +1,12 @@ package com.example.pojo.auction; +import lombok.Getter; +import lombok.Setter; + import java.util.List; +@Getter +@Setter public class User extends Persistent { private String userName; private String password; @@ -10,56 +15,8 @@ public class User extends Persistent { private List bids; private List auctions; - public String getEmail() { - return email; - } - - public String getPassword() { - return password; - } - - public String getUserName() { - return userName; - } - - public void setEmail(String string) { - email = string; - } - - public void setPassword(String string) { - password = string; - } - - public void setUserName(String string) { - userName = string; - } - - public List getAuctions() { - return auctions; - } - - public List getBids() { - return bids; - } - - public void setAuctions(List list) { - auctions = list; - } - - public void setBids(List list) { - bids = list; - } - public String toString() { return userName; } - public Name getName() { - return name; - } - - public void setName(Name name) { - this.name = name; - } - } diff --git a/src/test/java/com/example/timezone/Item.java b/src/test/java/com/example/timezone/Item.java index 8d9aacc6..8bc7ac42 100644 --- a/src/test/java/com/example/timezone/Item.java +++ b/src/test/java/com/example/timezone/Item.java @@ -1,10 +1,14 @@ package com.example.timezone; import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; import java.time.Instant; import java.time.LocalDateTime; +@Getter +@Setter @Entity public class Item { @@ -24,44 +28,4 @@ public class Item { @Column(columnDefinition = "TIMESTAMP WITH TIME ZONE") private LocalDateTime timestamp4; - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public Instant getTimestamp1() { - return timestamp1; - } - - public void setTimestamp1(Instant timestamp1) { - this.timestamp1 = timestamp1; - } - - public LocalDateTime getTimestamp2() { - return timestamp2; - } - - public void setTimestamp2(LocalDateTime timestamp2) { - this.timestamp2 = timestamp2; - } - - public Instant getTimestamp3() { - return timestamp3; - } - - public void setTimestamp3(Instant timestamp3) { - this.timestamp3 = timestamp3; - } - - public LocalDateTime getTimestamp4() { - return timestamp4; - } - - public void setTimestamp4(LocalDateTime timestamp4) { - this.timestamp4 = timestamp4; - } - }