/**
*
*/
package com.fms.xx.kettle;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.Result;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobEntryListener;
import org.pentaho.di.job.JobListener;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.job.entry.JobEntryCopy;
import org.pentaho.di.job.entry.JobEntryInterface;
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 KettleTest {
private static String repName = "KETTLE_4";
private static String dbType = "MS SQL Server";//"Oracle";
private static String dbAccess = "Native";
private static String dbHost = "localhost";//"localhost";
private static String dbName = "kettle_DB";//"orcl";
private static String dbPort = "1433";//"1521";
private static String dbUser = "sa";//"etl123";
private static String dbPass = "sa123";//"etl123";
public static void main(String[] args) {
KettleTest ktp = new KettleTest();
ktp.transferProject();
}
public boolean transferProject() {
boolean isTrue=true;
try {
//初始化环境
KettleEnvironment.init();
//创建DB资源库
KettleDatabaseRepository repository = new KettleDatabaseRepository();
DatabaseMeta databaseMeta = new DatabaseMeta(repName, dbType,dbAccess, dbHost, dbName, dbPort, dbUser, dbPass);
// 选择资源库
KettleDatabaseRepositoryMeta kettleDatabaseRepositoryMeta = new KettleDatabaseRepositoryMeta("Kettle", "Kettle", "Transformation description",databaseMeta);
repository.init(kettleDatabaseRepositoryMeta);
//连接资源库
repository.connect("admin", "admin");
//根据变量查找到模型所在的目录对象
RepositoryDirectoryInterface directory = repository.findDirectory("");///xx2/xx数据库中资源库路径,尽量不要修改
JobMeta jobMeta = ((Repository) repository).loadJob("Job1", directory, null, null);
Job job = new Job(repository, jobMeta);
job.start();
job.addJobListener(new JobListener() {
@Override
public void jobStarted(Job arg0) throws KettleException {
}
@Override
public void jobFinished(Job arg0) throws KettleException {
//isTrue = true;
System.out.println("工作完成了");
}
});
job.addJobEntryListener(new JobEntryListener() {
@Override
public void beforeExecution(Job arg0, JobEntryCopy arg1,JobEntryInterface arg2) {
}
@Override
public void afterExecution(Job arg0, JobEntryCopy arg1,JobEntryInterface arg2, Result arg3) {
System.out.println(arg1+"--------"+arg3+"*****"+arg2);
}
});
job.waitUntilFinished();
Result result = job.getResult();
System.out.println("result"+result);
return isTrue;
} catch(Throwable e) {
e.printStackTrace();
return false;
}
}
}
*
*/
package com.fms.xx.kettle;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.Result;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobEntryListener;
import org.pentaho.di.job.JobListener;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.job.entry.JobEntryCopy;
import org.pentaho.di.job.entry.JobEntryInterface;
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 KettleTest {
private static String repName = "KETTLE_4";
private static String dbType = "MS SQL Server";//"Oracle";
private static String dbAccess = "Native";
private static String dbHost = "localhost";//"localhost";
private static String dbName = "kettle_DB";//"orcl";
private static String dbPort = "1433";//"1521";
private static String dbUser = "sa";//"etl123";
private static String dbPass = "sa123";//"etl123";
public static void main(String[] args) {
KettleTest ktp = new KettleTest();
ktp.transferProject();
}
public boolean transferProject() {
boolean isTrue=true;
try {
//初始化环境
KettleEnvironment.init();
//创建DB资源库
KettleDatabaseRepository repository = new KettleDatabaseRepository();
DatabaseMeta databaseMeta = new DatabaseMeta(repName, dbType,dbAccess, dbHost, dbName, dbPort, dbUser, dbPass);
// 选择资源库
KettleDatabaseRepositoryMeta kettleDatabaseRepositoryMeta = new KettleDatabaseRepositoryMeta("Kettle", "Kettle", "Transformation description",databaseMeta);
repository.init(kettleDatabaseRepositoryMeta);
//连接资源库
repository.connect("admin", "admin");
//根据变量查找到模型所在的目录对象
RepositoryDirectoryInterface directory = repository.findDirectory("");///xx2/xx数据库中资源库路径,尽量不要修改
JobMeta jobMeta = ((Repository) repository).loadJob("Job1", directory, null, null);
Job job = new Job(repository, jobMeta);
job.start();
job.addJobListener(new JobListener() {
@Override
public void jobStarted(Job arg0) throws KettleException {
}
@Override
public void jobFinished(Job arg0) throws KettleException {
//isTrue = true;
System.out.println("工作完成了");
}
});
job.addJobEntryListener(new JobEntryListener() {
@Override
public void beforeExecution(Job arg0, JobEntryCopy arg1,JobEntryInterface arg2) {
}
@Override
public void afterExecution(Job arg0, JobEntryCopy arg1,JobEntryInterface arg2, Result arg3) {
System.out.println(arg1+"--------"+arg3+"*****"+arg2);
}
});
job.waitUntilFinished();
Result result = job.getResult();
System.out.println("result"+result);
return isTrue;
} catch(Throwable e) {
e.printStackTrace();
return false;
}
}
}