久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Java調(diào)用Kettle執(zhí)行任務(wù)或轉(zhuǎn)換

 hehffyy 2013-12-27

Java調(diào)用Kettle執(zhí)行任務(wù)或轉(zhuǎn)換,需要使用Kettle中的jar,,可以先導(dǎo)入lib目錄中的幾個基本的jar,,如:kettle-core.jar、kettle-db.jar,、kettle-engine.jar ,,其它jar根據(jù)情況進(jìn)行添加,所需的jar在<kettle-home>\lib,、<kettle-home>\libext下面都可以找到,,本示例引用的jar如下圖:

 

 

 

之后編寫代碼測試Java調(diào)用,調(diào)用前先使用Kettle的設(shè)計器設(shè)計了一個轉(zhuǎn)換,,取名為voucher.ktr,。另外,本示例使用的是Kettle3.2的版本,,據(jù)說4.1版本調(diào)用方法會有不同。

  1. import org.pentaho.di.core.database.DatabaseMeta;  
  2. import org.pentaho.di.core.exception.KettleException;  
  3. import org.pentaho.di.core.logging.LogWriter;  
  4. import org.pentaho.di.core.util.EnvUtil;  
  5. import org.pentaho.di.job.Job;  
  6. import org.pentaho.di.job.JobEntryLoader;  
  7. import org.pentaho.di.job.JobMeta;  
  8. import org.pentaho.di.repository.Repository;  
  9. import org.pentaho.di.repository.RepositoryDirectory;  
  10. import org.pentaho.di.repository.RepositoryMeta;  
  11. import org.pentaho.di.repository.UserInfo;  
  12. import org.pentaho.di.trans.StepLoader;  
  13. import org.pentaho.di.trans.Trans;  
  14. import org.pentaho.di.trans.TransMeta;  
  15.   
  16. /** 
  17.  * Java調(diào)用Kettle示例代碼 
  18.  *  
  19.  * @author 李文鍇 
  20.  * @since 2012-8-14 下午03:50:00 
  21.  *  
  22.  */  
  23. public class KettleTest {  
  24.   
  25.     public static void main(String[] args) throws KettleException {  
  26.         String filename = "voucher.ktr";  
  27.         // callNativeTrans(filename);  
  28.         // executeTrans();  
  29.         // executeJobs();  
  30.         callNativeTransWithParam(filename);  
  31.         System.out.println("ok");  
  32.     }  
  33.   
  34.     /** 
  35.      * 調(diào)用本地的轉(zhuǎn)換文件 
  36.      *  
  37.      * @Description: 
  38.      * @param transFileName 
  39.      * @throws KettleException 
  40.      * @author 李文鍇 
  41.      * @since:2012-8-15 下午02:58:41 
  42.      */  
  43.     public static void callNativeTrans(String transFileName) throws KettleException {  
  44.         // 初始化  
  45.         EnvUtil.environmentInit();  
  46.         StepLoader.init();  
  47.         // 轉(zhuǎn)換元對象  
  48.         TransMeta transMeta = new TransMeta(transFileName);  
  49.         // 轉(zhuǎn)換  
  50.         Trans trans = new Trans(transMeta);  
  51.         // 執(zhí)行轉(zhuǎn)換  
  52.         trans.execute(null);  
  53.         // 等待轉(zhuǎn)換執(zhí)行結(jié)束  
  54.         trans.waitUntilFinished();  
  55.     }  
  56.   
  57.     /** 
  58.      * 調(diào)用本地的轉(zhuǎn)換文件(帶參數(shù)) 
  59.      *  
  60.      * @Description: 
  61.      * @param transFileName 
  62.      * @throws KettleException 
  63.      * @author 李文鍇 
  64.      * @since:2012-8-15 下午02:58:54 
  65.      */  
  66.     public static void callNativeTransWithParam(String transFileName) throws KettleException {  
  67.         // 初始化  
  68.         EnvUtil.environmentInit();  
  69.         StepLoader.init();  
  70.         // 轉(zhuǎn)換元對象  
  71.         TransMeta transMeta = new TransMeta(transFileName);  
  72.         // 轉(zhuǎn)換  
  73.         Trans trans = new Trans(transMeta);  
  74.         String[] params = {};  
  75.         // 執(zhí)行轉(zhuǎn)換  
  76.         trans.execute(params);  
  77.         // 等待轉(zhuǎn)換執(zhí)行結(jié)束  
  78.         trans.waitUntilFinished();  
  79.   
  80.     }  
  81.   
  82.     /** 
  83.      * 執(zhí)行存儲在數(shù)據(jù)庫資源庫中的轉(zhuǎn)換 
  84.      *  
  85.      * @Description: 
  86.      * @throws KettleException 
  87.      * @author 李文鍇 
  88.      * @since:2012-8-15 下午02:59:14 
  89.      */  
  90.     public static void executeTrans() throws KettleException {  
  91.         // 初始化  
  92.         EnvUtil.environmentInit();  
  93.         StepLoader.init();  
  94.         // 日志  
  95.         LogWriter log = LogWriter.getInstance("TransTest.log"true, LogWriter.LOG_LEVEL_DEBUG);  
  96.         // 用戶  
  97.         UserInfo userInfo = new UserInfo();  
  98.         userInfo.setLogin("admin");  
  99.         userInfo.setPassword("admin");  
  100.         // 數(shù)據(jù)庫連接元對象(連接名稱,,不必與kettle中配置的保持一致:數(shù)據(jù)庫類型:連接方式(kettle支持的連接方式):資源庫IP:資源庫實例名:資源庫端口:資源庫用戶名:資源庫用戶密碼)  
  101.         DatabaseMeta connection = new DatabaseMeta("""Oracle""Native""192.168.3.232""NSDEV""1521""nstcsa3441""671468");  
  102.         // 資源庫元對象  
  103.         RepositoryMeta repinfo = new RepositoryMeta();  
  104.         repinfo.setConnection(connection);  
  105.         // 資源庫  
  106.         Repository rep = new Repository(log, repinfo, userInfo);  
  107.         // 連接資源庫  
  108.         rep.connect("");  
  109.         // 資源庫目錄對象  
  110.         RepositoryDirectory dir = new RepositoryDirectory(rep);  
  111.         // 轉(zhuǎn)換元對象  
  112.         TransMeta transMeta = new TransMeta(rep, "憑證(N9->EVC2)", dir);  
  113.         // 轉(zhuǎn)換  
  114.         Trans trans = new Trans(transMeta);  
  115.         // 執(zhí)行轉(zhuǎn)換  
  116.         trans.execute(null);  
  117.         // 等待轉(zhuǎn)換執(zhí)行結(jié)束  
  118.         trans.waitUntilFinished();  
  119.     }  
  120.   
  121.     /** 
  122.      * 執(zhí)行本地的任務(wù)文件 
  123.      *  
  124.      * @Description: 
  125.      * @param jobFileName 
  126.      * @throws KettleException 
  127.      * @author 李文鍇 
  128.      * @since:2012-8-15 下午02:59:34 
  129.      */  
  130.     public static void callNativeJob(String jobFileName) throws KettleException {  
  131.         // 初始化  
  132.         EnvUtil.environmentInit();  
  133.         JobEntryLoader.init();  
  134.         StepLoader.init();  
  135.         // 日志  
  136.         LogWriter log = LogWriter.getInstance("TransTest.log"true, LogWriter.LOG_LEVEL_DETAILED);  
  137.         // job元對象  
  138.         JobMeta jobMeta = new JobMeta(log, jobFileName, null);  
  139.         // job  
  140.         Job job = new Job(log, StepLoader.getInstance(), null, jobMeta);  
  141.         jobMeta.setInternalKettleVariables(job);  
  142.         // 執(zhí)行job  
  143.         job.execute();  
  144.         // 等待job執(zhí)行結(jié)束  
  145.         job.waitUntilFinished();  
  146.     }  
  147.   
  148.     /** 
  149.      * 執(zhí)行數(shù)據(jù)庫資源庫中的任務(wù) 
  150.      *  
  151.      * @Description: 
  152.      * @throws KettleException 
  153.      * @author 李文鍇 
  154.      * @since:2012-8-15 下午02:59:45 
  155.      */  
  156.     public static void executeJobs() throws KettleException {  
  157.         // 初始化  
  158.         EnvUtil.environmentInit();  
  159.         JobEntryLoader.init();  
  160.         StepLoader.init();  
  161.         // 日志  
  162.         LogWriter log = LogWriter.getInstance("TransTest.log"true, LogWriter.LOG_LEVEL_DETAILED);  
  163.         // 用戶  
  164.         UserInfo userInfo = new UserInfo();  
  165.         userInfo.setLogin("admin");  
  166.         userInfo.setPassword("admin");  
  167.         // 數(shù)據(jù)庫連接元對象  
  168.         DatabaseMeta connection = new DatabaseMeta("""Oracle""Native""192.168.3.232""NSDEV""1521""nstcsa3441""671468");  
  169.         // 資源庫元對象  
  170.         RepositoryMeta repinfo = new RepositoryMeta();  
  171.         repinfo.setConnection(connection);  
  172.         // 資源庫  
  173.         Repository rep = new Repository(log, repinfo, userInfo);  
  174.         // 連接資源庫  
  175.         rep.connect("");  
  176.         // 資源庫目錄對象  
  177.         RepositoryDirectory dir = new RepositoryDirectory(rep);  
  178.         // 步驟加載對象  
  179.         StepLoader steploader = StepLoader.getInstance();  
  180.         // job元對象  
  181.         JobMeta jobmeta = new JobMeta(log, rep, "4.賬戶每日余額", dir);  
  182.         // job  
  183.         Job job = new Job(log, steploader, rep, jobmeta);  
  184.         // 執(zhí)行job  
  185.         job.execute();  
  186.         // 等待job執(zhí)行結(jié)束  
  187.         job.waitUntilFinished();  
  188.   
  189.     }  
  190.   
  191. }  

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多