JunsuLime / spring-cloud-native-explorer

Spring cloud explorer
1 stars 0 forks source link

Spring의 JdbcTemplate 을 사용해보자. #31

Closed JunsuLime closed 2 years ago

JunsuLime commented 2 years ago

Spring Data JDBC 는 기능 상 이런 일을 하는 친구이다.

This module deals with enhanced support for JDBC based data access layers. It makes it easier to build Spring powered applications that use data access technologies.

This makes Spring Data JDBC a simple, limited, opinionated ORM.

이 친구가 중요하게 생각하는 개념은 Aggregate Root 이다.

One consequence of this is that you should have a repository per Aggregate Root. Aggregate Root 당 하나의 repository 가 있는 것을 의도했으며 여기서 언급한 Aggregate Root 는 DDD 의 개념이다.

https://martinfowler.com/bliki/DDD_Aggregate.html

Features

[Reference] https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.repositories

JunsuLime commented 2 years ago

잠깐!! JDBC 란 무엇인가?

JDBC(Java Database Connectivity)는 자바에서 데이터베이스에 접속할 수 있도록 하는 자바 API이다. JDBC는 데이터베이스에서 자료를 쿼리하거나 업데이트하는 방법을 제공한다.

Aggregate Root 당 하나의 Repository 가 생성됨을 기대하며, 한 Repository 의 (마저 채우자)

JunsuLime commented 2 years ago

======================================= 음 위에서 확인했던 내용은 spring-data 의 jdbc repository 에 대한 내용이었다. (ORM 관련된 내용) 내가 원한 내용은 쿼리만 알면 사용할 수 있을 정도인 기본적인 내용이었다.

https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#jdbc

이를 참고해서 마저 공부를 해보자.

JunsuLime commented 2 years ago

https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#jdbc-JdbcTemplate 이를 참고해서 사용해보자.

spring boot 에서는 jdbctemplate, namedParameterJdbcTemplate 을 auto-configure 해주기 때문에 별도 생성이 필요 없다 (이미 bean 으로 등록 되어있다.)

JunsuLime commented 2 years ago

SQLExceptionTranslator

SQLExceptionTranslator is an interface to be implemented by classes that can translate between SQLExceptions and Spring’s own org.springframework.dao.DataAccessException, which is agnostic in regard to data access strategy.

요 친구는 vendor 의 exception 의 spring exception 으로 변환해주는 (번역해주는) 역할을 한다. exception 발생시 참고해보도록 하자.

확인하고 싶은 내용들

필요한 기능 만들면서 사용했던 친구들

JunsuLime commented 2 years ago

Specificiation 을 적절하게 쿼리 메서드에 적용하는 방법을 공부 후 다시 보자