develog

template, callback 본문

Dev/Java

template, callback

냐옴 2013. 7. 17. 15:52

public class Service {


private Dao dao;

public void setDao(Dao dao) {

this.dao = dao;

}

private void template(IService service, Map<String, String> param) {

Connection conn = null;

try {

conn = ConnectionManager.getConnection();

service.invoke(conn, param);

} catch (Exception e) {

e.printStackTrace();

} finally {

ConnectionManager.closeConnection(conn);

}

}

    

    public void insertUser(String userSeq) {

Map<String, String> param = new HashMap<String, String>();

param.put("USER_SEQ", userSeq);

template(new IService() {

public void invoke(Connection conn, Map<String, String> param) throws Exception {

dao.insertUser(conn, param);

}

}, param);

}

}


interface IService {

public void invoke(Connection conn, Map<String, String> param) throws Exception;

}



'Dev > Java' 카테고리의 다른 글

REQUIRES_NEW  (0) 2013.07.18
jndi  (0) 2013.07.18
AsyncHttpClient  (0) 2013.07.11
StringBuilder, replace  (0) 2013.07.11
spring-test-dbunit  (0) 2013.07.09
Comments