kettle與java(kettle怎麼說)

本文目錄一覽:

如何將kettle 集成到java應用

在Java應用程序中調用Kettle的Transformation

package com.ggd543.kettle.trans

import org.pentaho.di.core.util.EnvUtil

import org.pentaho.di.core.KettleEnvironment

import org.pentaho.di.trans.{Trans, TransMeta}

/**

*

* User: 劉永健

* Date: 12-3-8

* Time: 下午12:14

* To change this template use File | Settings | File Templates.

*/

object TransDemo extends App {

execTrans(args(0)) // ktr文件的全路徑

def execTrans(fileName: String) {

KettleEnvironment.init()

EnvUtil.environmentInit();

val transMeta = new TransMeta(fileName)

val trans = new Trans(transMeta)

trans.execute(null) // you can pass arguments instead of null

trans.waitUntilFinished();

if (trans.getErrors 0) {

throw new RuntimeException(“There were errors during transformation execution”)

}

}

}

?xml version=”1.0″ encoding=”UTF-8″?

project xmlns=””

xmlns:xsi=””

xsi:schemaLocation=” “

modelVersion4.0.0/modelVersion

groupIdkettledemo/groupId

artifactIdkettledemo/artifactId

version1.0/version

dependencies

!– Test —

dependency

groupIdjunit/groupId

artifactIdjunit/artifactId

version4.8.1/version

scopetest/scope

/dependency

dependency

groupIdorg.scala-tools.testing/groupId

artifactIdspecs_2.9.1/artifactId

version1.6.9/version

scopetest/scope

/dependency

dependency

groupIdorg.scalatest/groupId

artifactIdscalatest_2.9.1/artifactId

version1.6.1/version

scopetest/scope

/dependency

dependency

groupIdcom.typesafe.akka/groupId

artifactIdakka-actor/artifactId

version2.0/version

/dependency

dependency

groupIdcom.typesafe.akka/groupId

artifactIdakka-testkit/artifactId

version2.0/version

/dependency

/dependencies

build

plugins

plugin

groupIdorg.apache.maven.plugins/groupId

artifactIdmaven-compiler-plugin/artifactId

configuration

source1.6/source

target1.6/target

encodingUTF-8/encoding

/configuration

/plugin

/plugins

/build

profiles

profile

idpentaho/id

activation

activeByDefaulttrue/activeByDefault

/activation

properties

pentaho.kettle.version4.2.1.1/pentaho.kettle.version

/properties

dependencies

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-core/artifactId

version${pentaho.kettle.version}/version

/dependency

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-db/artifactId

version${pentaho.kettle.version}/version

/dependency

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-engine/artifactId

version${pentaho.kettle.version}/version

/dependency

dependency

groupIdpentaho/groupId

artifactIdpentaho-hdfs-vfs/artifactId

version1.0.1/version

/dependency

dependency

groupIdlog4j/groupId

artifactIdlog4j/artifactId

version1.2.16/version

/dependency

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-test/artifactId

version${pentaho.kettle.version}/version

scopetest/scope

/dependency

/dependencies

repositories

repository

idpentaho/id

namePentaho Repository/name

url;/url

/repository

/repositories

/profile

profile

idscala/id

activation

activeByDefaulttrue/activeByDefault

/activation

properties

scala.version2.9.1/scala.version

/properties

repositories

repository

idtypesafe/id

nameTypesafe Repository/name

url;/url

/repository

/repositories

dependencies

dependency

groupIdorg.scala-lang/groupId

artifactIdscala-compiler/artifactId

version${scala.version}/version

scopecompile/scope

/dependency

dependency

groupIdorg.scala-lang/groupId

artifactIdscala-library/artifactId

version${scala.version}/version

/dependency

dependency

groupIdorg.scala-lang/groupId

artifactIdscala-swing/artifactId

version${scala.version}/version

/dependency

/dependencies

build

plugins

plugin

groupIdorg.scala-tools/groupId

