GalaxyPilot —— D.S


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

java调用kettle4.2数据库型资料库中的转换

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
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;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;

/**
 * <p>Title: java调用kettle4.2数据库型资料库中的转换</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright () 2012</p>
 * @author 舵手
 * @version
 */

public class ExecRepositoryTrans {

    private static String transName = "Trans";

    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();

            TransMeta transformationMeta = ((Repository) repository).loadTransformation(transName, directory, null, true, null ) ;

            Trans trans = new Trans( transformationMeta );
            //trans.setParameterValue( parameterName, parameterValue);
            trans.execute(null);
            trans.waitUntilFinished();
            if ( trans.getErrors() > 0 ) {                    
                System.out.println("Error running transformation.");
            }else{
                System.out.println("Transformation run successfully.");
            }
        } catch (KettleException e) {
            e.printStackTrace();
        }
    }

}

posted on 2012-07-25 16:00 舵手 阅读(2292) 评论(3)  编辑  收藏

评论

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

这段代码Pan.java里面也有
2012-07-25 17:51 | 夏天的太阳

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

我写这几行代码费了不少事,早知道就不这么费事了。

搜遍kettle的安装目录,只找到org.pentaho.di.pan.Pan.class
反编译也没有,不知夏天说的Pan.java在什么位置?
2012-07-25 19:45 | 舵手

# re: java调用kettle4.2数据库型资料库中的转换[未登录]  回复  更多评论   

package org.pentaho.di.pan;

import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.pentaho.di.core.Const;
import org.pentaho.di.core.JndiUtil;
import org.pentaho.di.core.database.Database;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogWriter;
import org.pentaho.di.core.parameters.NamedParams;
import org.pentaho.di.core.parameters.NamedParamsDefault;
import org.pentaho.di.core.util.EnvUtil;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.job.JobEntryLoader;
import org.pentaho.di.repository.RepositoriesMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectory;
import org.pentaho.di.repository.RepositoryMeta;
import org.pentaho.di.repository.UserInfo;
import org.pentaho.di.trans.StepLoader;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.version.BuildVersion;
import org.w3c.dom.Document;


public class Pan
{
2012-09-30 07:56 | owen

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


网站导航: