====== Springframework JDBC ====== * [[springframework:embeddeddatasource|Spring Framework Embedded DataSource]] * [[http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.html|ResourceDatabasePopulator]] DB에 초기 데이터를 적재하는 스크립트 로더. * [[http://www.baeldung.com/spring-jdbc-jdbctemplate|Spring JDBC Tutorial]] ===== Stored Procedure ===== * [[https://lalitjc.wordpress.com/2013/07/02/different-ways-of-calling-stored-procedure-using-spring/|Different ways of calling stored procedure using spring]] ===== NamedParameterJdbcTemplate ===== * [[https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.html|NamedParameterJdbcTemplate]] * '':paramName'' 방식으로 파라미터 바인딩 가능 * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/SqlParameterSource.html|SqlParameterSource]]를 통해 파라미터 저장 * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.html|MapSqlParameterSource]] * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.html|BeanPropertySqlParameterSource]] : 일반 Java Bean의 프라퍼티명을 통해 파라미터 지정 가능. ===== RowMapper ===== * [[https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/RowMapper.html|RowMapper]] : 쿼리 결과를 Java 객체로 생성하는 매핑 규칙 ==== BeanPropertyRowMapper ==== * [[https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/BeanPropertyRowMapper.html|BeanPropertyRowMapper]] * Java Bean property 이름과 컬럼 이름을 매핑 var rowMapper = BeanPropertyRowMapper.newInstance(Country.class); * 한번 초기화 되면 Thread safe 하게 사용가능하다.(억지로 값을 설정하지만 않으면 됨) * [[https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/convert/ConversionService.html|ConversionService]] 지정을 통해 프라퍼티 타입 확장 가능. * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/convert/support/DefaultConversionService.html|DefaultConversionService]] : 기본값 * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/format/support/DefaultFormattingConversionService.html|DefaultFormattingConversionService]] ===== DatabasePopulator ===== * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/datasource/init/DatabasePopulator.html|DatabasePopulator]] * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.html|ResourceDatabasePopulator]] * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.html|DatabasePopulatorUtils]] * ''DataSource''를 지정하여 자동으로 SQL을 실행해준다. * [[http://www.javased.com/index.php?api=org.springframework.jdbc.datasource.init.ResourceDatabasePopulator|Java Code Examples of org.springframework.jdbc.datasource.init.ResourceDatabasePopulator]] ResourceDatabasePopulator populator=new ResourceDatabasePopulator(); populator.setScripts(new Resource[]{new ClassPathResource(SQL_FILE)}); // populator.initialize()를 호출해도 됨. DatabasePopulatorUtils.execute(populator,dataSource); ===== DataSourceInitializer ===== * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/datasource/init/DataSourceInitializer.html|DataSourceInitializer]] * ''DatabasePopulator''와의 조합으로 애플리케이션이 뜰 때 초기화와 종료시 클렌징을 할 수 있다.