Skip to content

Commit

Permalink
3장: 변하는 것과 변하지 않는 것 - DI적용을 위한 클라이언트/컨텍스트 분리
Browse files Browse the repository at this point in the history
전략을 유동적으로 주입할 수 있게 메소드로 분리하자.
deleteAll()메소드가 클라이언트 역할이 되고, 컨텍스트를 호출하는 책임을 맡게된다.
  • Loading branch information
kimdahyeee committed Mar 14, 2020
1 parent f65d162 commit 1eda4e0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/com/toby/tobyspring/user/dao/UserDao.java
Expand Up @@ -95,13 +95,17 @@ public int getCount() throws SQLException {
}

public void deleteAll() throws SQLException {
StatementStrategy statementStrategy = new DeleteAllStrategy();
this.jdbcContextWithStatementStrategy(statementStrategy);
}

public void jdbcContextWithStatementStrategy(StatementStrategy statementStrategy) throws SQLException {
Connection connection = null;
PreparedStatement preparedStatement = null;

try {
connection = dataSource.getConnection();

StatementStrategy statementStrategy = new DeleteAllStrategy();
preparedStatement = statementStrategy.makePreparedStatement(connection);

preparedStatement.executeUpdate();
Expand Down

0 comments on commit 1eda4e0

Please sign in to comment.