Chap03_02_01_서버서비스개발-서버설정
X-API 정의 : XPLATFORM 클라이언트와 통신을 제공하고, 데이터 송수신, 또는 송수신된 데이터의 조작을 단순화함으로써 개발자는 비지니스 개발에 초점을 맞추도록 하는 것. 간단히 말해서 클라이언트 Frame과 서버의 Frame을 간단하게 사용할 수 있도록 하는 모듈
※ Oracle과 연동 시 ojdbc14.jar 파일이나 ojdbc6.jar을 자바 폴더에 안에 붙여넣기 한다.
설치 파일 필요 모든 파일 (/Tomcat 8.0/lib에 복사)
- xplatform-xapi-x.x.jar
- commons-logging-x.x.x.jar
- XPLATFORM_Server_License.xml
설치 위치 : JAR 설치되는 폴더(Class Path) - ex) WEB-INF/lib, /Tomcat 6.0/lib
설치 테스트 방법 : 교육자료 - sample - jsp - XPTest.jsp 파일을 Tomcat 8.0 - webapps - ROOT에 복사
웹에서 http://localhost:8080/XPTest.jsp 입력하고 엔터 - 그전에 2013년 9월 1일로 날짜 변경 하기 - 화면이 보이면 설치 OK
Chap03_02_02_서버서비스개발-Select
서비스 연계 구성도 이해하기!
조회서비스의 작성
employees_select.jsp : SQL query 수행 후 검색된 데이터를 Dataset에 할당하고 전송한다.
X-API 관련 작성 내용
- Package import : 클래스 패키지 압축 파일
- PlatformData 생성 : 통신 하기 위해, Dataset과 변수가 대상
- Dataset를 생성 : : 쿼리에 들어올린 데이터를 담기 위해, 데이터 할당
- 변수 생성, 데이터 할당
Tomcat 8.0 -webapps - ROOT - edu 폴더 생성 - xp 폴더 생성 - 폴더 안에 교육자료(sample - jsp - employees_select.jsp를 복사하기)
<%@ page import="org.apache.commons.logging.*" %>
<%@ page import="com.tobesoft.xplatform.data.*" %>
<%@ page import="com.tobesoft.xplatform.tx.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.io.*" %>
<%@ page contentType="text/xml; charset=UTF-8" %>
<%
// PlatformData
PlatformData o_xpData = new PlatformData();
int nErrorCode = 0;
String strErrorMsg = "START";
String sTest="111";
try {
/******* JDBC Connection *******/
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//conn = DriverManager.getConnection("jdbc:sqlserver://61.107.23.159:1433;DatabaseName=EDU;User=edu;Password=edu123");
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "melting", "0007");
stmt = conn.createStatement();
/******* SQL ************/
String SQL="select * from employees";
rs = stmt.executeQuery(SQL);
/********* Dataset **********/
DataSet ds = new DataSet("ds_employees");
ds.addColumn("EMPL_ID" ,DataTypes.STRING ,(short)10 );
ds.addColumn("FULL_NAME" ,DataTypes.STRING ,(short)50 );
ds.addColumn("HIRE_DATE" ,DataTypes.STRING ,(short)30 );
ds.addColumn("MARRIED" ,DataTypes.STRING ,(short)1 );
ds.addColumn("SALARY" ,DataTypes.INT ,(short)10 );
ds.addColumn("GENDER" ,DataTypes.STRING ,(short)1 );
ds.addColumn("DEPT_ID" ,DataTypes.STRING ,(short)10 );
ds.addColumn("EMPL_MEMO" ,DataTypes.STRING ,(short)4000 );
while(rs.next())
{
int row = ds.newRow();
ds.set(row ,"EMPL_ID" ,rs.getString("EMPL_ID") );
ds.set(row ,"FULL_NAME" ,rs.getString("FULL_NAME") );
ds.set(row ,"HIRE_DATE" ,rs.getString("HIRE_DATE") );
ds.set(row ,"MARRIED" ,rs.getString("MARRIED") );
ds.set(row ,"SALARY" ,rs.getString("SALARY") );
ds.set(row ,"GENDER" ,rs.getString("GENDER") );
ds.set(row ,"DEPT_ID" ,rs.getString("DEPT_ID") );
ds.set(row ,"EMPL_MEMO" ,rs.getString("EMPL_MEMO") );
}
// DataSet-->PlatformData
o_xpData.addDataSet(ds);
nErrorCode = 0;
strErrorMsg = "SUCC";
} catch (SQLException e) {
nErrorCode = -1;
strErrorMsg = e.getMessage();
}
/******** JDBC Close ********/
if ( stmt != null ) try { stmt.close(); } catch (Exception e) {nErrorCode = -1; strErrorMsg = e.getMessage();}
if ( conn != null ) try { conn.close(); } catch (Exception e) {nErrorCode = -1; strErrorMsg = e.getMessage();}
} catch (Throwable th) {
nErrorCode = -1;
strErrorMsg = th.getMessage();
}
// VariableList
VariableList varList = o_xpData.getVariableList();
strErrorMsg=sTest;
//Variable--> VariableList
varList.add("ErrorCode", nErrorCode);
varList.add("ErrorMsg", strErrorMsg);
// HttpPlatformResponse
HttpPlatformResponse pRes = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML, "UTF-8");
pRes.setData(o_xpData);
// Send data
pRes.sendData();
%>
저장서비스의 작성
employees_save.jsp : Client에서 전송된 데이터를 수신하고 SQL query를 통해 DB 데이터를 조작한다.(insert, update, delete)
X-API 관련 작성
- Package import
- PlatformData 생성 : 클라이언트 측에서 넘어온 dataset을 받아야 하기 때문에
트랜잭션 : n개의 dataset과 변수를 주고 받을 수 있다. 클라이언트쪽에서 받아야 하는 데이터를 받기 위한 input data, 다시 클라이언트쪽으로 넘기기 위한 output data가 필요하기 때문에 PlatformData가 두개 있음
- Dataset 수신 및 Parsing
클라이언트쪽에서 보내준 데이터를 받아서 할당하는 것. XML 통신
- DB 데이터 조작
- Client로 결과 전송
<%@ page import="org.apache.commons.logging.*" %>
<%@ page import="com.tobesoft.xplatform.data.*" %>
<%@ page import="com.tobesoft.xplatform.tx.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.io.*" %>
<%@ page contentType="text/xml; charset=UTF-8" %>
<%!
// Dataset value
public String dsGet(DataSet ds, int rowno, String colid) throws Exception
{
String value;
value = ds.getString(rowno,colid);
if( value == null )
return "";
else
return value;
}
%>
<%
// PlatformData
PlatformData o_xpData = new PlatformData();
int nErrorCode = 0;
String strErrorMsg = "START";
// HttpPlatformRequest
HttpPlatformRequest pReq = new HttpPlatformRequest(request);
// XML parsing
pReq.receiveData();
// PlatformData
PlatformData i_xpData = pReq.getData();
// Get
VariableList in_vl = i_xpData.getVariableList();
String in_var2 = in_vl.getString("sVal1");
DataSet ds = i_xpData.getDataSet("in_ds");
try {
/******* JDBC Connection *******/
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//conn = DriverManager.getConnection("jdbc:sqlserver://61.107.23.159:1433;DatabaseName=EDU;User=edu;Password=edu123");
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "melting", "0007");
stmt = conn.createStatement();
String SQL = "";
int i;
//System.out.println(">>> SQL : " + ds.getRowCount());
/******** Dataset(INSERT, UPDATE) ********/
for(i=0;i<ds.getRowCount();i++)
{
int rowType = ds.getRowType(i);
if( rowType == DataSet.ROW_TYPE_INSERTED )
{
SQL = "INSERT INTO EMPLOYEES (EMPL_ID,FULL_NAME,DEPT_ID,HIRE_DATE,GENDER,MARRIED,SALARY,EMPL_MEMO) VALUES ( " +
"'" + dsGet(ds,i,"EMPL_ID" ) + "'," +
"'" + dsGet(ds,i,"FULL_NAME" ) + "'," +
"'" + dsGet(ds,i,"DEPT_ID" ) + "'," +
"'" + dsGet(ds,i,"HIRE_DATE" ) + "'," +
"'" + dsGet(ds,i,"GENDER" ) + "'," +
"'" + dsGet(ds,i,"MARRIED" ) + "'," +
"'" + dsGet(ds,i,"SALARY" ) + "'," +
"'" + dsGet(ds,i,"EMPL_MEMO") + "' )";
System.out.println(">>> insert : "+SQL);
}
else if( rowType == DataSet.ROW_TYPE_UPDATED )
{
String org_id = ds.getSavedData(i,"EMPL_ID").toString();
SQL = "UPDATE EMPLOYEES SET " +
"FULL_NAME = '" + dsGet(ds,i,"FULL_NAME" ) + "'," +
"DEPT_ID = '" + dsGet(ds,i,"DEPT_ID" ) + "'," +
"HIRE_DATE = '" + dsGet(ds,i,"HIRE_DATE" ) + "'," +
"GENDER = '" + dsGet(ds,i,"GENDER" ) + "'," +
"MARRIED = '" + dsGet(ds,i,"MARRIED" ) + "'," +
"SALARY = '" + dsGet(ds,i,"SALARY" ) + "'," +
"EMPL_MEMO = '" + dsGet(ds,i,"EMPL_MEMO" ) + "' " +
"WHERE EMPL_ID = " + "'" + org_id + "'";
}
rs = stmt.executeQuery(SQL);
}
/****** Dataset을 DELETE처리 ****/
for( i = 0 ; i< ds.getRemovedRowCount() ; i++ )
{
String del_id = ds.getRemovedData(i,"EMPL_ID").toString();
SQL = "DELETE FROM EMPLOYEES WHERE " +
"EMPL_ID = " + "'" + del_id + "'";
rs = stmt.executeQuery(SQL);
}
//conn.commit();
} catch (SQLException e) {
// VariableList에 값을 직접 추가
nErrorCode = -1;
strErrorMsg = e.getMessage();
}
/******** JDBC Close ********/
if ( stmt != null ) try { stmt.close(); } catch (Exception e) {nErrorCode = -1; strErrorMsg = e.getMessage();}
if ( conn != null ) try { conn.close(); } catch (Exception e) {nErrorCode = -1; strErrorMsg = e.getMessage();}
nErrorCode = 0;
strErrorMsg = "SUCC";
} catch (Throwable th) {
nErrorCode = -1;
strErrorMsg = th.getMessage();
}
// VariableList 참조
VariableList varList = o_xpData.getVariableList();
// VariableList에 값을 직접 추가
varList.add("ErrorCode", nErrorCode);
varList.add("ErrorMsg", strErrorMsg);
// HttpServletResponse를 이용하여 HttpPlatformResponse 생성
HttpPlatformResponse pRes = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML, "UTF-8");
pRes.setData(o_xpData);
// 데이터 송신
pRes.sendData();
%>
Chap03_03_01_Service호출-load
Script 작성 및 서비스 호출
조회서비스 호출
Dataset.load()
지정한 URL의 Dataset 정보(서버)를 읽어 클라이언트측의 Dataset를 구성한다.
만약, 현재 Dataset이 다른 Dataset 정보를 포함하고 있었다면 이전의 Dataset 정보는 Clear 된다.
하나의 Dataset을 조회할 때 사용됨. n개의 변수만 조회할때
실습
Retrieve에 이벤트 작성 function 적용 시 Dataset 이름은 기존에 작성한 Dataset 이름과 같아야함.
//조회
function fn_Retrieve(obj:Button, e:ClickEventInfo)
{
ds_employees.url = "DataURL::employees_select.jsp";
ds_employees.load();
}
employees_select.jsp를 인사관리시스템 DB에 맞게 수정한다.
* 포트번호나 파일 경로가 바뀔 때 모두 수정하는 것을 방지 하기 위한 방법
typeDefinition 더블클릭 - services 탭 - add - jsp 선택, 경로 복사 - Ok
* DataURL::employees_select.jsp -> 세미콜론 오른쪽 실제 확장자를 가진 물리적인 파일을 왼쪽에 있는 제목에 가지고 있다.
* XPLATFORM은 Default 통신 방식이 비동기 방식으로 세팅되어 있다. 응답을 기다리지 않고 script를 실행함.
그렇기 때문에 load() 이후에 로직을 작성하지 않고 Dataset의 event의 onlaod를 사용한다.
Chap03_03_02_Service호출-transaction
저장서비스 호출
transaction() : Dataset의 값을 갱신하기 위한 서비스를 호출하고, transaction이 완료되면 CallBack Function을 수행하는 Method
Sytanx
transaction(strSvcID, strURL, strInDatasets, strOutDatasets,
strArgument, strCallbackFunc,
[,bAsync[,bBinary[,bCompress]]]);
레코드 추가
// Add
function fn_add(obj:Button, e:ClickEventInfo)
{
ds_employees.addRow();
//특정한 곳에 추가 insertRow()
}
레코드 삭제
//삭제
function fn_delete(obj:Button, e:ClickEventInfo)
{
//사용자가 선택한 위치를 삭제한다
ds_employees.deleteRow(ds_employees.rowposition);
}
데이터 저장
//Save
function fn_save(obj:Button, e:ClickEventInfo)
{
//공백을 포함한 변수의 값의 전송은 ''을 붙인다.
transaction("trSave" //트랜잭션 아이디
,"DataURL::employees_save.jsp" //서버측 주소
,"in_ds=ds_employees:u" //input 서버측에서 받는 DataSet, 변경한 레코드만 넘어간다. 구분자 공백
,"" //output 데이터. 저장, 조회도 가능
,"sVall=1"
,"fn_callback");
//비동기 응답을 받는 function. callback
}
var out_var;
//비동기 응답받는 Function으로 transaction의 6번째 인자와 동일해야함
function fn_callback(trID, nCD, sMSG)
{
if(trID == "trSave")
{
if(nCD<0)
{
alert("저장실패");
}
else {
alert("저장성공");
}
}
}
Chap03_03_03_Debugging
alert : 보여지는 dialog 화면
trace : 추적 로그를 남기는 Method 예)java의 System.out.println();
디버깅 단축키:
디버깅 후에 variables 탭 클릭 : 로직 추적
통신을 추적할 때는 통신 전과 통신 후에 Break Point를 설정해야한다.
'IT 지식' 카테고리의 다른 글
[XPLATFORM] Chap05_Application (0) | 2025.04.13 |
---|---|
[XPLATFORM] Chap04_Design (0) | 2025.04.13 |
[XPLATFORM] Chap03_01_화면Design (0) | 2025.04.13 |
anyframe (0) | 2025.04.13 |
통합권한관리 및 감사솔루션 nOM(netcruz Operation Manager) (1) | 2025.04.13 |