-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week9][Chap3] Feat : 순수 JPA 기반 리포지토리 (#108)
- Loading branch information
1 parent
c0f52d4
commit 2a8b3c5
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
...ring_data_jpa_jinu/data-jpa/src/main/java/study/datajpa/repository/TeamJpaRepository.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,42 @@ | ||
package study.datajpa.repository; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import study.datajpa.entity.Member; | ||
import study.datajpa.entity.Team; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public class TeamJpaRepository { | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
|
||
public Team save(Team team){ | ||
em.persist(team); | ||
return team; | ||
} | ||
|
||
public void delete(Team team){ | ||
em.remove(team); | ||
} | ||
|
||
public List<Team> findAll(){ | ||
return em.createQuery("select t from Team t",Team.class).getResultList(); | ||
} | ||
|
||
public Optional<Team> findById(Long id){ | ||
Team team=em.find(Team.class,id); | ||
return Optional.ofNullable(team); | ||
} | ||
|
||
public long count(){ | ||
return em.createQuery("select count(t) from Team t",Long.class).getSingleResult(); | ||
} | ||
|
||
|
||
} |
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