maxpool="10"
maxconn="20"
expiry="18000"
init="1"
url="jdbc:
db2:
RED_DB"
user="db2admin"
password="db2admin"/>
4ETLService同步数据映射配置
配置文件在ETLService.ear中的ETLWeb
4.1同步数据映射说明
同步映射配置,可以一个业务对象对多个数据表,如下:
4.2数据映射的配置实例
xmlversion="1.0"encoding="GB2312"standalone="yes"?
>
--系统实时同步的数据映射定义
table:
name:
表名
seq:
序列字段名称,例如:
EMPLOYEE_ID
seqtable:
序列的名称,例如:
ECC_FND.ECC_FND_EMPLOYEES_S
poolname:
表所在的数据库连接池
field
name:
数据字段的名称
transname:
迁移数据的名称
-->
5数据实时同步开发介绍
采用EJB的调用方式,EJB的名称XREtl,在调用的程序中引用XREtl.jar:
5.1远程接口获得
try
{
//TransfromIntime的接口
TransfromIntimetransfromIntime=(TransfromIntime)EJBHomeFactory.getFactory(com.pcm.etl.ReferenceConst.EJB_NAME).lookupHome(TransfromIntimes.class);
}
catch(EjbHomeFactoryExceptione)
{
Debug.printErr(e);
thrownewEJBException(e);
}
5.2远程接口方法
voidinsertData(Stringxml,intregisterId);
xml的格式参见下节
registered:
注册企业,从User对象中获得;
5.3远程接口方法参数说明
5.3.1插入数据的XML
XML的格式如下:
xmlversion="1.0"encoding="GB2312"standalone="yes"?
>
--系统实时同步的数据映射定义
trans:
属性:
name:
系统实时同步的名称,与ETLWeb中实时配置的trans的名称一致
数据的内容:
name:
系统实时同步数据名称,与ETLWeb中实时配置的trans的相同名称中的table中field的transname的值相同,否者就不会保存
-->
一个插入一条业务数据
5.3.2插入数据的XML的实现方式
可以通过工具类:
Model2XMLUtils实现
Model2XMLUtilsutil=Model2XMLUtils.getInstance();
EccFndEmployeesmodel=….//获得员工的数据
StringdataConfig=”employee”;//员工的映射名称,在ETLWeb的trans中配置
try
{
StringemployeeXML=Util.getTransMappingXML(model,dataConfig);
}
catch(UtilException)
{
…
}
6数据线程同步开发介绍
在工程中必须引用:
XRUtil.jar
6.1开发说明
类必须从BaseSchedulerThread派生实现doInitial和doWake两个方法,doInitial是线程启动时做初始化准备,若是没有准备,可以不用填写实现内容,doWake线程的工作内容,是同步过程的实现方法。
数据库的操作开发
1.获得Connection
Connectioncon=BaseDAO.getConnectionByPools(StringpoolName);
2.释放Connection
6.2开发实例
从两个数据不同数据库查询,并将操作日志写入到同步的日志文件中,这个类的路径在AdminWeb中配置使用。
BaseDAO.freeConnectionByPools(Connectioncon,StringpoolName)
packagecom.pcm.web.etl.test;
importjava.sql.Connection;
importjava.sql.SQLException;
importjava.sql.Timestamp;
importjava.util.Iterator;
importcom.pcm.db.ColumnData;
importcom.pcm.db.QueryUtil;
importcom.pcm.ejb.EJBHomeFactory;
importcom.pcm.ejb.EjbHomeFactoryException;
importcom.pcm.exception.UtilException;
importcom.pcm.fnd.ReferenceConst;
importcom.pcm.fnd.constants.ETLConstants;
importcom.pcm.fnd.model.ETLSchedulerLogModel;
importcom.pcm.fnd.universe.ETLSchedulerLogLet;
importcom.pcm.tracer.Debug;
importcom.pcm.util.Constants;
importcom.pcm.util.data.QueryPageData;
importcom.pcm.util.data.QueryResultData;
publicclassTestextendscom.pcm.util.BaseSchedulerThread
{
ETLSchedulerLogLetetlSchedulerLogLet=null;
@Override
protectedvoiddoInitial()
{
try
{
etlSchedulerLogLet=(ETLSchedulerLogLet)EJBHomeFactory.getFactory(ReferenceConst.EJB_NAME).lookupHome(ETLSchedulerLogLet.class);
}
catch(EjbHomeFactoryExceptione)
{
Debug.printErr(e);
}
}
protectedvoiddoWakeUp()
{
if(etlSchedulerLogLet==null)
return;
//
ConnectioneipCon=null;
ConnectionwmsCon=null;
Stringtime=newTimestamp(System.currentTimeMillis()).toString();
ETLSchedulerLogModelmodel=newETLSchedulerLogModel();
model.setLogType(this.getClass().getName());
model.setLogTime(time);
model.setCreationDate(time);
model.setRegisterId(super.registerId);
model.setEnableFlag(Constants.ENABLE_FLAG_TRUE);
try
{
eipCon=com.pcm.pubs.db.connection.BaseDbDAO.getConnectionByPools("eip_db");
wmsCon=com.pcm.pubs.db.connection.BaseDbDAO.getConnectionByPools("wms_db");
QueryUtilqueryUtil=QueryUtil.getInstance();
QueryResultDataeipRes=queryUtil.query("select*fromecc_fnd.ecc_fnd_enterprise",newQueryPageData(),eipCon);
Debug.printErr("================eipCon==============");
listPage(eipRes);
QueryResultDatawmsRes=queryUtil.query("select*fromecc_fnd.ecc_fnd_employeeswhereregister_id=400",newQueryPageData(),wmsCon);
Debug.printErr("================wmsCon==============");
Debug.printErr("select*fromecc_fnd.ecc_fnd_employeeswhereregister_id=400");
listPage(wmsRes);
//
model.setLog("getdataformeip_db,andinsertintowms_db,isOK");
model.setLogLevel(ETLConstants.ETL_SUCCESS);
etlSchedulerLogLet.insert(model);
}
catch(SQLExceptione)
{
Debug.printErr(e);
model.setLog(e.getMessage());
model.setLogLevel(ETLConstants.ETL_ERROR);
etlSchedulerLogLet.insert(model);
}
catch(UtilExceptione)
{
Debug.printErr(e);
model.setLog(e.getMessage());
model.setLogLevel(ETLConstants.ETL_ERROR);
etlSchedulerLogLet.insert(model);
}
finally
{
try
{
com.pcm.pubs.db.connection.BaseDbDAO.freeConnectionByPools(eipCon,"eip_db");
}
catch(SQLExceptione)
{
Debug.printErr(e);
model.setLog(e.getMessage());
model.setLogLevel(ETLConstants.ETL_WARN);
etlSchedulerLogLet.insert(model);
}
try
{
com.pcm.pubs.db.connection.BaseDbDAO.freeConnectionByPools(wmsCon,"wms_db");
}
catch(SQLExceptione)
{
Debug.printErr(e);
model.setLog(e.getMessage());
model.setLogLevel(ETLConstants.ETL_WARN);
etlSchedulerLogLet.insert(model);
}
}
}
privatevoidlistPage(QueryResultDatares)
{
//
if(res.getColumnNames()!
=null)
{
intnColumn=res.getColumnNames().length;
Stringhead="";
for(intiColumn=0;iColumn{
head+=res.getColumnNames()[iColumn]+"/"+res.getColumnLabels()[iColumn]+"/"+res.getColumnTypes()[iColumn]+"";
}
Debug.println(head);
//
inti=1;
for(Iteratorit=res.getResultList().iterator();it.hasNext();)
{
Stringline="";
ColumnDatadata=it.next();
Object[]colmuns=data.getDatas();
//
for(intiColumn=0;iColumn{
if(colmuns[iColumn]==null)
line+="null";
else
line+=colmuns[iColumn].toString()+"";
}
Debug.println(line);
}
}
}
}
6.3部署方式
把程序输出jar文件,放在ETL的运行环境的lib下;
以系统管理员进入AdminWeb,配置运行线程,参见《AdminWeb的ETL相关简介》
重新运新ETL工程就可以了;
7附件
7.1数据工具类QueryUtil的介绍
该工具类是通用查询工具类,输入查询SQL,返回查询结果保存在QueryResultData对象中,参见实例
调用方法