SSAFY11th-book-study / book-study

0 stars 0 forks source link

[5.2.3] 트랜잭션 동기화 방식에서의 트랜잭션 식별 #51

Open hj-k66 opened 4 months ago

hj-k66 commented 4 months ago

363p에서 (3) 첫 번째 update() 메소드가 호출되고, update() 메소드 내부에서 이용하는 JdbcTemplate 메소드에서는 가장 먼저 (4) 트랜잭션 동기화 저장소에 현재 시작된 트랜잭션을 가진 Connection 오브젝트가 존재하는지 확인한다고 하는데,

어떻게 트랜잭션 식별하는지 궁금합니다.

limjongheok commented 4 months ago
  1. DataSourceUtils.getConnection(dataSouces) ; : Connection이 연결되어 있음 ConnectionHolder에서 찾아 가져오거나 없으면 새로 만들어 Connection image

image

그렇다면 update 쿼리를 날리는 update() 메서드 속에서도 DBUtiles.getConnection을 이용하여 ConnectionHolder 에서Connection을 찾아 쿼리를 작성하고 다시 service 서 commit 을 할시 쿼리가 db로 전송 된다 생각합니다.

gmelon commented 4 months ago

JdbcTemplate의 execute 메서드에서 DataSourceUtils.getConnection()을 통해 Connection을 얻음

image

따라서, 클라이언트에서 생성해 등록한 Connection이 있다면 그걸 사용하고(트랜잭션 유지), 없다면 바로 생성해서 사용