GalaxyPilot —— D.S


        生命不熄,战斗不止
数据加载中……

java调用kettle4.2数据库型资料库中的作业

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.job.Job;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectoryInterface;
import org.pentaho.di.repository.kdr.KettleDatabaseRepository;
import org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta;

public class execRepositoryJobs {

    private static String jobName = "Job";

    public static void main(String[] args) {
        try {
            KettleEnvironment.init();

            KettleDatabaseRepository repository = new KettleDatabaseRepository();

            DatabaseMeta databaseMeta = new DatabaseMeta("repository", "MSSQL","Native", "192.169.0.146", "repository", "1433", "sa","sa");

            KettleDatabaseRepositoryMeta kettleDatabaseMeta = new KettleDatabaseRepositoryMeta("repository", "ERP", "Transformation description",databaseMeta);

            repository.init(kettleDatabaseMeta);

            repository.connect("admin", "admin");

            RepositoryDirectoryInterface directory = repository.loadRepositoryDirectoryTree();
            
            JobMeta jobMeta = ((Repository) repository).loadJob(jobName, directory, null, null ) ;

//            RepositoryDirectoryInterface fooBar = directory.findDirectory("/");
//
//            JobMeta jobMeta = repository.loadJob(repository.getJobId(jobName, fooBar), null);

            Job job = new Job(repository,jobMeta);
            
            job.start();
            
            job.waitUntilFinished();
            
            if (job.getErrors() > 0) {
                throw new RuntimeException(
                        "There were errors during transformation execution.");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

posted on 2012-07-30 14:33 舵手 阅读(1508) 评论(1)  编辑  收藏

评论

# re: java调用kettle4.2数据库型资料库中的作业  回复  更多评论   

这阵子跟kettle较劲了?
2012-10-25 11:19 | klzz

只有注册用户登录后才能发表评论。


网站导航: