Kettle日志之Kettle step materic日志代码实现(一)

一、Developer Environment:

JDK1.6

MyEclipse6.5

Kettle4.0

二、Code List
1、创建Step日志表kettle_step_log_table(Oracle建表sql)

create table KETTLE_STEP_LOG_TABLE
(
  ID_BATCH       INTEGER,
  CHANNEL_ID     VARCHAR2(255),
  LOG_DATE       DATE,
  TRANSNAME      VARCHAR2(255),
  STEPNAME       VARCHAR2(255),
  STEP_COPY      INTEGER,
  LINES_READ     INTEGER,
  LINES_WRITTEN  INTEGER,
  LINES_UPDATED  INTEGER,
  LINES_INPUT    INTEGER,
  LINES_OUTPUT   INTEGER,
  LINES_REJECTED INTEGER,
  ERRORS         INTEGER,
  LOG_FIELD      CLOB
)


 

2、配置step日志数据库连接

<connection>
    <name>kettle_step_log_table</name>
    <server>10.10.3.52</server>
    <type>ORACLE</type>
    <access>Native</access>
    <database>DGWSJ</database>
    <port>1521</port>
    <username>bsoft</username>
    <password>Encrypted 2be98afc86aa7f2e4cb79ce72cd9da9ce</password>
    <servername/>
    <data_tablespace/>
    <index_tablespace/>
    <attributes>
      <attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>
      <attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>
      <attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>
      <attribute><code>PORT_NUMBER</code><attribute>1521</attribute></attribute>
      <attribute><code>QUOTE_ALL_FIELDS</code><attribute>N</attribute></attribute>
      <attribute><code>SUPPORTS_BOOLEAN_DATA_TYPE</code><attribute>N</attribute></attribute>
      <attribute><code>USE_POOLING</code><attribute>N</attribute></attribute>
    </attributes>
  </connection>


3、Trans实现代码

package com.ohgrateboy;

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.StepLogTable;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.core.variables.Variables;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;

public class ReaderTransFromFileRep {
	public static void main(String[] args) throws KettleException {
		KettleEnvironment.init();
		Trans trans=null;
		//定义变量
		VariableSpace space = new Variables();
		//将step日志数据库配置名加入到变量集中
		space.setVariable("kettle_step_log_table","kettle_step_log_table");
	    space.initializeVariablesFrom(null);
		try {
				TransMeta transMetadel = new TransMeta("D:/Untitled.xml");
				//声明StepLogTable。space-系统变量,tanMetade1-提供数据库连接
				StepLogTable stepLogTable = StepLogTable.getDefault(space,transMetadel);
				//StepLogTable使用的数据库连接名(上面配置的变量名)。
				stepLogTable.setConnectionName("kettle_step_log_table");
				//设置Step日志的表名
				stepLogTable.setTableName("kettle_step_log_table");
				//设置TransMeta的StepLogTable
				transMetadel.setStepLogTable(stepLogTable);
				// 转换
				trans = new Trans(transMetadel);
				// 执行转换
				trans.execute(null);
				// 等待转换执行结束
				trans.waitUntilFinished();
				//抛出异常
				if(trans.getErrors()>0){
					throw new Exception("There are errors during transformation exception!(传输过程中发生异常)");
				}
			
		} catch (Exception e) {
			if(trans!=null){
				trans.stopAll();
			}
			e.printStackTrace();
			throw new KettleException(e);
		}
	}
}

4、控制台运行截图

5、step日志表查询结果截图(部分字段):

转载于:https://my.oschina.net/u/174862/blog/285969

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值