DB 테이블을 수정하는 모델 개발하기

개요

DB의 테이블을 수정하는 모델을 개발하기 위해선 DB Modify Invoke를 이용하여 개발합니다.

본 장에서는 X-UP 빌더를 이용하여 DB 테이블을 수정하는 X-UP 모델을 생성하고 X-UP 서버로 배포 한 뒤 Nexacro-Studio에서 해당 모델을 사용하는 방법에 대해 설명합니다.

본 문서는 동영상을 기반으로 작성되었습니다.

필요 사항

해당 장에서 사용되는 'EMP' 테이블의 데이터를 조회하는 'SearchEmployees' 모델은 이미 서버에 배포되어 있습니다. (DB 테이블을 조회하는 모델 개발하기)

DB 테이블을 수정하는 모델 개발하기

DB 테이블을 수정하는 X-UP 모델을 개발하고 Nexacro 어플리케이션과 연동하기 위해선 다음과 같이 개발을 수행합니다.

도메인 개발하기

DB 테이블을 수정하기 위한 도메인 개발은 다음과 같은 절차로 이루어집니다.

1도메인 생성하기

2DB 데이터소스 생성하기

3DB 데이터 조회 모델 개발하기 (Skip)

4DB 데이터 수정 모델 개발하기

5Jetty Web Server 구동하기

6Jetty Web Server에 올라간 모델 테스트하기

Modify Invoke를 이용한 도메인 개발하기

Nexacro 어플리케이션에서 X-UP 모델 호출하기

X-UP에서 만들어진 도메인을 사용하기 위해서 Nexacro 어플리케이션에서는 다음과 같은 순서로 진행됩니다.

1TypeDefinition Service 등록하기

2모델 리스트와 인터페이스 가져오기

3모델 호출 스크립트 작성하기

4테스트 하기

Nexacro 어플리케이션에서 X-UP 모델 호출하기

Nexacro 어플리케이션 Sample download

Review

도메인 개발하기

X-UP에서 모델을 개발하기 위해 Java의 Project와 같은 도메인을 생성합니다.

도메인 생성하기

'NexawebInc'라는 도메인을 생성합니다.

DB 데이터소스 생성하기

DBMS와 연결을 맺기 위한 데이터소스(Legacy 연결 설정정보)를 생성합니다.

데이터소스는 도메인 별 생성되며, 모델내의 Invoke에서 사용하게 됩니다.

데이터소스 명칭은 'DB_ORACLE'을 입력하고 환경에 맞는 데이터소스 설정 정보를 입력합니다.

도메인의 mashup.msh 파일내의 DataSources 탭에서 생성합니다.

DB 데이터 조회 모델 개발하기

DB 데이터 조회 모델을 개발하기 위해 DB Select Invoke를 이용한 모델 개발하기DB 데이터 조회 모델 개발하기를 참고 합니다. 'SearchEmployees' 모델

이미 숙지하고 있는 경우 Skip 하며, 동영상에서도 마찬가지로 Skip 된다.

DB 데이터 수정 모델 개발하기

'DB_ORACLE' 데이터소스에 정의된 설정정보를 토대로 DB Modify Invoke를 이용해 'EMP' 테이블을 수정하는 모델을 개발한다.

DB Modify Invoke : DBMS로부터 쿼리를 이용하여 데이터를 수정하는 모듈

'ModifyEmployees' 모델을 생성하고 'EMP' 테이블에 insert, update, delete 쿼리를 수행하기 위해 Modify Invoke를 생성합니다.

생성 된 Modify Invoke는 'EMP' 테이블의 Primary Key를 대상으로 insert, update, delete 쿼리가 자동으로 생성되며, 'EMP' 테이블에 필요한 입력 파라매터가 자동으로 생성됩니다. 생성 된 입력 파라매터의 이름을 'employees'로 변경합니다.

1'EMP' Modify Invoke - 'EMP' 테이블로 부터 정의 된 쿼리를 이용하여 데이터를 수정

2employees - 쿼리에서 사용하게 될 사원의 정보

3Target DataSet - 지정 된 'employees'를 기준으로 데이터셋의 Row Type에 따라 쿼리를 수행한다. 단, Target DataSet이 지정 되지 않을 경우 Delete, Insert, Update 순서로 무조건 한번씩 실행 된다.

4SQL - Insert, Update, Delete 쿼리. 기본은 Primary key를 대상으로 자동 생성

5Enable Surround CDATA - 쿼리에 특수문자가 존재할 경우 쿼리를 CDATA로 감싼다.

SQL

Insert SQL

Update SQL

Delete SQL

insert into MIMASHUP.EMP

( EMPNO,

ENAME,

JOB,

MGR,

HIREDATE,

SAL,

COMM,

DEPTNO )

values

