forked from gii-is-DP2/spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganized packages to a domain-oriented approach
The packages are owner, pet, vet and user. We chose to keep pet out of owner because it is the central element of the application. However, visit is included in pet because a visit heavily depends on the pet that makes it. These were also the same packages that were used to organized the JSP code.
- Loading branch information
Showing
38 changed files
with
824 additions
and
842 deletions.
There are no files selected for viewing
361 changes: 182 additions & 179 deletions
361
...mework/samples/petclinic/model/Owner.java → ...mework/samples/petclinic/owner/Owner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,179 +1,182 @@ | ||
/* | ||
* Copyright 2002-2013 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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.JoinColumn; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
import javax.validation.constraints.Digits; | ||
import javax.validation.constraints.NotEmpty; | ||
|
||
import org.springframework.beans.support.MutableSortDefinition; | ||
import org.springframework.beans.support.PropertyComparator; | ||
import org.springframework.core.style.ToStringCreator; | ||
|
||
/** | ||
* Simple JavaBean domain object representing an owner. | ||
* | ||
* @author Ken Krebs | ||
* @author Juergen Hoeller | ||
* @author Sam Brannen | ||
* @author Michael Isvy | ||
*/ | ||
@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; | ||
|
||
// | ||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "username", referencedColumnName = "username") | ||
private User user; | ||
// | ||
|
||
public String getAddress() { | ||
return this.address; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
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 Set<Pet> getPetsInternal() { | ||
if (this.pets == null) { | ||
this.pets = new HashSet<>(); | ||
} | ||
return this.pets; | ||
} | ||
|
||
protected void setPetsInternal(Set<Pet> pets) { | ||
this.pets = pets; | ||
} | ||
|
||
public List<Pet> getPets() { | ||
List<Pet> sortedPets = new ArrayList<>(getPetsInternal()); | ||
PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); | ||
return Collections.unmodifiableList(sortedPets); | ||
} | ||
|
||
public void addPet(Pet pet) { | ||
getPetsInternal().add(pet); | ||
pet.setOwner(this); | ||
} | ||
|
||
public boolean removePet(Pet pet) { | ||
return getPetsInternal().remove(pet); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
public Pet getPetwithIdDifferent(String name,Integer id) { | ||
name = name.toLowerCase(); | ||
for (Pet pet : getPetsInternal()) { | ||
String compName = pet.getName(); | ||
compName = compName.toLowerCase(); | ||
if (compName.equals(name) && pet.getId()!=id) { | ||
return pet; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* 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(); | ||
} | ||
|
||
} | ||
/* | ||
* Copyright 2002-2013 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.samples.petclinic.owner; | ||
|
||
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.JoinColumn; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
import javax.validation.constraints.Digits; | ||
import javax.validation.constraints.NotEmpty; | ||
|
||
import org.springframework.beans.support.MutableSortDefinition; | ||
import org.springframework.beans.support.PropertyComparator; | ||
import org.springframework.core.style.ToStringCreator; | ||
import org.springframework.samples.petclinic.model.Person; | ||
import org.springframework.samples.petclinic.pet.Pet; | ||
import org.springframework.samples.petclinic.user.User; | ||
|
||
/** | ||
* Simple JavaBean domain object representing an owner. | ||
* | ||
* @author Ken Krebs | ||
* @author Juergen Hoeller | ||
* @author Sam Brannen | ||
* @author Michael Isvy | ||
*/ | ||
@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; | ||
|
||
// | ||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "username", referencedColumnName = "username") | ||
private User user; | ||
// | ||
|
||
public String getAddress() { | ||
return this.address; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(User user) { | ||
this.user = user; | ||
} | ||
|
||
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 Set<Pet> getPetsInternal() { | ||
if (this.pets == null) { | ||
this.pets = new HashSet<>(); | ||
} | ||
return this.pets; | ||
} | ||
|
||
protected void setPetsInternal(Set<Pet> pets) { | ||
this.pets = pets; | ||
} | ||
|
||
public List<Pet> getPets() { | ||
List<Pet> sortedPets = new ArrayList<>(getPetsInternal()); | ||
PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); | ||
return Collections.unmodifiableList(sortedPets); | ||
} | ||
|
||
public void addPet(Pet pet) { | ||
getPetsInternal().add(pet); | ||
pet.setOwner(this); | ||
} | ||
|
||
public boolean removePet(Pet pet) { | ||
return getPetsInternal().remove(pet); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
public Pet getPetwithIdDifferent(String name,Integer id) { | ||
name = name.toLowerCase(); | ||
for (Pet pet : getPetsInternal()) { | ||
String compName = pet.getName(); | ||
compName = compName.toLowerCase(); | ||
if (compName.equals(name) && pet.getId()!=id) { | ||
return pet; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* 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(); | ||
} | ||
|
||
} |
Oops, something went wrong.