Skip to content
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
1,254 changes: 949 additions & 305 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@
import javax.persistence.MappedSuperclass;

/**
* Simple JavaBean domain object with an id property.
* Used as a base class for objects needing this property.
* Simple JavaBean domain object with an id property. Used as a base class for objects needing this property.
*
* @author Ken Krebs
* @author Juergen Hoeller
*/
@MappedSuperclass
public class BaseEntity {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;

public void setId(Integer id) {
this.id = id;
}

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}

public boolean isNew() {
return (this.id == null);
}
public Integer getId() {
return id;
}

public boolean isNew() {
return (this.id == null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@


/**
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>.
* Used as a base class for objects needing these properties.
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as a base class for objects
* needing these properties.
*
* @author Ken Krebs
* @author Juergen Hoeller
*/
@MappedSuperclass
public class NamedEntity extends BaseEntity {

@Column(name="name")
private String name;

@Column(name = "name")
private String name;

public void setName(String name) {
this.name = name;
}

public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return this.getName();
}
public String getName() {
return this.name;
}

@Override
public String toString() {
return this.getName();
}

}
231 changes: 112 additions & 119 deletions src/main/java/org/springframework/samples/petclinic/model/Owner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,15 @@
*/
package org.springframework.samples.petclinic.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Digits;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.core.style.ToStringCreator;

import javax.persistence.*;
import javax.validation.constraints.Digits;
import java.util.*;

/**
* Simple JavaBean domain object representing an owner.
*
Expand All @@ -41,111 +32,113 @@
* @author Sam Brannen
* @author Michael Isvy
*/
@Entity @Table(name="owners")
@Entity
@Table(name = "owners")
public class Owner extends Person {
@Column(name="address")
@NotEmpty
private String address;

@Column(name="city")
@NotEmpty
private String city;

@Column(name="telephone")
@NotEmpty @Digits(fraction = 0, integer = 10)
private String telephone;

@OneToMany(cascade=CascadeType.ALL, mappedBy="owner")
private Set<Pet> pets;


public String getAddress() {
return this.address;
}

public void setAddress(String address) {
this.address = address;
}

public String getCity() {
return this.city;
}

public void setCity(String city) {
this.city = city;
}

public String getTelephone() {
return this.telephone;
}

public void setTelephone(String telephone) {
this.telephone = telephone;
}

protected void setPetsInternal(Set<Pet> pets) {
this.pets = pets;
}

protected Set<Pet> getPetsInternal() {
if (this.pets == null) {
this.pets = new HashSet<Pet>();
}
return this.pets;
}

public List<Pet> getPets() {
List<Pet> sortedPets = new ArrayList<Pet>(getPetsInternal());
PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true));
return Collections.unmodifiableList(sortedPets);
}

public void addPet(Pet pet) {
getPetsInternal().add(pet);
pet.setOwner(this);
}

/**
* Return the Pet with the given name, or null if none found for this Owner.
*
* @param name to test
* @return true if pet name is already in use
*/
public Pet getPet(String name) {
return getPet(name, false);
}

/**
* Return the Pet with the given name, or null if none found for this Owner.
*
* @param name to test
* @return true if pet name is already in use
*/
public Pet getPet(String name, boolean ignoreNew) {
name = name.toLowerCase();
for (Pet pet : getPetsInternal()) {
if (!ignoreNew || !pet.isNew()) {
String compName = pet.getName();
compName = compName.toLowerCase();
if (compName.equals(name)) {
return pet;
}
}
}
return null;
}

@Override
public String toString() {
return new ToStringCreator(this)

.append("id", this.getId())
.append("new", this.isNew())
.append("lastName", this.getLastName())
.append("firstName", this.getFirstName())
.append("address", this.address)
.append("city", this.city)
.append("telephone", this.telephone)
.toString();
}
@Column(name = "address")
@NotEmpty
private String address;

@Column(name = "city")
@NotEmpty
private String city;

@Column(name = "telephone")
@NotEmpty
@Digits(fraction = 0, integer = 10)
private String telephone;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
private Set<Pet> pets;


public String getAddress() {
return this.address;
}

public void setAddress(String address) {
this.address = address;
}

public String getCity() {
return this.city;
}

public void setCity(String city) {
this.city = city;
}

public String getTelephone() {
return this.telephone;
}

public void setTelephone(String telephone) {
this.telephone = telephone;
}

protected void setPetsInternal(Set<Pet> pets) {
this.pets = pets;
}

protected Set<Pet> getPetsInternal() {
if (this.pets == null) {
this.pets = new HashSet<Pet>();
}
return this.pets;
}

public List<Pet> getPets() {
List<Pet> sortedPets = new ArrayList<Pet>(getPetsInternal());
PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true));
return Collections.unmodifiableList(sortedPets);
}

public void addPet(Pet pet) {
getPetsInternal().add(pet);
pet.setOwner(this);
}

/**
* Return the Pet with the given name, or null if none found for this Owner.
*
* @param name to test
* @return true if pet name is already in use
*/
public Pet getPet(String name) {
return getPet(name, false);
}

/**
* Return the Pet with the given name, or null if none found for this Owner.
*
* @param name to test
* @return true if pet name is already in use
*/
public Pet getPet(String name, boolean ignoreNew) {
name = name.toLowerCase();
for (Pet pet : getPetsInternal()) {
if (!ignoreNew || !pet.isNew()) {
String compName = pet.getName();
compName = compName.toLowerCase();
if (compName.equals(name)) {
return pet;
}
}
}
return null;
}

@Override
public String toString() {
return new ToStringCreator(this)

.append("id", this.getId())
.append("new", this.isNew())
.append("lastName", this.getLastName())
.append("firstName", this.getFirstName())
.append("address", this.address)
.append("city", this.city)
.append("telephone", this.telephone)
.toString();
}
}
Loading