| jdbcTemplate | 참조할 jdbcTemplate service의 bean id | ||
| sqlRepository | 참조할 sqlLoader service의 bean id | ||
| lobHandler | 참조할 lobHandler service의 bean id |
| config:configuration | filename nullcheck | ||||
| filename | 테이블 매핑 정보와 사용할 쿼리문을 정의하고 있는 파일명을 지정하는 요소로 복수 지정 가능하다. filename 요소에 대한 지정은 절대 / 상대적인 파일 경로 지정 방법과 Classpath를 이용한 지정 방식의 2가지가 있다. Classpath를 이용하여 매핑 파일 정보를 지정하고자 할 경우 classpath:로 시작한다. | ||||
| nullcheck | 해당 DB Column의 값이 없는 경우, null value가 리턴되었을 때, 지정한 값으로 변환시켜준다. | ||||
| property | name="skiperror" | error 발생 시 skip 여부를 세팅한다. |
<bean name="sqlService" class="anyframe.core.query.impl.SQLServiceImpl"> <property name="jdbcTemplate"> <ref bean="pagingNamedParamJdbcTemplate"/> </property> <property name="lobHandler"> <ref bean="lobHandler"/> </property> <property name="sqlRepository"> <ref bean="sqlLoader"/> </property> </bean> <bean id="MIPSqlService" parent="txConfig"> <property name="target"> <bean class="anyframe.core.query.impl.mip.MIPSQLServiceImpl"> <property name="sqlService"> <ref bean="sqlService"/> </property> <property name="sqlRepository"> <ref bean="sqlLoader"/> </property> </bean> </property> <property name="proxyInterfaces" value="anyframe.core.query.MIPSQLService" /> </bean>
public class MiCategoryDispatchAction extends DefaultMIDispatchActionSupport {
public void selectCategoryList(ActionMapping mapping, PlatformRequest request,
VariableList inVl, DatasetList inDl, VariableList outVl,
DatasetList outDl) throws Exception {
MIPSQLService sqlService = (MIPSQLService)getService("MISQLService");
Dataset dsAccess = sqlService.search("getMiCategoryList", inVl);
outDl.addDataset("ds_access",dsAccess);
}
public void updateCategory(ActionMapping mapping, PlatformRequest request,
VariableList inVl, DatasetList inDl, VariableList outVl,
DatasetList outDl) throws Exception {
MIPSQLService sqlService = (MIPSQLService)getService("MISQLService");
Map sqlMap = new HashMap();
sqlMap.put(MIPSQLService.QUERY_INSERT, "insertCATEGORY_MI");
sqlMap.put(MIPSQLService.QUERY_UPDATE, "updateCATEGORY_MI");
sqlMap.put(MIPSQLService.QUERY_DELETE, "deleteCATEGORY_MI");
sqlService.update(sqlMap, inDl.getDataset("ds_input"), new MiActionCommand(){
public void postDelete(Dataset arg0, int arg1) {
}
public void postInsert(Dataset arg0, int arg1) {
}
public void postUpdate(Dataset arg0, int arg1) {
}
public void preDelete(Dataset ds, int index) {
}
public void preInsert(Dataset ds, int index) {
IIdGenerationService idGenerationService
= (IIdGenerationService)getService("idGenerationServiceCategory");
try {
String id = idGenerationService.getNextStringId();
Variant variant = new Variant();
variant.setObject(id);
ds.setColumn(index,"categoryNo", variant);
} catch (BaseException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public void preUpdate(Dataset arg0, int arg1) {
}});
}
}
사용method |
|||
| 조회시 | select | Dataset search(String queryId, VariableList variablelist) Dataset search(String queryId, Dataset dataset) |
Variable, Dataset 두 형태 모두 Argument로 가능 |
| 수정시 | update | void update(HashMap queryMap, Dataset dataset) | 전달하는 인자인 dataset에는 insert,update,delete하는 모든 record를 포함하고 있으며 insert,update,delete에 해당하는 query id를 각각 queryMap에 지정한다 |
<queryservice>
<queries>
<query id="findByPkCATEGORY_MI" isDynamic="true">
<statement>
SELECT
CATEGORY_NO, CATEGORY_NAME, CATEGORY_DESC, USE_YN, REG_ID,
REG_DATE, MODIFY_ID, MODIFY_DATE, FILE_REF_ID
FROM CATEGORY
WHERE CATEGORY_NO=:categoryNo
</statement>
<result class="anyframe.templates.emp.mi.category.service.MiCategoryVO"></result>
</query>
<query id="insertCATEGORY_MI" isDynamic="true">
<statement>
INSERT INTO CATEGORY
( CATEGORY_NO, CATEGORY_NAME, CATEGORY_DESC, USE_YN, REG_ID,
REG_DATE, MODIFY_ID, MODIFY_DATE, FILE_REF_ID )
VALUES ( :categoryNo, :categoryName, :categoryDesc, :useYn, :regId,
SYSDATE, :modifyId, SYSDATE, :fileRefId )
</statement>
</query>
<query id="updateCATEGORY_MI" isDynamic="true">
<statement>
UPDATE CATEGORY
SET CATEGORY_NAME=:categoryName, CATEGORY_DESC=:categoryDesc, USE_YN=:useYn,
REG_ID=:regId, REG_DATE=SYSDATE, MODIFY_ID=:modifyId, MODIFY_DATE=SYSDATE,
FILE_REF_ID=:fileRefId
WHERE CATEGORY_NO = :categoryNo
</statement>
</query>
<query id="deleteCATEGORY_MI" isDynamic="true">
<statement>
DELETE FROM CATEGORY
WHERE CATEGORY_NO=:categoryNo
</statement>
</query>
</queries>
</queryservice>
<bean name="sqlService" class="anyframe.core.query.impl.SQLServiceImpl"> <property name="jdbcTemplate"> <ref bean="pagingNamedParamJdbcTemplate"/> </property> <property name="lobHandler"> <ref bean="lobHandler"/> </property> <property name="sqlRepository"> <ref bean="sqlLoader"/> </property> </bean> <bean id="NitobiSQLService" parent="txConfig"> <property name="target"> <bean class="anyframe.core.query.impl.nitobi.NitobiSQLServiceImpl"> <property name="sqlService"> <ref bean="sqlService"/> </property> <property name="sqlRepository"> <ref bean="sqlLoader"/> </property> </bean> </property> <property name="proxyInterfaces" value="anyframe.core.query.NitobiSQLService" /> </bean>
public class AJAXGetCategoryAction extends CommonListAction{
public ActionForward selectCategoryList(ActionMapping mapping, ValueObject vo,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
/*
* LIVE SCROLLING 기능을 위한 PARAMETER를 SETTING
*/
CommonSearchVO searchVO = (CommonSearchVO)vo;
String startRecordIndexString = request.getParameter("StartRecordIndex");
String pageSizeString = request.getParameter("PageSize");
startRecordIndexString = (startRecordIndexString == null)
? "1":startRecordIndexString;
pageSizeString = (pageSizeString == null) ? "1":pageSizeString;
int startRecordIndex = new Integer(startRecordIndexString).intValue();
int pageSize = new Integer(pageSizeString).intValue();
if(request.getParameter("SortColumn") != null
&& !request.getParameter("SortColumn").equals("") ){
searchVO.setSortColumn(request.getParameter("SortColumn"));
searchVO.setSortDirection(request.getParameter("SortDirection"));
}
Map paramMap = new HashMap();
populateParameter(request, paramMap);
paramMap.put("vo", searchVO);
NitobiSQLService queryService = (NitobiSQLService) getService("NitobiSQLService");
GetHandler getHandler = queryService.search(getQueryId(mapping, vo, request, response),
paramMap,startRecordIndex,pageSize);
getHandler.writeToClient(response);
return null;
}
}
| UI component에서 호출할 때 | <ajax:grid gethandler="../../../AjaxGetCategoryList.do?method=selectCategoryList"> |
| struts-config.xml에서 action mapping시 | <action path="/AjaxGetCategoryList" type="com.sds.web.ajax.action.AjaxGetCategoryList"/> |
| query xml에서 실행query id | <query id="AjaxGetCategoryList"> |
public class AjaxSaveCategoryAction extends AbstractNitobiUpdateAction {
protected String getDeleteQueryID() {
return "deleteCATEGORY_Nitobi";
}
protected String getInsertQueryID() {
return "insertCATEGORY_Nitobi";
}
protected String getUpdateQueryID() {
return "updateCATEGORY_Nitobi";
}
protected NitobiActionCommand getActionCommand() {
IIdGenerationService idGenerationService
= (IIdGenerationService)getWebApplicationContext().getBean("idGenerationServiceAjaxCategory");
return new CategoryActionCommand(idGenerationService );
}
class CategoryActionCommand extends DefaultNitobiActionCommand{
final private IIdGenerationService idGenerationService;
CategoryActionCommand(IIdGenerationService idGenerationService){
this.idGenerationService = idGenerationService;
}
public void preInsert(Record record) {
String categoryNo = null;
try {
categoryNo = idGenerationService.getNextStringId();
record.setField("categoryNo", categoryNo);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
<queryservice>
<queries>
<query id="AjaxGetCategoryList" isDynamic="true">
<statement>
SELECT
CATEGORY_NO, CATEGORY_NAME, CATEGORY_DESC, USE_YN, REG_ID,
REG_DATE, MODIFY_ID, MODIFY_DATE, FILE_REF_ID
FROM CATEGORY
WHERE CATEGORY_NO=:vo.categoryNo
</statement>
<result class="anyframe.templates.emp.mi.category.service.MiCategoryVO"></result>
</query>
<query id="insertCATEGORY_Nitobi" isDynamic="true">
<statement>
INSERT INTO CATEGORY
( CATEGORY_NO, CATEGORY_NAME, CATEGORY_DESC, USE_YN, REG_ID,
REG_DATE, MODIFY_ID, MODIFY_DATE, FILE_REF_ID )
VALUES ( :vo.categoryNo, :vo.categoryName, :vo.categoryDesc, :vo.useYn,
:vo.regId, SYSDATE, :vo.modifyId, SYSDATE, :vo.fileRefId )
</statement>
</query>
<query id="updateCATEGORY_Nitobi" isDynamic="true">
<statement>
UPDATE CATEGORY
SET CATEGORY_NAME=:vo.categoryName, CATEGORY_DESC=:vo.categoryDesc,
USE_YN=:vo.useYn, REG_ID=:vo.regId, REG_DATE=SYSDATE, MODIFY_ID=:vo.modifyId,
MODIFY_DATE=SYSDATE, FILE_REF_ID=:vo.fileRefId
WHERE CATEGORY_NO = :vo.categoryNo
</statement>
</query>
<query id="deleteCATEGORY_Nitobi" isDynamic="true">
<statement>
DELETE FROM CATEGORY
WHERE CATEGORY_NO=:vo.categoryNo
</statement>
</query>
</queries>
</queryservice>