이번글은 공식 문서에서 소개하는 Package Hierarchy에 대해 정리했습니다.
The Spring Framework’s JDBC abstraction framework consists of four different packages
Spring Framework의 JDBC 추상화 프레임워크는 네 개의 서로 다른 패키지로 구성됩니다.
core: The org.springframework.jdbc.core package contains the JdbcTemplate class and its various callback interfaces, plus a variety of related classes. A subpackage named org.springframework.jdbc.core.simple contains the SimpleJdbcInsert and SimpleJdbcCall classes. Another subpackage named org.springframework.jdbc.core.namedparam contains the NamedParameterJdbcTemplate class and the related support classes. See Using the JDBC Core Classes to Control Basic JDBC Processing and Error Handling, JDBC Batch Operations, and Simplifying JDBC Operations with the SimpleJdbc Classes.
org.springframework.jdbc.core 패키지는 JdbcTemplate 클래스와 다양한 콜백 인터페이스들, 그리고 여러 관련 클래스들을 포함합니다.
하위 패키지 org.springframework.jdbc.core.simple는 SimpleJdbcInsert와 SimpleJdbcCall 클래스를 포함하고,
또 다른 하위 패키지 org.springframework.jdbc.core.namedparam는 NamedParameterJdbcTemplate 클래스와 관련 지원 클래스들을 포함합니다.
관련 주제: 기본 JDBC 처리와 예외 처리 제어, JDBC 배치 작업, SimpleJdbc 클래스를 사용한 JDBC 작업 단순화
datasource: The org.springframework.jdbc.datasource package contains a utility class for easy DataSource access and various simple DataSource implementations that you can use for testing and running unmodified JDBC code outside of a Jakarta EE container. A subpackage named org.springframework.jdbc.datasource.embedded provides support for creating embedded databases by using Java database engines, such as HSQL, H2, and Derby. See Controlling Database Connections and Embedded Database Support.
org.springframework.jdbc.datasource 패키지는 DataSource에 쉽게 접근할 수 있도록 도와주는 유틸리티 클래스와
테스트 및 Jakarta EE 컨테이너 외부에서 수정 없이 JDBC 코드를 실행할 수 있도록 지원하는 간단한 DataSource 구현체들을 포함합니다.
하위 패키지 org.springframework.jdbc.datasource.embedded는 HSQL, H2, Derby 같은 Java 기반 데이터베이스 엔진을 이용해 내장 데이터베이스를 생성하는 기능을 지원합니다.
관련 주제: 데이터베이스 연결 제어, 내장 데이터베이스 지원
object: The org.springframework.jdbc.object package contains classes that represent RDBMS queries, updates, and stored procedures as thread-safe, reusable objects. See Modeling JDBC Operations as Java Objects. This style results in a more object-oriented approach, although objects returned by queries are naturally disconnected from the database. This higher-level of JDBC abstraction depends on the lower-level abstraction in the org.springframework.jdbc.core package.
org.springframework.jdbc.object 패키지는 RDBMS 쿼리, 업데이트, 저장 프로시저 등을 스레드에 안전하고 재사용 가능한 객체로 표현하는 클래스들을 제공합니다.
이 방식은 더 객체지향적인 접근 방식을 제공하지만, 쿼리로 반환된 객체들은 데이터베이스와는 자연스럽게 분리되어 있습니다.
이 고수준의 JDBC 추상화는 org.springframework.jdbc.core 패키지의 저수준 추상화에 기반합니다.
관련 주제: JDBC 작업을 자바 객체로 모델링하는 방식
support: The org.springframework.jdbc.support package provides SQLException translation functionality and some utility classes. Exceptions thrown during JDBC processing are translated to exceptions defined in the org.springframework.dao package. This means that code using the Spring JDBC abstraction layer does not need to implement JDBC or RDBMS-specific error handling. All translated exceptions are unchecked, which gives you the option of catching the exceptions from which you can recover while letting other exceptions be propagated to the caller. See Using SQLExceptionTranslator.
org.springframework.jdbc.support 패키지는 SQLException을 변환해주는 기능과 몇 가지 유틸리티 클래스를 제공합니다.
JDBC 처리 중 발생한 예외들은 org.springframework.dao 패키지에 정의된 예외들로 변환됩니다.
따라서 Spring JDBC 추상화를 사용하는 코드는 JDBC 또는 DB 특화된 예외 처리를 따로 구현하지 않아도 됩니다.
변환된 예외는 모두 언체크 예외이므로, 복구할 수 있는 예외만 직접 처리하고, 그 외에는 호출자에게 전파시킬 수 있습니다.
관련 주제: SQLExceptionTranslator 사용법
1. core 패키지
핵심 기능을 담고 있습니다.
JdbcTemplate, NamedParameterJdbcTemplate, SimpleJdbcInsert, SimpleJdbcCall 등을 제공합니다.
JDBC 코드 작성 시 반복되는 작업을 줄여줍니다.
SQL 실행, 파라미터 바인딩, 결과 매핑 등을 간편하게 처리할 수 있게 도와줍니다.
2. datasource 패키지
DataSource 관련 유틸리티 제공합니다.
테스트용 간단한 DataSource 구현체 포함합니다.
H2, HSQL, Derby 같은 내장형 데이터베이스 지원 기능도 있습니다.
Jakarta EE 환경 없이도 JDBC 테스트 가능하게 해줍니다.
3. object 패키지
SQL 쿼리, 업데이트, 저장 프로시저 등을 자바 객체로 표현합니다.
SqlQuery, SqlUpdate, StoredProcedure 등 제공합니다.
객체지향적으로 SQL 작업을 재사용하고 구성할 수 있게 해줍니다.
4. support 패키지
SQLException을 Spring의 DataAccessException으로 변환합니다.
DB 종류마다 다른 오류를 일관된 예외로 처리할 수 있게 합니다.
모든 예외는 unchecked 예외라서 복구 가능한 예외만 골라서 처리 가능합니다.
정리
- core: JDBC 작업을 간편하게 만들어주는 핵심 기능 제공합니다.
- datasource: DB 연결과 테스트 환경 지원합니다.
- object: SQL을 객체처럼 다루고 재사용할 수 있게 도와줍니다.
- support: 예외 처리 단순화, 일관성 있게 예외 변환합니다.
'공식문서' 카테고리의 다른 글
[Spring Docs] Using the JDBC Core Classes to Control Basic JDBC Processing and Error Handling #2 (0) | 2025.03.30 |
---|---|
[Spring Docs] Using the JDBC Core Classes to Control Basic JDBC Processing and Error Handling #1 (0) | 2025.03.28 |
[Spring Docs] Choosing an Approach for JDBC Database Access (0) | 2025.03.26 |
[Spring Docs] DAO Support (0) | 2025.03.25 |
Garbage Collector #3 (0) | 2025.03.24 |