Successfully reported this slideshow.

01.egovFrame Training Book II


Published on

eGovFrame - Framework for e-government
Session 02

  • Be the first to comment

  • Be the first to like this

01.egovFrame Training Book II

  1. 1. eGovFrame Training Book II eGovFrame Center 2012
  2. 2. Table of contents I DI(Dependency Injection), IoC(Inversion of Control)II AOP (Aspect Oriented Programming)III MVC (Model, View, Controller) pattern conceptIV Programming Procedure based on eGovFrameV Common component concept Page l 2
  3. 3. DI(Dependency Injection), IoC(Inversion of Control) Composition of eGovFrameChange the flow of control between classes and reducing dependence(Easeof maintainability) public class MovieLister{ public void list() { MovieFinder finder = new MovieFinderImpl(); } } When change Impl class, need to change Lister as well public class MovieLister{ public void list() { MovieFinder finder = Assember.getBean("movieFinder"); } } Assembler manages dependency Page l 3
  4. 4. AOP (Aspect Oriented Programming)(1/2) Composition of eGovFrame AOP is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns. Separate add-on services (ex: logging, security, exception, etc) that are repeated in a number of biz logic code in an information system as Aspect. Make that a separate module and maintain a program with configuration files. When changes occur in additional functions(add-ons), simply by changing Aspect, the change can be reflected to the biz logic code and the maintenance of the code will be much easier. Improve readability as removing duplicated code in business logic. Page l 4
  5. 5. AOP (Aspect Oriented Programming)(2/2) Composition of eGovFrame Aspect: A modularization of a concern that cuts across multiple objects Join point: A point during the execution of a program, such as the execution of a method or the handling of an exception Advice: Action taken by an aspect at a particular join point Pointcut: A predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name) Weaving: Linking aspects with other application types or objects to create an advised object Core Concerns Core Concerns Crosscutting Module Concerns Module Credit Deposit Calculating Credit Transfer Weaving Security Transfer Withdraw interest Logging Deposit Cross Withdraw cutting Security LoggingConcerns Calculating Transaction interest [ Separating Aspect] [ Weaving] Page l 5
  6. 6. Object Relational Mapping(ORM) Composition of eGovFrameORM does not use SQL in source code, instead, directly maps java classes to thecolumns of the table or runs and handles SQL in the form of XML Full ORM (Hibernate) DB Column – Business Logic Business Logic Java Class Mapping JDBC JDBC SQL SQL MAP Business Logic (Process SQL in the form of XML) DataBase DataBase Java-Mapping Partial ORM (iBatis) Features General Development ORM based Need direct mapping java classes to the table Developers can be processed directly in terms of object- Apply Mapping columns oriented When SQL changes, directly modify source code Can be applied only with modifications of the mapping Flexibility and deploy information Mapping information, XML, etc can be applied in the form Standard Pattern No pattern of template DB Control Directly control DB In case of Mapping, direct control can be difficult Technology in use SQL Persistence framework (Hibernate, iBatis) Page l 6
  7. 7. Composition of eGovFrameSQL Map Implementation Code Example • Separate SQL from business logic • Provide simple transaction control (Provide declarative transaction) • Provide a familiar SQL-based ORM model Statement st = null; ResultSet rs = null; try { st = con.createStatement(); // Component StringBuffer query = new StringBuffer(); Separation of List result = business ISqlManagement.getList(“”,”value”) query.append("n SELECT A.CHKLST_NO, "); query.append("n A.EVALFL_CD, "); logic and S query.append("n FROM PR_EVALIT_MB A "); QL query.append("n WHERE A.CHKLST_NO = " + sChklstNo + " "); query.append("n ORDER BY EVALIT_NO enhance // SqlMap.xml productivity, <select id=“id” resultclass =“hmap”> rs = st.executeQuery(st.toString()); SELECT A.CHKLST_NO, A.EVALFL_CD FROM while( { maintainabilit PR_EVALIT_MB A WHERE A.CHKLST_NO = #value# ... y, and ORDER BY EVALIT_NO } reusability, </select> } finally { try {rs.close();} catch (Exception e) {} try {st.close();} catch (Exception e) {} } Page l 7
  8. 8. MVC (Model, View, Controller) pattern concept Composition of eGovFrame MVC is a software architecture, considered an architectural pattern used in software engineering. The MVC pattern isolates ‘domain logic’(the application logic for the user - model) from user interface (input and presentation - view), then the controller handles the input event from the user interface to process the request through the domain logic. It permits independent development, testing and maintenance of each. Especially, Spring MVC provides DispatcherServlet (*FrontController) that is designed to implement Presentation layer easier in MVC architecture Http Request DispatcherServlet Controller Http Response View Model [ Conceptual Sequence of MVC pattern with DispatcherServlet ] Page l 8
  9. 9. Spring MVC Architecture Composition of eGovFrameSprings Web MVC framework is designed around a DispatcherServlet thatdispatches requests to handlers, with configurable handler mappings, viewresolution. HandlerMapping Controller Request Model Request Contoller (Biz Model and Model and View Logic) View Request Dispatcher Servlet (Front Controller) Response Model and View View View Name Response DB View View Resolver (JSP) Page l 9
  10. 10. Programming Procedure based on eGovFrame (1/8) Programming Procedure Presentation Layer Business Layer Data Access Layer HandlerMapping Controller DAO Service Interface Spring Config.Request Dispatcher (ORM) Servlet SQL(XML) View ServiceImpl ViewResolver (JSP) Spring Config Spring Config DataBase (transaction) (datasource) Data Value Object Value Object Development Configuration Spring Module Page l 10
  11. 11. Programming Procedure based on eGovFrame (2/8) Programming ProcedureOutput Screen Page l 11
  12. 12. Programming Procedure based on eGovFrame (3/8) Programming ProcedureController : Receive a request and call a service(biz logic)Implement features such as data binding, forms processing, and muti-action, etc @Controller JSP Controller Service DAO @SessionAttributes(types=SampleVO.class) public class EgovSampleController { VO SQL /** SampleService */ @Resource(name = "sampleService") private EgovSampleService sampleService; /** * Inquire post list. (pageing) * @param searchVO - SampleDefaultVO * @param model * @return "/sample/egovSampleList" * @exception Exception */ @RequestMapping(value="/sample/") public String selectSampleList(@ModelAttribute("searchVO") SampleDefaultVO searchVO, ModelMap model) throws Exception { List sampleList = sampleService.selectSampleList(searchVO); model.addAttribute("resultList", sampleList); return "/sample/egovSampleList"; } } Page l 12
  13. 13. Programming Procedure based on eGovFrame (4/8) Programming ProcedureService : Interface that declares methods for business functions Service JSP Controller ServiceImpl DAO public interface EgovSampleService { VO SQL /** * Inquire post list. * @param searchVO – VO including search information * @return post list * @exception Exception */ List selectSampleList(SampleDefaultVO searchVO) throws Exception; } Page l 13
  14. 14. Programming Procedure based on eGovFrame (5/8) Programming ProcedureServiceImpl : Implementation class that implements methods that defined in aservice Service JSP Controller ServiceImpl DAO @Service("sampleService") public class EgovSampleServiceImpl extends AbstractServiceImpl implements VO SQL EgovSampleService { /** SampleDAO */ @Resource(name="sampleDAO") private SampleDAO sampleDAO; /** * Inquire post list. * @param searchVO - VO including search information * @return post list * @exception Exception */ public List selectSampleList(SampleDefaultVO searchVO) throws Exception { return sampleDAO.selectSampleList(searchVO); } } ※ Tip : In case of a ServiceImpl, AbstractServiceImpl must be extended Page l 14
  15. 15. Programming Procedure based on eGovFrame (6/8) Programming ProcedureDAO : Process data transaction (support iBatis connection) JSP Controller Service DAO @Repository("sampleDAO") public class SampleDAO extends EgovAbstractDAO { VO SQL /** * Inquire post list. * @param searchVO - VO including search information Call EgovAbstractDAO’s list method to run iBatis * @return post list Query ID * @exception Exception */ public list<SampleVO> selectSampleList(SampleVO vo) throws Exception { return list("sampleDAO.selectSampleList_D", vo); } ※ Tip : In case of a DAO, EgovAbsractDAO must be extended.Method Summaryint delete(java.lang.String queryId, java.lang.Object parameterObject) : Execute delete SQL insert(java.lang.String queryId, java.lang.Object parameterObject) : Execute Insert SQL mappingjava.util.List list(java.lang.String queryId, java.lang.Object parameterObject) : Execute list SQL mapping listWithPaging(java.lang.String queryId, java.lang.Object parameterObject, int pageIndex, int pageSize) : Execute sub rangejava.util.List list SQL mappingjava.lang.Object selectByPk(java.lang.String queryId, java.lang.Object parameterObject) : select one result by PK setSuperSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Execute configuration as receiving sqlMapClientvoid in the form of Annotation and calling setSqlMapClient method of super(SqlMapClientDaoSupport)int update(java.lang.String queryId, java.lang.Object parameterObject) : Execute update SQL mapping Page l 15
  16. 16. Programming Procedure based on eGovFrame (7/8) Programming ProcedureiBatis SQL Map : Define SQL execution query JSP Controller Service DAO <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-// SQL Map 2.0//EN" ""> VO SQL <sqlMap namespace="Sample"> <typeAlias alias="egovMap" type="egovframework.rte.psl.dataaccess.util.EgovMap"/> <typeAlias alias="searchVO" type="egovframework.rte.sample.service.SampleDefaultVO"/> <resultMap id="sample" class="egovframework.rte.sample.service.SampleVO"> <result property="id" column="id"/> <result property="name" column="name"/> <result property="description" column="description"/> <result property="useYn" column="use_yn"/> <result property="regUser" column="reg_user"/> </resultMap> <select id="sampleDAO.selectSampleList_D" parameterClass="searchVO" resultClass="egovMap“> SELECT ID, NAME, DESCRIPTION, USE_YN, REG_USER FROM SAMPLE WHERE 1=1 <isEqual prepend="AND" property="searchCondition" compareValue="0"> ID = #searchKeyword# </isEqual> <isEqual prepend="AND" property="searchCondition" compareValue="1"> NAME LIKE % || #searchKeyword# || % </isEqual> ORDER BY ID DESC LIMIT #recordCountPerPage# OFFSET #firstIndex# </select> </sqlMap> Page l 16
  17. 17. Programming Procedure based on eGovFrame (8/8) Programming ProcedureVO : The object used for the purpose of data transfer between objects JSP Controller Service DAO public class SampleVO extends SampleDefaultVO { private static final long serialVersionUID = 1753729060514530707L; VO SQL /** ID */ private String id; /** Name */ private String name; public String getId() { return id; } public void setId(String id) { = id; } public String getName() { return name; } public void setName(String name) { = name; } } Page l 17
  18. 18. Common ComponentsCommon component concept A collection of reusable common modules in developing applications for e-Government projects An software unit that can run itself Example - Notice board, log-in, string validation check, etc Page l 18
  19. 19. Page l 19