Sie sind auf Seite 1von 19

eGovFrame Training Book II

eGovFrame Center
2012

Table of contents
I

DI(Dependency Injection), IoC(Inversion of Control)

II

AOP (Aspect Oriented Programming)

III

MVC (Model, View, Controller) pattern concept

IV

Programming Procedure based on eGovFrame

Common component concept

Page l

DI(Dependency Injection), IoC(Inversion of Control)

Composition of eGovFrame

Change the flow of control between classes and reducing dependence(Ease


of 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

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

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

Credit
Transfer

Deposit
Withdraw

Logging

Cross
cutting
Concerns

Core Concerns
Module
Calculating
interest

Credit
Transfer

Crosscutting
Concerns Module

Weaving

Security

Deposit
Withdraw

Security

Logging
Calculating
interest

Transaction

[ Separating Aspect]

[ Weaving]

Page l

Composition of eGovFrame

Object Relational Mapping(ORM)

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
Full ORM (Hibernate)
Business Logic

JDBC

Business Logic

DB Column
Java Class
Mapping
JDBC

SQL
Business Logic
Java-Mapping

DataBase

SQL MAP
(Process SQL in
the form of XML)

DataBase

Partial ORM (iBatis)


Features
Apply Mapping
Flexibility
Standard Pattern
DB Control

Technology in use

General Development
Need direct mapping java classes to the table
columns
When SQL changes, directly modify source code
and deploy
No pattern

ORM based
Developers can be processed directly in terms of objectoriented
Can be applied only with modifications of the mapping
information
Mapping information, XML, etc can be applied in the form
of template

Directly control DB

In case of Mapping, direct control can be difficult

SQL

Persistence framework (Hibernate, iBatis)

Page l

SQL Map Implementation Code Example

Composition of eGovFrame

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) {
...
}

Separation of
business
logic and S
QL
enhance
productivity,
maintainabilit
y, and
reusability,

// 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>

} finally {
try {rs.close();} catch (Exception e) {}
try {st.close();} catch (Exception e) {}
}

Page l

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

View

Model

Http Response

[ Conceptual Sequence of MVC pattern with DispatcherServlet ]


Page l

Composition of eGovFrame

Spring MVC Architecture

Spring's Web MVC framework is designed around a DispatcherServlet that


dispatches requests to handlers, with configurable handler mappings, view
resolution.

HandlerMapping

Controller
Request

Request
Request

Model

Contoller
Model and
View

Model and
View

(Biz
Logic)

Dispatcher Servlet
(Front Controller)

Response

Model and
View
View View Name

View
Resolver

Response

DB

View
(JSP)

Page l

Programming Procedure
Presentation Layer

HandlerMapping

based on eGovFrame (1/8)

Business Layer

Programming Procedure

Data Access Layer

Controller
DAO
Spring Config.

Service Interface

Dispatcher

Request

(ORM)

Servlet

SQL(XML)
View
(JSP)

ServiceImpl

ViewResolver

Spring Config
(transaction)

Data

Spring Config
(datasource)

Value Object
Development

DataBase

Value Object
Configuration

Spring Module

Page l

10

Programming Procedure

based on eGovFrame (2/8)

Programming Procedure

Output Screen

Page l

11

Programming Procedure

based on eGovFrame (3/8)

Programming Procedure

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 {

JSP

Controller

Service

DAO

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/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";
}
}

Page l

12

Programming Procedure

Programming Procedure

based on eGovFrame (4/8)

Service : Interface that declares methods for business functions


Service
JSP

Controller

ServiceImpl

DAO

VO

SQL

public interface EgovSampleService {


/**
* Inquire post list.
* @param searchVO VO including search information
* @return post list
* @exception Exception
*/
List selectSampleList(SampleDefaultVO searchVO) throws Exception;
}

Page l

13

Programming Procedure

based on eGovFrame (5/8)

Programming Procedure

ServiceImpl : Implementation class that implements methods that defined in a


service
Service
JSP

Controller

@Service("sampleService")
public class EgovSampleServiceImpl extends AbstractServiceImpl implements
EgovSampleService {

ServiceImpl

DAO

VO

SQL

/** 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

Programming Procedure

based on eGovFrame (6/8)

Programming Procedure

DAO : Process data transaction (support iBatis connection)


JSP

Controller

Service

DAO

VO

SQL

@Repository("sampleDAO")
public class SampleDAO extends EgovAbstractDAO {

/**
* Inquire post list.
Call EgovAbstractDAOs list method to run iBatis
* @param searchVO - VO including search information
Query ID
* @return post list
* @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 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.List

listWithPaging(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

void

setSuperSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Execute configuration as receiving sqlMapClient


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

Programming Procedure

based on eGovFrame (7/8)

Programming Procedure

iBatis SQL Map : Define SQL execution query


JSP

Controller

<?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">

Service

DAO

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

Programming Procedure

based on eGovFrame (8/8)

Programming Procedure

VO : The object used for the purpose of data transfer between objects
JSP

Controller

Service

DAO

VO

SQL

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;
}
}

Page l

17

Common component concept

Common Components

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

Page l

19

Das könnte Ihnen auch gefallen