mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-28 06:09:37 +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 {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
protected Integer id;
|
||||
private Integer id;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
|
|
|
@ -30,11 +30,11 @@ public class Person extends BaseEntity {
|
|||
|
||||
@Column(name = "first_name")
|
||||
@NotEmpty
|
||||
protected String firstName;
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "last_name")
|
||||
@NotEmpty
|
||||
protected String lastName;
|
||||
private String lastName;
|
||||
|
||||
public String getFirstName() {
|
||||
return this.firstName;
|
||||
|
@ -52,5 +52,4 @@ public class Person extends BaseEntity {
|
|||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||
import org.springframework.samples.petclinic.visit.Visit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
|
@ -29,16 +31,14 @@ import javax.persistence.JoinColumn;
|
|||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||
import org.springframework.samples.petclinic.visit.Visit;
|
||||
|
||||
/**
|
||||
* Simple business object representing a pet.
|
||||
|
@ -64,7 +64,7 @@ public class Pet extends NamedEntity {
|
|||
@JoinColumn(name = "owner_id")
|
||||
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<>();
|
||||
|
||||
public void setBirthDate(Date birthDate) {
|
||||
|
@ -104,13 +104,14 @@ public class Pet extends NamedEntity {
|
|||
|
||||
public List<Visit> getVisits() {
|
||||
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);
|
||||
}
|
||||
|
||||
public void addVisit(Visit visit) {
|
||||
getVisitsInternal().add(visit);
|
||||
visit.setPetId(this.id);
|
||||
visit.setPetId(this.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue