kettle源码设计模式(kettle源码分析)
本文目录一览:
- 1、kettle源码在idea上部署运行时出错
- 2、java 怎么设置kettle数据库
- 3、如何使用kettle源码更改spoon的东西
- 4、kettle源码搭建运行时出现错误
- 5、使用kettle整合新的三层结构的数据库,该怎么玩,怎么修改代码
- 6、kettle 实现列转行,行专列,源码如何debug跟踪调试?
kettle源码在idea上部署运行时出错
如果java_home设置kettle源码设计模式了kettle源码设计模式,下面可以不用设置kettle源码设计模式,如果提示JVM不能正常启动
Could not find themain class. Program will exit!
可以设置环境变量:pentaho_java_home,例如:C:\Program Files\Java\jdk1.7.0_79,其实就是你kettle源码设计模式的java安装目录,1.6以上即可。windows下
如果启动还报错“could not create the Java virtual machine”,不是java虚拟机出了问题,修改一下spoon.bat里内存配置
if "%PENTAHO_DI_JAVA_OPTIONS%"=="" setPENTAHO_DI_JAVA_OPTIONS="-Xms2058m" "-Xmx1024m""-XX:MaxPermSize=256m"
改为
if "%PENTAHO_DI_JAVA_OPTIONS%"=="" setPENTAHO_DI_JAVA_OPTIONS="-Xms512m" "-Xmx512m" "-XX:MaxPermSize=256m"
java 怎么设置kettle数据库
java调用kettle数据库类型资源库中的ktr
此问题在1个月前或许已经接触kettle源码设计模式,单是一直木有怎么用到,就被耽搁至今;问题的解决要来源于网络,其实我还想说问题的解决更多的是要靠我们自己的思想,不过多的言情,我们接下来直接进入主题吧kettle源码设计模式!
环境kettle源码设计模式:kettle-spoon 4.2.0,oracle11g,myeclipse6.5,sqlserver2008
前提:在kettle图形界面spoon里面已经做好kettle源码设计模式了一个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();
}
}
}
如何使用kettle源码更改spoon的东西
1.2. 编译源码
将项目加载到eclipse
将kettle项目拷贝到eclipse的workspace目录下,在eclipse中新建java project,项目名称和你拷贝过来的kettle文件夹名称一致
项目导入到eclipse中会出现一个错误,如下图,将这个文件的源码全部注释掉
编译
打开build.xml, 在右边的。Outline 点击kettle-run as -ant build
第一次编译的时候需要从网上下载几个文件,放在C:\Documents and Settings\Administrator\.subfloor,网络不好的话下载会比较慢,也可以直接文件放在C:\Documents and Settings\Administrator\下。编译完成后将bin目录下的.bat文件拷贝到Kettle目录下点击Spoon.bat运行,运行成功代表编译已近通过
用源码运行Spoon
Kettle源码工程本身可能是在linux64位机器上调试的,swt配置是linux64的库,所有在运行源码前需要修改成win32的swt,步骤如下:工程à属性àJava Build Pathàlibrariesàadd jars
然后将linux64的SWT库删除
最后打开src-uiàorg.pentaho.di.ui.spoonàSpoon.java, Run As àjava application
二.源码分析
2.1. 修改kettle界面
修改初始化界面
打开package org.pentaho.di.ui.spoon的Spoon.Java,找到main函数,该main函数为Spoon工具的入口,找到如下语句
Splash splash = new Splash(display);
该语句为spoon初始化显示的界面,跳到定义Splash.java,下面函数
canvas.addPaintListener(new PaintListener() {
publicvoid paintControl(PaintEvent e) {
String versionText = BaseMessages.getString(PKG, "SplashDialog.Version") + " " + Const.VERSION; //$NON-NLS-1$ //$NON-NLS-2$
StringBuilder sb = new StringBuilder();
String line = null;
try {
BufferedReader reader = new BufferedReader(newInputStreamReader(Splash.class.getClassLoader().getResourceAsStream("org/pentaho/di/ui/core/dialog/license/license.txt")));//$NON-NLS-1$
while((line = reader.readLine()) != null) {
sb.append(line + System.getProperty("line.separator")); //$NON-NLS-1$
}
} catch (Exception ex) {
sb.append(""); //$NON-NLS-1$
Log.warn(BaseMessages.getString(PKG, "SplashDialog.LicenseTextNotFound")); //$NON-NLS-1$
}
String licenseText = sb.toString();
e.gc.drawImage(kettle_image, 0, 0);
// If this is a Milestone or RC release, warn the user
if (Const.RELEASE.equals(Const.ReleaseType.MILESTONE)) {
versionText = BaseMessages.getString(PKG, "SplashDialog.DeveloperRelease") + " - " + versionText; //$NON-NLS-1$ //$NON-NLS-2$
drawVersionWarning(e);
} elseif (Const.RELEASE.equals(Const.ReleaseType.RELEASE_CANDIDATE)) {
versionText = BaseMessages.getString(PKG, "SplashDialog.ReleaseCandidate") + " - " + versionText; //$NON-NLS-1$//$NON-NLS-2$
}
elseif (Const.RELEASE.equals(Const.ReleaseType.PREVIEW)) {
versionText = BaseMessages.getString(PKG, "SplashDialog.PreviewRelease") + " - " + versionText; //$NON-NLS-1$//$NON-NLS-2$
}
elseif (Const.RELEASE.equals(Const.ReleaseType.GA)) {
versionText = BaseMessages.getString(PKG, "SplashDialog.GA") + " - " + versionText; //$NON-NLS-1$//$NON-NLS-2$
}
Font verFont = new Font(e.display, "Helvetica", 11, SWT.BOLD); //$NON-NLS-1$
e.gc.setFont(verFont);
e.gc.drawText(versionText, 290, 205, true);
// try using the desired font size for the license text
int fontSize = 8;
Font licFont = new Font(e.display, "Helvetica", fontSize, SWT.NORMAL); //$NON-NLS-1$
e.gc.setFont(licFont);
// if the text will not fit the allowed space
while (!willLicenseTextFit(licenseText, e.gc)) {
fontSize--;
licFont = new Font(e.display, "Helvetica", fontSize, SWT.NORMAL); //$NON-NLS-1$
e.gc.setFont(licFont);
}
e.gc.drawText(licenseText, 290, 290, true);
}
});
1. 修改背景图片
找到ui/image/下面的kettle_splash.png,替换该图片
2. 修改版本信息
找到e.gc.drawText(versionText, 290, 205, true); 改为e.gc.drawText("海康威视数据交换平台V1.0", 290, 205, true);
3. 修改下面的描述性文字
找到e.gc.drawText(licenseText, 290, 290, true);改为e.gc.drawText("作者:海康", 290, 290, true);
4. 预览效果
kettle源码搭建运行时出现错误
将安装包pdi-ce-5.4.0.1-130\data-integration\ui目录下的所有文件拷贝到源码包pentaho-kettle-5.4.0.1-R\ui目录下,即可解决~~
使用kettle整合新的三层结构的数据库,该怎么玩,怎么修改代码
资源库
默认数据库连接为全局共有
非资源库
a) 将数据库连接进行共享,view-database connections-share
b) 设置为全局变量,在kettle.properties文件中,将数据库连接各属性配置为变量
kettle 实现列转行,行专列,源码如何debug跟踪调试?
本文主要记录kettle列转行控件的使用。
1、用例脚本
create TABLE studentInfo
(
studentno int,
Cname varchar(10),
grade int
);
insert into studentInfo values(2018100,'语文',81);
insert into studentInfo values(2018100,'数学',82);
insert into studentInfo values(2018100,'英语',83);
insert into studentInfo values(2018101,'语文',71);
insert into studentInfo values(2018101,'数学',71);
insert into studentInfo values(2018101,'英语',72);
insert into studentInfo values(2018102,'语文',91);
insert into studentInfo values(2018102,'数学',92);
insert into studentInfo values(2018102,'英语',93);
INSERT INTO studentInfo VALUES(2018103,'语文',60);
INSERT INTO studentInfo VALUES(2018103,'数学',61);
INSERT INTO studentInfo VALUES(2018103,'英语',94);
commit;
————————————————