artifactIdmaven-scala-plugin/artifactId

executions

execution

goals

goalcompile/goal

goaltestCompile/goal

/goals

/execution

/executions

/plugin

/plugins

/build

/profile

/profiles

/project

java 怎麼設置kettle資料庫

java調用kettle資料庫類型資源庫中的ktr

此問題在1個月前或許已經接觸,單是一直木有怎麼用到,就被耽擱至今;問題的解決要來源於網路,其實我還想說問題的解決更多的是要靠我們自己的思想,不過多的言情,我們接下來直接進入主題吧!

環境:kettle-spoon 4.2.0,oracle11g,myeclipse6.5,sqlserver2008

前提:在kettle圖形界面spoon裡面已經做好了一個ktr轉換模型,此時我的ktr信息如下圖:

Step1:在myeclipse創建project,導入kettle集成所需要的包

Step2:重點解析與code源碼

//定義ktr名字

private static String transName = “test1”;

//初始化kettle環境

KettleEnvironment.init();

//創建資源庫對象,此時的對象還是一個空對象

KettleDatabaseRepository repository = new KettleDatabaseRepository();

//創建資源庫資料庫對象,類似我們在spoon裡面創建資源庫

DatabaseMeta dataMeta =

new DatabaseMeta(“enfo_bi”,”Oracle”,”Native”,”ip”,”sid”,”port”,”username”,”password”);

//資源庫元對象,名稱參數,id參數,描述等可以隨便定義

KettleDatabaseRepositoryMeta kettleDatabaseMeta =

new KettleDatabaseRepositoryMeta(“enfo_bi”, “enfo_bi”, “king description”,dataMeta);

//給資源庫賦值

repository.init(kettleDatabaseMeta);

//連接資源庫

repository.connect(“admin”,”admin”);

//根據變數查找到模型所在的目錄對象

RepositoryDirectoryInterface directory = repository.findDirectory(“/enfo_worker/wxj”);

//創建ktr元對象

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

//創建ktr

Trans trans = new Trans(transformationMeta);

//執行ktr

trans.execute(null);

//等待執行完畢

trans.waitUntilFinished();

上面的兩個步驟才可以確定是資源庫中的那個路徑下的ktr和我們用命令執行一樣的-dir ,-tran -job

附上源碼:

package kettle;

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;

/**

* pTitle: java調用kettle4.2資料庫型資料庫中的轉換/p

* pDescription: /p

* pCopyright: Copyright () 2012/p

*/

public class ExecuteDataBaseRepTran {

private static String transName = “test1”;

public static void main(String[] args) {

try {

//初始化kettle環境

KettleEnvironment.init();

//創建資源庫對象,此時的對象還是一個空對象

KettleDatabaseRepository repository = new KettleDatabaseRepository();

//創建資源庫資料庫對象,類似我們在spoon裡面創建資源庫

DatabaseMeta dataMeta =

new DatabaseMeta(“enfo_bi”,”Oracle”,”Native”,”ip”,”sid”,”port”,”username”,”password”);

//資源庫元對象,名稱參數,id參數,描述等可以隨便定義

KettleDatabaseRepositoryMeta kettleDatabaseMeta =

new KettleDatabaseRepositoryMeta(“enfo_bi”, “enfo_bi”, “king description”,dataMeta);

//給資源庫賦值

repository.init(kettleDatabaseMeta);

//連接資源庫

repository.connect(“admin”,”admin”);

//根據變數查找到模型所在的目錄對象,此步驟很重要。

RepositoryDirectoryInterface directory = repository.findDirectory(“/enfo_worker/wxj”);

//創建ktr元對象

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

//創建ktr

Trans trans = new Trans(transformationMeta);

//執行ktr

trans.execute(null);

//等待執行完畢

trans.waitUntilFinished();

if(trans.getErrors()0)

{

System.err.println(“Transformation run Failure!”);

}

else

{

System.out.println(“Transformation run successfully!”);

}

} catch (KettleException e) {

e.printStackTrace();

}

}

}