( #employees.EMPNO#,

#employees.ENAME#,

#employees.JOB#,

#employees.MGR#,

#employees.HIREDATE#,

#employees.SAL#,

#employees.COMM#,

#employees.DEPTNO# )

update MIMASHUP.EMP set

EMPNO = #employees.EMPNO#,

ENAME = #employees.ENAME#,

JOB = #employees.JOB#,

MGR = #employees.MGR#,

HIREDATE = #employees.HIREDATE#,

SAL = #employees.SAL#,

COMM = #employees.COMM#,

DEPTNO = #employees.DEPTNO#

where EMPNO = #employees.EMPNO#

delete from MIMASHUP.EMP

where

EMPNO = #employees.EMPNO#

Modify Invoke의 결과 데이터셋은 서버에서 쿼리의 정상 수행여부를 판단하기 위해 사용됩니다.

Jetty Web Server 실행

Start 버튼을 누르면 Jetty Web Server가 동작합니다.

X-UP Explorer에 보이는 모든 X-UP Project가 Jetty Web Server에 올라가게 됩니다.

Jetty Web Server에 올라간 모델 테스트하기

Jetty Web Server에 올라간 모델을 테스트하기 위해 브라우저에서 모델을 호출합니다.

Editor에서 오른쪽 마우스 버튼을 클릭하면 'Copy Service URL to Clipboard' 버튼을 클릭하면 호출 URL을 클립보드에 복사하게 됩니다.

호출 URL은 다음과 같습니다.

http://localhost:8080/xup/FrontControllerServlet.do?service=xupservice&format=xml&version=nexacro&domain=NexawebInc&model=ModifyEmployees

해당 모델의 test는 nexacro 어플리케이션을 통해 테스트를 수행 하여야 합니다. 만일 browser에서 호출 시 입력 파라미터가 없어 오류가 발생 할 수 있습니다.

Nexacro 어플리케이션에서 X-UP 모델 호출하기

Nexacro 어플리케이션에서 개발하기 위해 Nexacro-Studio에서 X-UP 모델을 사용하기 위한 개발단계는 다음과 같습니다.

1TypeDefinition Service 등록하기

2모델 리스트와 인터페이스 가져오기

3모델 호출 스크립트 작성하기

4테스트 하기

TypeDefinition Service 등록하기

TypeDefinition에서 다음과 같이 Service로 등록합니다.

이미 Service로 등록되어 있는 경우 Skip 합니다.

Field Name

Field Value

Prefix

'XUP_SERVER'

모델 호출 스크립트 코드에서 사용되는 Prefix를

입력합니다.

Type

'bs'

X-UP 모델을 호출하기 위해서는 반드시 bs 타입을 선택해야

합니다.

URL

'http://localhost:8080/xup/'

X-UP 서버 URL을 입력합니다.

ServiceList

'ServiceInfoServiceServlet.do?service=serviceInfo&target=modelList'

서비스 리스트 호출 url을 입력합니다.

DatasetLayout

'ServiceInfoServiceServlet.do?service=serviceInfo&target=modelLayout'

입출력 정보를 획득하기 위한 url을 입력합니다.

모델 리스트와 인터페이스 가져오기

모델 리스트와 인터페이스를 가져오기 위해 생성 된 Service ('XUP_SERVER') 를 Refresh 하고 'ModifyEmployees' 모델을 Refresh 하여 모델의 인터페이스 정보를 가져옵니다.

모델 호출 스크립트 작성하기

모델을 호출 하기 위해 Form을 하나 생성합니다.

X-UP 모델을 사용하기 위해 조회 된 모델의 인터페이스 정보에서 입출력 데이터셋을 Invisible Object 에디터로 Drag & Drop 합니다.

아래와 같이 Form을 구성하고 Script 에디터에서 호출코드를 작성합니다.

EditBox : 사원의 명칭을 입력받는다. (id : edtName)

Button : 사원을 검색한다. (id : btnSearch)

Button : 수정된 사원정보를 저장한다. (id : btnSave)

Button : 사원을 추가한다. (id : btnAdd)

Button : 사원을 삭제한다. (id : btnDel)

Grid : 검색 된 사원의 정보를 출력한다.

아래는 UI를 구성하기 위한 xfdl 파일의 정보입니다.

<?xml version="1.0" encoding="utf-8"?>
<FDL version="1.5">
  <TypeDefinition url="..\default_typedef.xml"/>
  <Form id="ModifyEmployees" classname="ModifyEmployees" left="0" top="0" width="1024" height="768" titletext="New Form">
    <Layouts>
      <Layout>
        <Static id="Static00" taborder="0" text="Name" left="19" top="41" width="59" height="26"/>
        <Edit id="edtName" taborder="1" left="77" top="40" width="385" height="28"/>
        <Button id="btnSearch" taborder="2" text="search" onclick="btnSearch_onclick" left="473" top="41" width="66" height="27"/>
        <Grid id="grdEmployees" taborder="3" binddataset="employees" useinputpanel="false" left="15" top="73" width="524" height="226">
          <Formats>
            <Format id="default">
              <Columns>
                <Column size="80"/>
                <Column size="80"/>
                <Column size="80"/>
                <Column size="80"/>
                <Column size="80"/>
                <Column size="80"/>
                <Column size="80"/>
                <Column size="80"/>
              </Columns>
              <Rows>
                <Row size="24" band="head"/>
                <Row size="24"/>
              </Rows>
              <Band id="head">
                <Cell text="EMPNO"/>
                <Cell col="1" text="ENAME"/>
                <Cell col="2" text="JOB"/>
                <Cell col="3" text="MGR"/>
                <Cell col="4" text="HIREDATE"/>
                <Cell col="5" text="SAL"/>
                <Cell col="6" text="COMM"/>
                <Cell col="7" text="DEPTNO"/>
              </Band>
              <Band id="body">
                <Cell edittype="normal" text="bind:EMPNO"/>
                <Cell col="1" edittype="normal" text="bind:ENAME"/>
                <Cell col="2" edittype="normal" text="bind:JOB"/>
                <Cell col="3" edittype="normal" text="bind:MGR"/>
                <Cell col="4" edittype="normal" text="bind:HIREDATE"/>
                <Cell col="5" edittype="normal" text="bind:SAL"/>
                <Cell col="6" edittype="normal" text="bind:COMM"/>
                <Cell col="7" edittype="normal" text="bind:DEPTNO"/>
              </Band>
            </Format>
          </Formats>
        </Grid>
        <Button id="btnAdd" taborder="4" text="add" onclick="btnAdd_onclick" left="547" top="76" width="66" height="27"/>
        <Button id="btnDel" taborder="5" text="delete" onclick="btnDel_onclick" left="547" top="111" width="66" height="27"/>
        <Button id="btnSave" taborder="6" text="save" onclick="btnSave_onclick" left="547" top="41" width="66" height="27"/>
      </Layout>
    </Layouts>
    <Objects>
      <Dataset id="employees">
        <ColumnInfo>
          <Column id="EMPNO" type="int" size="4"/>
          <Column id="ENAME" type="string" size="10"/>
          <Column id="JOB" type="string" size="9"/>
          <Column id="MGR" type="int" size="4"/>
          <Column id="HIREDATE" type="date" size="7"/>
          <Column id="SAL" type="int" size="7"/>
          <Column id="COMM" type="int" size="7"/>
          <Column id="DEPTNO" type="int" size="2"/>
        </ColumnInfo>
        <Rows/>
      </Dataset>
    </Objects>
  </Form>
</FDL>
this.btnAdd_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	this.employees.addRow();
}

