-
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.
added spring data jpa service for vets.closes #41
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...inic-data/src/main/java/guru/springframework/sfgpetclinic/repositories/VetRepository.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,7 @@ | ||
package guru.springframework.sfgpetclinic.repositories; | ||
|
||
import guru.springframework.sfgpetclinic.model.Vet; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface VetRepository extends CrudRepository<Vet,Long> { | ||
} |
48 changes: 48 additions & 0 deletions
48
...c/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/VetSDJpaService.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 guru.springframework.sfgpetclinic.services.springdatajpa; | ||
|
||
import guru.springframework.sfgpetclinic.model.Vet; | ||
import guru.springframework.sfgpetclinic.repositories.VetRepository; | ||
import guru.springframework.sfgpetclinic.services.VetService; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Service | ||
@Profile("springdatajpa") | ||
public class VetSDJpaService implements VetService { | ||
|
||
private final VetRepository vetRepository; | ||
|
||
public VetSDJpaService(VetRepository vetRepository) { | ||
this.vetRepository = vetRepository; | ||
} | ||
|
||
@Override | ||
public Set<Vet> findAll() { | ||
Set<Vet> vets = new HashSet<>(); | ||
vetRepository.findAll().forEach(vets::add); | ||
return vets; | ||
} | ||
|
||
@Override | ||
public Vet findById(Long aLong) { | ||
return vetRepository.findById(aLong).orElse(null); | ||
} | ||
|
||
@Override | ||
public Vet save(Vet object) { | ||
return vetRepository.save(object); | ||
} | ||
|
||
@Override | ||
public void delete(Vet object) { | ||
vetRepository.delete(object); | ||
} | ||
|
||
@Override | ||
public void deleteById(Long aLong) { | ||
vetRepository.deleteById(aLong); | ||
} | ||
} |