5.spring Abstract Api

  • Uploaded by: Taekyu Park
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 5.spring Abstract Api as PDF for free.

More details

  • Words: 351
  • Pages: 11
Spring 프레임워크의 이해

5. Spring Abstract API

2007 Grow up to be NHN

Spring – Abstract API

Spring JDBC 를 이용할 때 개발 자들이 구현 할 부분 작업

Spring JDBC

개발자

Connection 관리

O

X

SQL

X

O

Statement 관리

O

X

ResultSet 관리

O

X

Row 데이터 추출

X

O

패러미터 선언

X

O

패러미터 Setting

O

X

트랜잭션 관리

O

X



2007 Grow up to be NHN

Spring – Abstract API

Template Method Pattern



Spring – Abstract API

2007 Grow up to be NHN



2007 Grow up to be NHN

Spring – Abstract API

public abstract class AbstractClass { public void templateMethod() { // .. 비지니스 로직 구현 operation1(); // .. 비지니스 로직 구현 operation2(); } protected abstract void operation1(); protected abstract void operation2(); }



Spring – Abstract API

2007 Grow up to be NHN

public class ConcreteClassA extends AbstractClass { protected void operation1() { // TODO Auto-generated method stub } protected void operation2() { // TODO Auto-generated method stub } }



Spring – Abstract API

2007 Grow up to be NHN

Template Method = IoC



2007 Grow up to be NHN

Spring – Abstract API

Callback Class

Callback Method



Spring – Abstract API

2007 Grow up to be NHN

public interface RowCallbackHandler { void processRow(ResultSet rs) throws SQLException; }



Spring – Abstract API

2007 Grow up to be NHN

public void query(String sql, RowCallbackHandler callbackHandler) throws JdbcSqlException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = 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); } }



Spring – Abstract API

2007 Grow up to be NHN

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();


Related Documents

5.spring Abstract Api
April 2020 9
Api
April 2020 43
Api
July 2020 25
Api
November 2019 64
Api
November 2019 62
Api
July 2020 32

More Documents from ""

Admin
May 2020 26
Admin_en
May 2020 8
5.spring Abstract Api
April 2020 9
Txt.docx
April 2020 2
Frfis 2.pptx
May 2020 9