kettle 응용 프로그램 통합 코드
package com.zjhcsoft.kettle.test;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.CentralLogStore;
import org.pentaho.di.core.logging.Log4jBufferAppender;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.core.plugins.RepositoryPluginType;
import org.pentaho.di.core.util.EnvUtil;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.RepositoriesMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryMeta;
import org.pentaho.di.repository.StringObjectId;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
public class TestKettle {
/**
* --
* @author twr_wjz
* @date 2011-11-17
* @param filename
* @throws Exception
*/
public void runFileTransformation(String filename) {
try {
// ( 、 )
KettleEnvironment.init();
EnvUtil.environmentInit();
//
TransMeta transMeta = new TransMeta(filename);
Trans trans = new Trans(transMeta);
// You can pass arguments instead of null.
trans.execute(null);
//
trans.waitUntilFinished();
/*
*
*/
if ( trans.getErrors() > 0 )
{
throw new RuntimeException( " 。" );
}
}
catch ( KettleException e ) {
// TODO Put your exception-handling code here.
System.out.println(e);
}
}
/**
* --
* @author twr_wjz
* @date 2011-11-17
* @param repID ID, :1 ---- ,
* @param transformationID ID-- r_transformation ID_TRANSFORMATION
* @param transformationVersion -- r_transformation TRANS_VERSION
* @throws Exception
*/
/**
* @param repID
* @param transformationID
* @param transformationVersion
*/
public void runRepTransformation(String repID,String transformationID,String transformationVersion) {
try {
// ( 、 )
KettleEnvironment.init();
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
//
repositoriesMeta.readData();
//
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repID);
//
Repository repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
repository.init(repositoryMeta);
//
repository.connect("admin", "admin");
// ID
ObjectId id = new StringObjectId(transformationID);
//
TransMeta transMeta = repository.loadTransformation(id,transformationVersion);
Trans trans = new Trans(transMeta);
// You can pass arguments instead of null.
trans.execute(null);
//
Log4jBufferAppender appender = CentralLogStore.getAppender();
//
trans.waitUntilFinished();
// IU
//InsertUpdate insertUpdate = (InsertUpdate)trans.findBaseSteps("IU").get(0);
//String logText = appender.getBuffer(insertUpdate.getLogChannelId(), false).toString();
//System.out.println("
"+logText+"
。
");
//
// CentralLogStore.discardLines(trans.getLogChannelId(),false);
/*
*
*/
if ( trans.getErrors() > 0 )
{
throw new RuntimeException( " 。" );
}
repository.disconnect();
}
catch ( KettleException e ) {
// TODO Put your exception-handling code here.
System.out.println(e);
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestKettle testKettle = new TestKettle();
// testKettle.runFileTransformation("C:/111.ktr");
System.out.println(System.getProperty("user.dir"));
System.out.println(System.getProperty("KETTLE_HOME"));
System.setProperty("user.dir", "E:/myeclipseworkspace/testkettle/kettleconfig");
System.setProperty("KETTLE_HOME", "E:/myeclipseworkspace/testkettle/kettleconfig");
System.out.println(System.getProperty("user.dir"));
System.out.println(System.getProperty("KETTLE_HOME"));
testKettle.runRepTransformation("testkettle","1","1.0");
testKettle.runRepTransformation("testkettle","2","1.0");
}
}
kettle 설정 디 렉 터 리 변경 후 코드 설정 은 다음 과 같 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.