如何將JAVA程序集成到KETTLE中

在Java應用程序中調用Kettle的Transformation

package com.ggd543.kettle.trans

import org.pentaho.di.core.util.EnvUtil

import org.pentaho.di.core.KettleEnvironment

import org.pentaho.di.trans.{Trans, TransMeta}

/**

*

* User: 劉永健

* Date: 12-3-8

* Time: 下午12:14

* To change this template use File | Settings | File Templates.

*/

object TransDemo extends App {

execTrans(args(0)) // ktr文件的全路徑

def execTrans(fileName: String) {

KettleEnvironment.init()

EnvUtil.environmentInit();

val transMeta = new TransMeta(fileName)

val trans = new Trans(transMeta)

trans.execute(null) // you can pass arguments instead of null

trans.waitUntilFinished();

if (trans.getErrors 0) {

throw new RuntimeException(“There were errors during transformation execution”)

}

}

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/297766.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-28 12:16
下一篇 2024-12-28 12:16

相關推薦

  • java client.getacsresponse 編譯報錯解決方法

    java client.getacsresponse 編譯報錯是Java編程過程中常見的錯誤,常見的原因是代碼的語法錯誤、類庫依賴問題和編譯環境的配置問題。下面將從多個方面進行分析…

    編程 2025-04-29
  • Java JsonPath 效率優化指南

    本篇文章將深入探討Java JsonPath的效率問題,並提供一些優化方案。 一、JsonPath 簡介 JsonPath是一個可用於從JSON數據中獲取信息的庫。它提供了一種DS…

    編程 2025-04-29
  • Java騰訊雲音視頻對接

    本文旨在從多個方面詳細闡述Java騰訊雲音視頻對接,提供完整的代碼示例。 一、騰訊雲音視頻介紹 騰訊雲音視頻服務(Cloud Tencent Real-Time Communica…

    編程 2025-04-29
  • Java Bean載入過程

    Java Bean載入過程涉及到類載入器、反射機制和Java虛擬機的執行過程。在本文中,將從這三個方面詳細闡述Java Bean載入的過程。 一、類載入器 類載入器是Java虛擬機…

    編程 2025-04-29
  • Java Milvus SearchParam withoutFields用法介紹

    本文將詳細介紹Java Milvus SearchParam withoutFields的相關知識和用法。 一、什麼是Java Milvus SearchParam without…

    編程 2025-04-29
  • Java 8中某一周的周一

    Java 8是Java語言中的一個版本,於2014年3月18日發布。本文將從多個方面對Java 8中某一周的周一進行詳細的闡述。 一、數組處理 Java 8新特性之一是Stream…

    編程 2025-04-29
  • Java判斷字元串是否存在多個

    本文將從以下幾個方面詳細闡述如何使用Java判斷一個字元串中是否存在多個指定字元: 一、字元串遍歷 字元串是Java編程中非常重要的一種數據類型。要判斷字元串中是否存在多個指定字元…

    編程 2025-04-29
  • VSCode為什麼無法運行Java

    解答:VSCode無法運行Java是因為默認情況下,VSCode並沒有集成Java運行環境,需要手動添加Java運行環境或安裝相關插件才能實現Java代碼的編寫、調試和運行。 一、…

    編程 2025-04-29
  • Java任務下發回滾系統的設計與實現

    本文將介紹一個Java任務下發回滾系統的設計與實現。該系統可以用於執行複雜的任務,包括可回滾的任務,及時恢復任務失敗前的狀態。系統使用Java語言進行開發,可以支持多種類型的任務。…

    編程 2025-04-29
  • Java 8 Group By 會影響排序嗎?

    是的,Java 8中的Group By會對排序產生影響。本文將從多個方面探討Group By對排序的影響。 一、Group By的概述 Group By是SQL中的一種常見操作,它…

    編程 2025-04-29

發表回復

登錄後才能評論