Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Lombok to entity classes #740

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
41 changes: 6 additions & 35 deletions src/test/java/com/example/ejb3/auction/AuctionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 15 additions & 47 deletions src/test/java/com/example/ejb3/auction/AuctionItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,37 @@
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<Bid> 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)
public List<Bid> getBids() {
return bids;
}

@Column(length = 1000)
public String getDescription() {
return description;
}

@ManyToOne
public User getSeller() {
return seller;
Expand All @@ -39,51 +49,9 @@ public Bid getSuccessfulBid() {
return successfulBid;
}

public void setBids(List<Bid> 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;
}


}
20 changes: 4 additions & 16 deletions src/test/java/com/example/ejb3/auction/AuditedItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.ejb3.auction;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.envers.Audited;

import jakarta.persistence.Column;
Expand All @@ -11,6 +13,8 @@

@Audited
@Entity
@Getter
@Setter
public class AuditedItem {

@Id
Expand All @@ -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;
}

}
27 changes: 7 additions & 20 deletions src/test/java/com/example/ejb3/auction/Bid.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Date;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

Expand All @@ -18,46 +20,31 @@
@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
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;
}
Expand Down
27 changes: 4 additions & 23 deletions src/test/java/com/example/ejb3/auction/FirstTable.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
}
20 changes: 4 additions & 16 deletions src/test/java/com/example/ejb3/auction/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}

}
28 changes: 4 additions & 24 deletions src/test/java/com/example/ejb3/auction/Name.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/com/example/ejb3/auction/Persistent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,8 +17,4 @@ public Long getId() {
return id;
}

public void setId(Long long1) {
id = long1;
}

}
Loading
Loading