Skip to content

Commit

Permalink
Make all entity fields private
Browse files Browse the repository at this point in the history
Encapsulation is better that way (and tere is a getter for all of them
anyway).
  • Loading branch information
dsyer committed Feb 3, 2017
1 parent 0a51540 commit 63dadcc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
private Integer id;

public Integer getId() {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,5 +52,4 @@ public void setLastName(String lastName) {
this.lastName = lastName;
}


}
33 changes: 17 additions & 16 deletions src/main/java/org/springframework/samples/petclinic/owner/Pet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,16 +31,14 @@
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.
Expand All @@ -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) {
Expand Down Expand Up @@ -104,13 +104,14 @@ protected void setVisitsInternal(Set<Visit> visits) {

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());
}

}

0 comments on commit 63dadcc

Please sign in to comment.