mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-29 06:39:38 +00:00
Make all entity fields private
Encapsulation is better that way (and tere is a getter for all of them anyway).
This commit is contained in:
parent
0a51540ad0
commit
63dadcc07f
3 changed files with 20 additions and 20 deletions
|
@ -33,7 +33,7 @@ import javax.persistence.MappedSuperclass;
|
||||||
public class BaseEntity implements Serializable {
|
public class BaseEntity implements Serializable {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
protected Integer id;
|
private Integer id;
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
@ -30,11 +30,11 @@ public class Person extends BaseEntity {
|
||||||
|
|
||||||
@Column(name = "first_name")
|
@Column(name = "first_name")
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
protected String firstName;
|
private String firstName;
|
||||||
|
|
||||||
@Column(name = "last_name")
|
@Column(name = "last_name")
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
protected String lastName;
|
private String lastName;
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return this.firstName;
|
return this.firstName;
|
||||||
|
@ -52,5 +52,4 @@ public class Person extends BaseEntity {
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import org.springframework.beans.support.MutableSortDefinition;
|
import java.util.ArrayList;
|
||||||
import org.springframework.beans.support.PropertyComparator;
|
import java.util.Collections;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import java.util.Date;
|
||||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
import java.util.HashSet;
|
||||||
import org.springframework.samples.petclinic.visit.Visit;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
@ -29,16 +31,14 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import org.springframework.beans.support.MutableSortDefinition;
|
||||||
import java.util.Date;
|
import org.springframework.beans.support.PropertyComparator;
|
||||||
import java.util.HashSet;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import java.util.LinkedHashSet;
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
import java.util.List;
|
import org.springframework.samples.petclinic.visit.Visit;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple business object representing a pet.
|
* Simple business object representing a pet.
|
||||||
|
@ -64,7 +64,7 @@ public class Pet extends NamedEntity {
|
||||||
@JoinColumn(name = "owner_id")
|
@JoinColumn(name = "owner_id")
|
||||||
private Owner owner;
|
private Owner owner;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy="petId", fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, mappedBy = "petId", fetch = FetchType.EAGER)
|
||||||
private Set<Visit> visits = new LinkedHashSet<>();
|
private Set<Visit> visits = new LinkedHashSet<>();
|
||||||
|
|
||||||
public void setBirthDate(Date birthDate) {
|
public void setBirthDate(Date birthDate) {
|
||||||
|
@ -104,13 +104,14 @@ public class Pet extends NamedEntity {
|
||||||
|
|
||||||
public List<Visit> getVisits() {
|
public List<Visit> getVisits() {
|
||||||
List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal());
|
List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal());
|
||||||
PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
|
PropertyComparator.sort(sortedVisits,
|
||||||
|
new MutableSortDefinition("date", false, false));
|
||||||
return Collections.unmodifiableList(sortedVisits);
|
return Collections.unmodifiableList(sortedVisits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVisit(Visit visit) {
|
public void addVisit(Visit visit) {
|
||||||
getVisitsInternal().add(visit);
|
getVisitsInternal().add(visit);
|
||||||
visit.setPetId(this.id);
|
visit.setPetId(this.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue