Download presentation
Presentation is loading. Please wait.
1
Spring 프레임워크의 이해 5. Spring Abstract API
2
Spring JDBC를 이용할 때 개발자들이 구현할 부분
Spring – Abstract API Spring JDBC를 이용할 때 개발자들이 구현할 부분 작업 Spring JDBC 개발자 Connection 관리 O X SQL Statement 관리 ResultSet 관리 Row 데이터 추출 패러미터 선언 패러미터 Setting 트랜잭션 관리
3
Template Method Pattern
Spring – Abstract API Template Method Pattern
4
Spring – Abstract API
5
Spring – Abstract API public abstract class AbstractClass {
public void templateMethod() { // .. 비지니스 로직 구현 operation1(); operation2(); } protected abstract void operation1(); protected abstract void operation2();
6
Spring – Abstract API public class ConcreteClassA extends AbstractClass { protected void operation1() { // TODO Auto-generated method stub } protected void operation2() {
7
Spring – Abstract API Template Method = IoC
8
Callback Class Callback Method
Spring – Abstract API Callback Class Callback Method
9
Spring – Abstract API public interface RowCallbackHandler { void processRow(ResultSet rs) throws SQLException; }
10
Spring – Abstract API public void query(String sql, RowCallbackHandler callbackHandler) throws JdbcSqlException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = <code to get connection> ps = con.prepareStatement (sql); rs = ps.executeQuery(); while (rs.next()) { callbackHandler.processRow(rs); } rs.close(); ps.close(); } catch (SQLException ex) { throw new JdbcSqlException("Couldn't run query [" + sql + "]", ex); finally { DataSourceUtils.closeConnectionIfNecessary(this.dataSource, con);
11
Spring – Abstract API class StringHandler implements JdbcTemplate.RowCallbackHandler { private List 1 = new LinkedList(); public void processRow(ResultSet rs)throws SQLException { 1.add(rs.getString(1)); } public String[] getStrings() { return (String[]) 1.toArray(new String[1.size()]); StringHandler sh = new StringHandler(); jdbcTemplate.query("SELECT FORENAME FROM CUSTMR", sh); String[] forenames = sh.getStrings();
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.