-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Spring Data JPA Service for PetType. closes #41
- Loading branch information
1 parent
3e92057
commit 1e235cd
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
.../src/main/java/spring/framework/petclinic/services/springdatajpa/PetTypeSDJpaService.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package spring.framework.petclinic.services.springdatajpa; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
import spring.framework.petclinic.model.PetType; | ||
import spring.framework.petclinic.repositories.PetTypeRepository; | ||
import spring.framework.petclinic.services.PetTypeService; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Service | ||
@Profile("springdatajpa") | ||
public class PetTypeSDJpaService implements PetTypeService { | ||
|
||
private final PetTypeRepository petTypeRepository; | ||
|
||
public PetTypeSDJpaService(PetTypeRepository petTypeRepository) { | ||
this.petTypeRepository = petTypeRepository; | ||
} | ||
|
||
@Override | ||
public Set<PetType> findAll() { | ||
Set<PetType> petTypes = new HashSet<>(); | ||
petTypeRepository.findAll().forEach(petTypes::add); | ||
return petTypes; | ||
} | ||
|
||
@Override | ||
public PetType findById(Long aLong) { | ||
return petTypeRepository.findById(aLong).orElse(null); | ||
} | ||
|
||
@Override | ||
public PetType save(PetType object) { | ||
return petTypeRepository.save(object); | ||
} | ||
|
||
@Override | ||
public void delete(PetType object) { | ||
petTypeRepository.delete(object); | ||
} | ||
|
||
@Override | ||
public void deleteById(Long aLong) { | ||
petTypeRepository.deleteById(aLong); | ||
} | ||
} |