kettle-资料整理&代码示例

2017-09-13  本文已影响0人  vengo_mo
整理的相关资料

集成和扩展Kettle的文档
官方例子
API
官方wiki

一些常用的实例
  1. 连接资源库
KettleEnvironment.init();
//DatabaseMeta(String name,String type,String access,String host,String db,String port,String user,String pass)
DatabaseMeta databaseMeta = new DatabaseMeta( "kettle", "Oracle", DatabaseMeta.dbAccessTypeCode[0] , url, dbName, port, dbUserName, dbPassword );
RepositoryMeta repositoryMeta =
                new KettleDatabaseRepositoryMeta( "KettleDatabaseRepository", "Oracle", "Oracle Repository", databaseMeta );
PluginRegistry registry = PluginRegistry.getInstance();
Repository repository = registry.loadClass(
                RepositoryPluginType.class,
                repositoryMeta,
                Repository.class
        );
repository.init(repositoryMeta);
repository.disconnect();
repository.connect(kettleUserName, kettlePassword);
  1. JOB运行
JobMeta jobMeta = kettleRepository.loadJob(new LongObjectId(jobId), null);
Job job =  new Job(kettleRepository,jobMeta);
job.setLogLevel(LogLevel.BASIC);
job.start();
job.waitUntilFinished();
  1. TRANS运行
TransMeta transMeta = kettleRepository.loadTransformation(new LongObjectId(transId), null);
Trans trans = new Trans(transMeta);
trans.execute(null);
trans.waitUntilFinished();
  1. 获取运行日志
//run trans
...
//get result
Result result = trans.getResult();
String logText = KettleLogStore.getAppender().getBuffer( trans.getLogChannelId(), true ).toString();

//run job
...
//get result
Result result = job.getResult();
String logText = KettleLogStore.getAppender().getBuffer( job.getLogChannelId(), true ).toString();
上一篇下一篇

猜你喜欢

热点阅读