this.btnDel_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	var currIndex = this.grdEmployees.currentrow;
	this.employees.deleteRow(currIndex);
}

this.btnSave_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	var svcparam 	= "domain=" 	+ "NexawebInc"  	// Domain name
					+ "&model=" 	+ "ModifyEmployees" // Model name
					+ "&format=" 	+ "xml"
					+ "&version=" 	+ "nexacro";

    var svcUrl = "XUP_SERVER::FrontControllerServlet.do?service=xupservice&" + svcparam;
    
    // Model Input parameters
    var strInDatasets = "employees=employees:U";
    var strOutDatasets = "";
    var strArgument = "";

	this.transaction("ModifyEmployees", svcUrl, strInDatasets, strOutDatasets, strArgument, "fn_Transaction_Callback");
}

this.btnSearch_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	
	var svcparam 	= "domain=" 	+ "NexawebInc"  	// Domain name
					+ "&model=" 	+ "SearchEmployees" // Model name
					+ "&format=" 	+ "xml"
					+ "&version=" 	+ "nexacro";

    var svcUrl = "XUP_SERVER::FrontControllerServlet.do?service=xupservice&" + svcparam;
    
    // Model Input parameters
    var strInDatasets = "";
    var strOutDatasets = "employees=employees";
    var strArgument = "ename="+this.edtName.text;

	this.transaction("SearchEmployees", svcUrl, strInDatasets, strOutDatasets, strArgument, "fn_Transaction_Callback");
	
}

this.fn_Transaction_Callback = function(strSvcID, nErrorCode, strErrorMag)
{
	if(nErrorCode < 0) {
		this.alert(strErrorMag);
		return;
	}
	
	if(strSvcID == "SearchEmployees") {
	
	} else if(strSvcID == "ModifyEmployees") {
		this.btnSearch_onclick(); // re-search
	}

}

테스트하기

테스트를 수행하기 위해 어플리케이션을 실행하고 실행 된 어플리케이션에서 데이터를 수정하여 정상적으로 데이터 수정이 이루어지는지 확인합니다.