Date post: | 19-May-2015 |
Category: |
Documents |
Upload: | chuong-nguyen |
View: | 1,220 times |
Download: | 0 times |
eGovFrame Training Book II
eGovFrame Center
2012
Table of contents
DI(Dependency Injection), IoC(Inversion of Control)
AOP (Aspect Oriented Programming)
MVC (Model, View, Controller) pattern concept
Programming Procedure based on eGovFrame
Common component concept
Page l 2
I
II
III
IV
V
Page l 3
DI(Dependency Injection), IoC(Inversion of Control)
public class MovieLister{
public void list() {
MovieFinder finder = new MovieFinderImpl();
}
}
public class MovieLister{
public void list() {
MovieFinder finder = Assember.getBean("movieFinder");
}
}
Change the flow of control between classes and reducing dependence(Ease
of maintainability)
When change Impl class, need to change Lister as well
Assembler manages dependency
Composition of eGovFrame
Page l 4
AOP (Aspect Oriented Programming)(1/2)
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.
Composition of eGovFrame
Page l 5
AOP (Aspect Oriented Programming)(2/2) Composition of eGovFrame
[ Separating Aspect] [ Weaving]
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
Credit
Transfer
Deposit
Withdraw
Calculating
interest
Logging
Security
Transaction
Core Concerns
Cross
cutting
Concerns
Core Concerns
Module
Calculating
interest
Deposit
Withdraw
Credit
Transfer
Crosscutting
Concerns Module
Logging
SecurityWeaving
Page l 6
Object Relational Mapping(ORM)
Features General Development ORM based
Apply MappingNeed direct mapping java classes to the table
columns
Developers can be processed directly in terms of object-
oriented
FlexibilityWhen SQL changes, directly modify source code
and deploy
Can be applied only with modifications of the mapping
information
Standard Pattern No patternMapping information, XML, etc can be applied in the form
of template
DB Control Directly control DB In case of Mapping, direct control can be difficult
Technology in use SQL Persistence framework (Hibernate, iBatis)
Composition of eGovFrame
SQL
Java-Mapping
Business LogicBusiness Logic
DB Column –
Java Class
Mapping
JDBC
DataBase
JDBC
DataBaseBusiness Logic
SQL MAP
(Process SQL in
the form of XML)
Full ORM (Hibernate)
Partial ORM (iBatis)
ORM does not use SQL in source code, instead, directly maps java classes to the
columns of the table or runs and handles SQL in the form of XML
Page l 7
SQL 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();
StringBuffer query = new StringBuffer();
query.append("\n SELECT A.CHKLST_NO, ");
query.append("\n A.EVALFL_CD, ");
query.append("\n FROM PR_EVALIT_MB A ");
query.append("\n WHERE A.CHKLST_NO = '"
+ sChklstNo + "' ");
query.append("\n ORDER BY EVALIT_NO
rs = st.executeQuery(st.toString());
while(rs.next) {
...
}
} finally {
try {rs.close();} catch (Exception e) {}
try {st.close();} catch (Exception e) {}
}
// Component
List result =
ISqlManagement.getList(“sql.id”,”value”)
// SqlMap.xml
<select id=“id” resultclass =“hmap”>
SELECT A.CHKLST_NO, A.EVALFL_CD FROM
PR_EVALIT_MB A WHERE A.CHKLST_NO = #value#
ORDER BY EVALIT_NO
</select>
Separation of
business
logic and S
QL
enhance
productivity,
maintainabilit
y, and
reusability,
Composition of eGovFrame
Page l 8
MVC (Model, View, Controller) pattern concept
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
Composition of eGovFrame
DispatcherServlet Controller
Http Request
Http Response
ModelView
[ Conceptual Sequence of MVC pattern with DispatcherServlet ]
Page l 9
Spring MVC Architecture Composition of eGovFrame
View
(JSP)
Controller
Model(Biz
Logic)
Dispatcher Servlet
(Front Controller)
DB
Model and
View
HandlerMapping
View
Resolver
Request
Response
RequestContoller
Request
View NameView Response
Model and
View
Model and
View
Spring's Web MVC framework is designed around a DispatcherServlet that
dispatches requests to handlers, with configurable handler mappings, view
resolution.
Page l 10
Programming Procedure based on eGovFrame (1/8)
Presentation Layer Business Layer Data Access Layer
View(JSP)
Dispatcher
Servlet
Controller
Service Interface
ServiceImpl
DAO
DataBase
Request
SQL(XML)
Development Configuration
HandlerMapping
ViewResolver
Spring Config(transaction)
Spring Config(datasource)
Spring Config.
(ORM)
Data Value Object Value Object
Programming Procedure
Spring Module
Page l 11
Output Screen
Programming Procedure based on eGovFrame (2/8) Programming Procedure
Page l 12
Controller : Receive a request and call a service(biz logic)
Implement features such as data binding, forms processing, and muti-action, etc
@Controller@SessionAttributes(types=SampleVO.class)public class EgovSampleController {
/** SampleService */@Resource(name = "sampleService")private EgovSampleService sampleService;
/*** Inquire post list. (pageing)* @param searchVO - SampleDefaultVO* @param model* @return "/sample/egovSampleList"* @exception Exception*/
@RequestMapping(value="/sample/egovSampleList.do")public String selectSampleList(@ModelAttribute("searchVO") SampleDefaultVO searchVO,
ModelMap model) throws Exception {
List sampleList = sampleService.selectSampleList(searchVO);model.addAttribute("resultList", sampleList);
return "/sample/egovSampleList";}
}
JSP Controller Service DAO
VO SQL
Programming ProcedureProgramming Procedure based on eGovFrame (3/8)
Page l 13
Service : Interface that declares methods for business functions
public interface EgovSampleService {
/**
* Inquire post list.
* @param searchVO – VO including search information
* @return post list
* @exception Exception
*/
List selectSampleList(SampleDefaultVO searchVO) throws Exception;
}
JSP Controller ServiceImpl DAO
VO SQL
Service
Programming ProcedureProgramming Procedure based on eGovFrame (4/8)
Page l 14
ServiceImpl : Implementation class that implements methods that defined in a
service
@Service("sampleService")
public class EgovSampleServiceImpl extends AbstractServiceImpl implements
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
JSP Controller ServiceImpl DAO
VO SQL
Service
Programming ProcedureProgramming Procedure based on eGovFrame (5/8)
Page l 15
DAO : Process data transaction (support iBatis connection)
@Repository("sampleDAO")
public class SampleDAO extends EgovAbstractDAO {
/**
* Inquire post list.
* @param searchVO - VO including search information
* @return post list
* @exception Exception
*/
public list<SampleVO> selectSampleList(SampleVO vo) throws Exception {
return list("sampleDAO.selectSampleList_D", vo);
}
Call EgovAbstractDAO’s list method to run iBatis
Query ID
JSP Controller Service DAO
VO SQL
※ Tip : In case of a DAO, EgovAbsractDAO must be extended.
Programming ProcedureProgramming Procedure based on eGovFrame (6/8)
Method Summary
int delete(java.lang.String queryId, java.lang.Object parameterObject) : Execute delete SQL mapping.
java.lang.Object insert(java.lang.String queryId, java.lang.Object parameterObject) : Execute Insert SQL mapping
java.util.List list(java.lang.String queryId, java.lang.Object parameterObject) : Execute list SQL mapping
java.util.ListlistWithPaging(java.lang.String queryId, java.lang.Object parameterObject, int pageIndex, int pageSize) : Execute sub range list SQL mapping
java.lang.Object selectByPk(java.lang.String queryId, java.lang.Object parameterObject) : select one result by PK
voidsetSuperSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Execute configuration as receiving sqlMapClientin 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 16
iBatis SQL Map : Define SQL execution query
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<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“>SELECTID, NAME, DESCRIPTION, USE_YN, REG_USERFROM SAMPLEWHERE 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 DESCLIMIT #recordCountPerPage# OFFSET #firstIndex#</select>
</sqlMap>
JSP Controller Service DAO
VO SQL
Programming ProcedureProgramming Procedure based on eGovFrame (7/8)
Page l 17
VO : The object used for the purpose of data transfer between objects
public class SampleVO extends SampleDefaultVO {
private static final long serialVersionUID = 1753729060514530707L;
/** ID */private String id;
/** Name */private String name;
public String getId() {return id;}
public void setId(String id) {this.id = id;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
}
JSP Controller Service DAO
VO SQL
Programming ProcedureProgramming Procedure based on eGovFrame (8/8)
Page l 18
Common 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
Common Components