- O 프로그램 구조 분석
- 日常茶飯事
- 2009. 8. 27. 20:37
- do라는 확장자를 가진 요청이 들어오면 스트러츠(Struts2)에서 처리한다.
struts-xxx.xml
- 스트러츠 액션에서 서비스를 호출해서 사용하면 되는데 우리쪽에서는 모델1 방식이라서 jsp 를 직접 호출하게 되어 있다.
jsp 에서 서비스를 호출하는데 do라는 확장만 호출하게 되어 있는 구조라서 액션에서 편법을 사용했다. 1
그런데 BaseAction 에 페이징관련 메서드가 있는 이유를 모르겠다.
- DAO는 iBatis를 사용
예외처리가 세련되지 못함.
struts-xxx.xml
<action name="xxx_list" class="xxx.action.XxxAction" method="findList"> <result>/jsp/xxx/list.jsp</result> </action>xxx_list 라는 요청이 들어오면 xxx.action.XxxAction.findList() 가 호출되면 /jsp/xxx/list.jsp 로 이동하게 된다.
- 스트러츠 액션에서 서비스를 호출해서 사용하면 되는데 우리쪽에서는 모델1 방식이라서 jsp 를 직접 호출하게 되어 있다.
jsp 에서 서비스를 호출하는데 do라는 확장만 호출하게 되어 있는 구조라서 액션에서 편법을 사용했다. 1
public class XxxAction extends BaseAction(ActionSupport){ ... public String findList() throws Exception { return SUCCESS; } }/jsp/xxx/list.jsp 로 이동해서 서비스를 호출해서 데이터를 처리하는 방식을 사용했다.
그런데 BaseAction 에 페이징관련 메서드가 있는 이유를 모르겠다.
- DAO는 iBatis를 사용
예외처리가 세련되지 못함.
public class XxxServiceImpl implements XxxService{ private static XxxServiceImpl instance = new XxxServiceImpl(); public static XxxServiceImpl getInstance(){ return instance; } DaoManager daoManager = null; XxxDAO dao; private XxxServiceImpl(){ daoManager = DaoConfig.getDaoManager(); dao = (XxxDAO)daoManager.getDao(XxxDAO.class); } public List findList() throws Exception{ //Exception 을 안던지게 하도록 List list = null; try{ list = dao.getList(); } catch (DaoException de) { //여긴 없어도 될듯 log.error(de, de); throw de; } catch (Exception e) { log.error(e, e); throw e; } return list; } public int insert(XxxVO vo) throws Exception{ //음... int result = 1; try{ dao.insert(vo); //트랜잭션 처리를 하지 않아도 예외가 발생하면 Rollback된다. } catch (DaoException de) { result = 0; System.out.println("de="+de.toString()); } catch (Exception e) { result = 0; System.out.println("e="+e.toString()); } return result; } public String change(XxxVO vo, String state) throws Exception{ String err_msg = "FAIL"; try{ daoMgr.startTransaction(); //명시적인 트랜잭션 처리 err_msg = dao.update(vo); dao.insertState(vo, state); daoMgr.commitTransaction(); } catch (DaoException de) { log.error(de, de); throw de; } catch (Exception e) { log.error(e, e); throw e; }finally{ daoMgr.endTransaction(); } return err_msg; } ... }
public class XxxDAOImpl extends SqlMapDaoTemplate implements XxxDAO{ public XxxDAOImpl(DaoManager daoManager) { super(daoManager); } public List getList() throws DaoException{ //DaoException은 Runtime Exception이다. return (XxxVO) queryForObject("xxx.list"); } ... }- 일부 Ajax도 사용
- 그런데 jsp 에서 직접 서비스를 호출하는 것을 액션에서 처리하도록 수정하는데 얼마 안걸렸을거 같다. [본문으로]
Recent comment