整理的相关资料
集成和扩展Kettle的文档
官方例子
API
官方wiki
一些常用的实例
- 连接资源库
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);
- JOB运行
JobMeta jobMeta = kettleRepository.loadJob(new LongObjectId(jobId), null);
Job job = new Job(kettleRepository,jobMeta);
job.setLogLevel(LogLevel.BASIC);
job.start();
job.waitUntilFinished();
- TRANS运行
TransMeta transMeta = kettleRepository.loadTransformation(new LongObjectId(transId), null);
Trans trans = new Trans(transMeta);
trans.execute(null);
trans.waitUntilFinished();
- 获取运行日志
//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();