Teiid搭建和使用小记

参考文档

  1. Teiid 基于数据联邦的集成方案
  2. 数据集成工具Teiid Designer的环境搭建
  3. 数据集成工具:Teiid实践
  4. teiid-quickstarts
  5. teiid-documents

引言

Teiid 可以让你用 JDBC + SQL 来访问企业的任何数据,并可对这些不同源的数据进行联合查询。

环境准备

Teiid Server安装

  1. 下载并安装JDK

    建议下载安装Java 7以上,这里装的是jdk1.8.0_11。

  2. 下载并安装Teiid Server

    1. 下载安装的是集成wildfly的版本:teiid-9.3.5-wildfly-server.zip
    2. 下载后解压至C:\teiid-9.3.5,路径名不要有空格,所以不要装在Program Files中
    3. 命令行运行cd,进入Teiid安装目录的bin文件夹,比如:cd C:\teiid-9.3.5\bin
    4. 安装Teiid独立模式服务器,运行standalone.bat和jboss-cli.bat

      启动服务器,运行:

      1
      2
      C:\Users\Administrator>cd C:\teiid-9.3.5\bin
      C:\teiid-9.3.5\bin>standalone.bat

      接着打开另一个命令窗口,运行:

      1
      2
      3
      C:\Users\Administrator>cd C:\teiid-9.3.5\bin
      C:\teiid-9.3.5\bin>jboss-cli.bat --connect --file=scripts/teiid-standalone-mode-install.cli
      C:\teiid-9.3.5\bin>add-user.bat
5. 创建Teidd服务器admin用户和应用用户,运行add-user.bat

创建admin用户:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
C:\teiid-9.3.5\bin>add-user.bat
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a): a
Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : admin
The username 'admin' is easy to guess
Are you sure you want to add user 'admin' yes/no? yes
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated list,
or leave blank for none)[ ]:
About to add user 'admin' for realm 'ManagementRealm'
Is this correct yes/no? yes
Is this new user going to be used for one AS process to connect to another AS process?
yes/no? no
创建应用用户:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
C:\teiid-9.3.5\bin>add-user.bat
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a): b
Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : user
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated list,
or leave blank for none)[ ]: odata
About to add user 'user' for realm 'ApplicationRealm'
Is this correct yes/no? yes
Is this new user going to be used for one AS process to connect to another AS process?
yes/no? no
或者,可以直接快速创建:
1
2
3
4
5
C:\teiid-9.3.5\bin>add-user.bat -a -u dashboardAdmin -p password1! -g admin
C:\teiid-9.3.5\bin>add-user.bat -a -u teiidUser -p password1! -g user
C:\teiid-9.3.5\bin>add-user.bat -a -u restUser -p password1! -g rest
C:\teiid-9.3.5\bin>add-user.bat -a -u odataUser -p password1! -g odata
C:\teiid-9.3.5\bin>add-user.bat admin password1!

Teiid Server运行

命令窗口中启动 Teiid Server

打开命令窗口,进入Teiid安装目录bin下,运行standalone.bat:

1
2
C:\Users\Administrator>cd C:\teiid-9.3.5\bin
C:\teiid-9.3.5\bin>standalone.bat

如果不使用默认设置运行,在后面添加自定义设置的文件名名:-c {configuration.file}:

1
2
C:\Users\Administrator>cd C:\teiid-9.3.5\bin
C:\teiid-9.3.5\bin>standalone.bat -c standalone-teiid.xml

在浏览器中输入http://localhost:8080/进入到 JBoss 欢迎界面,点击界面上的“Administration Console”链接就看到管理界面。

Eclipse中启动 Teiid Server
  1. 在 Eclipse中安装JBOSS TOOLS插件
    1. 打开 Eclipse,选择 Help > Install New Software
    2. 地址栏输入如下地址:http://download.jboss.org/jbosstools/neon/stable/updates/
    3. 选择出现的所有插件,一直点击下一步,安装完毕后,重启Eclipse
  2. 在 Eclipse中配置 Teiid server
    1. 打开 Eclipse,在视图 Servers中右键选择 New > Server
    2. 选择对应于安装的 Server 类型,JBoss Community > WildFly 10.x,点下一步
    3. 选择 Create new runtime (next page),其他默认,点下一步
    4. 设置WildFly安装路径(C:\teiid-9.3.5),选择启动的配置文件standalone-teiid.xml,点完成
    5. 双击视图 Servers 中新建的 WildFly Server名,打开配置页面 Overview
    6. 配置 Management Login Credentials,使用之前设置的admin账号和密码
    7. 启动服务器,在Server配置页Teiid Instance中填入JDBC的用户名和密码,测试连接成功后保存设置

      JDBC的用户名和密码默认是 user:user,在$JBOSS_HOME/standalone/configuration/teiid-security-users.properties中配置。

虚拟数据库(VDB)建立

手动创建和部署VDB

适配不同数据源和生成虚拟数据库(VDB)需要维护好几个配置文件,可参考Teiid 基于数据联邦的集成方案中的最后部分“建立虚拟数据库”,比较复杂,一般创建和部署可使用Teiid提供的辅助工具Teiid Designer来完成。

Teiid Designer 配置
  1. 打开 Eclipse,选择 Help > Install New Software
  2. 地址栏输入如下地址:http://download.jboss.org/jbosstools/updates/release/neon/integration-stack/teiiddesigner/11.0.0.Final/
  3. 选择插件工具 Data Virtualization,一直点击下一步,安装完毕后,重启Eclipse
Teiid Designer 实践

测试案例为一个ORACLE测试库和一个CSV测试文件的数据联邦。以下为具体步骤:

  1. 启动与设置 Teiid Server
    1. 打开配置好 Teiid Designer 插件的 Eclipse,切换至 Teiid Designer 视图
    2. 点击Default Server下的No default server define,参考在 Eclipse中配置 Teiid server,设置 Teiid Server
    3. 完成后Default Server变成新建服务器,启动服务器,在Server配置页Teiid Instance中配置JDBC连接
  2. 创建 Teiid Model 工程
    1. 在 Teiid Designer 的 Model Explorer视图中,右击选择 New > Teiid Model Project
    2. 输入工程名后,点击下一步,Create Folders 界面勾选要创建的 Folders 后,完成创建
  3. 导入 ORACLE 数据源
    1. 在 Guides 中,选择 Model JDBC Source,下方窗口显示具体操作选项
    2. 双击 Define Teiid Model Project ,选择之前创建的 Teiid Model 工程
    3. 双击 Create JDBC connection,在弹出的窗口中,选择 Oracle 数据库,然后点下一步
    4. 选择 Oracle 驱动,配置好 Oracle 数据源的的 url、用户名、密码后,点击完成
    5. 双击 Create source model for JDBC data source,一直下一步,直到选择数据库和表
    6. 选择所需数据库和表,点下一步,自定义 Model Name(Oracle.xmi),其他默认,点击完成
    7. 双击 Preview Data,在弹框中选择需要 preview 的表或者 precedure ,结果显示在 SQL Result 框中

      运行Preview Data时,会跳出提示(Required data sources are not deployed …),点击Yes,数据源将在服务器创建和部署。

  4. 导入 CSV 数据源
    1. 在 Guides 中,选择 Model Flat File Source,下方窗口显示具体操作选项
    2. 双击 Define Teiid Model Project ,选择之前创建的 Teiid Model 工程
    3. 双击 Create Flat File connection,在弹出的窗口中,点击下一步,设置CSV所在目录,然后点击完成
    4. 双击 Create source model for local flat file source,点击下一步,直到选择CSV文件窗口
    5. 选择所需CSV文件,按照默认配置一直下一步,在view model definition 界面,设置含合法字符的table view ,点击Finish
    6. 双击 Preview Data,在弹框中选择需要 preview 的views目录下的表,结果将显示在 SQL Result 框中

      运行Preview Data时,会跳出提示(Required data sources are not deployed …),点击Yes,数据源将在服务器创建和部署。

  5. 生成虚拟数据库
    1. 在 Guides 中,选择之前设置过的 Model JDBC Source 或者 Model Flat File Source
    2. 双击 Define VDB > New… ,输入VDB名,Add添加之前导入的数据源(包括sources和views),点击Finish
    3. Define VDB 自动显示新建VDB,点击确定,Define VDB下的Edit VDB和Execute VDB自动关联对应VDB
  6. 部署虚拟数据库
    1. 在 Guides 中,选择生成虚拟数据库步骤所在的选项
    2. 双击 Execute VDB ,之前已自动关联VDB,点击OK运行后,自动跳转到Database Development视图中
    3. 在跳转的界面中,可选择对应类型和Database,查询之前设置的Oracle和CSV数据源中的数据

      运行Execute VDB,Teiid Designer会部署自动虚拟数据库(VDB)到服务器中。

注意:以上操作会修改Teiid Server中的配置,比如standalone-teiid.xml,故在命令行运行添加VDB后的服务器时,需使用以下命令:

1
2
C:\Users\Administrator>cd C:\teiid-9.3.5\bin
C:\teiid-9.3.5\bin>standalone.bat -c standalone-teiid.xml

问题

  1. 关于性能和时延

    Teiid是数据联邦的开源实现,优点是可将各类不同数据集合到一个虚拟数据源中,能方便和实时的获取数据;缺点是随着数据量增大,Teiid将面临性能方面的问题。

    Teiid 基于数据联邦的集成方案描述:

    与其它数据集成技术相比,数据联邦技术的明显优势在于获取数据的方便性和实时性。现在很多企业都在实现 SOA,SOA 的灵活性和敏捷性要求组织提供数据时应该具有更少的时延。以前的利用批量任务或者 ETL 的方式创建数据集市和数据仓库的方式的实时性都不太好,在很多应用场景中被数据联邦技术所取代。

    但是数据联邦技术访问数据是通过一个“联邦”视图(federation view)来实现的,视图是实时的。随着企业数据量的增大,性能问题是所有数据集成(Data Integration tools)都面临的问题,但是由于设计上的根本缺陷,数据联邦在这方面虽有很大进展,但是仍无法和另外一些数据集成技术相比。这种缺点制约了它在数据集成领域的适用性,虽然很多领域都使用了数据联邦技术,但是在关键的核心业务系统它的应用非常少。

    目前已实施数据联邦项目的特点如下:使用简单的有限的数据源,数据结果集不大,只读性的数据访问,数据质量要求简单。比较典型数据联邦产品有:BEA 的 AquaLogic Data Services Platform、IBM 公司的 Federation Server、Software AG 公司的 Enterprise Information Integration、Sybase 的 DataFederation 以及 Red Hat 公司的 JBoss MetaMatrix,其开源实现即 Teiid。

  2. 关于Teiid组件版本兼容

    Teiid Server版本是Teiid 9.3.5,Teiid Designer插件版本是11.0.1,使用Eclipse创建VDB时,经常有报错信息,可能是两者的兼容问题引起。

  3. 部分JDBC Source无法Create source model

    比如,创建SQL Server数据库source model时,JDBC Source连接和访问正常,但之后创建的source model无法显示列和数据,原因未知。

Top

Hexo+OSChina搭建免费个人博客

参考文档:免费个人博客搭建教程(详细-图文)

环境搭建

  1. Node.js安装

    参考:http://www.runoob.com/nodejs/nodejs-install-setup.html

    没有VPN的用户可通过在命令行窗口中执行以下代码切换npm的源:

    1
    npm config set registry http://registry.npm.taobao.org #切换npm为淘宝镜像
  2. Git安装

    参考:http://www.runoob.com/git/git-install-setup.html

  3. Hexo安装

    在命令行窗口中执行:

    1
    npm install -g hexo-cli #安装Hexo

    安装成功后可在命令窗口输入hexo,测试是否安装成功;

    hexo常用命令说明:https://hexo.io/zh-cn/docs/commands.html

本地运行Hexo

使用Git Bash执行下列命令,folder就是我们要放文档的地方,注意每次使用的命令行操作的时候要切换到这个目录下面。

1
2
3
4
$ cd <folder> #切换到项目目录下
$ hexo init #初始化,Hexo 默认在目前的文件夹建立网站
$ npm install #install before hexo generate
$ hexo generate #生成静态文件

执行$ npm install时,出现以下警告:

1
2
npm WARN optional Skipping failed optional dependency /browser-sync/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.8

参考:进行npm install时出现警告信息

fsevent是mac osx系统的,你是在win或者Linux下使用了 所以会有警告,忽略即可。

1
2
3
$ cd <folder> #切换到项目目录下
$ npm install #install before start blogging
$ hexo server #运行本地服务

浏览器输入http://localhost:4000就可以看到效果。

如果输入后无法访问,可能是Hexo默认端口(4000)被占用,使用另外未被占有端口运行:

1
$ hexo server -p 5000

浏览器输入自然变成:http://localhost:5000。

修改Hexo的主题

  1. 可以在官方收录的主题中去挑选:Hexo主题
  2. 主题下载后,将主题文件解压到Hexo项目的themes文件夹下面;
  3. 修改Hexo的配置文件_config.yml,将里面theme 对应的值改为之前下载的主题的文件夹名字;

    _config.yml配置文档:https://hexo.io/zh-cn/docs/configuration.html

    修改内容位置如下:

    1
    2
    3
    4
    # Extensions
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    theme: hexo-theme-twentyfifteen-wordpress-master

    注意:这里“: ”后面必须要有一个空格,而且这个空格要在英文输入法下,不然会报一些稀奇古怪的错。

  4. 执行以下代码,重新在本地启动项目:

    1
    2
    3
    4
    5
    $ cd <folder> #切换到项目目录下
    $ npm install #install before hexo generate
    $ hexo clean #清除缓存文件 (db.json) 和已生成的静态文件 (public)
    $ hexo generate #生成静态文件
    $ hexo server -p 5000 #运行本地服务
  5. 主题中也有一个叫_config.yml配置文件,其中主要是些与主题相关的设置,一般里面也都有注释。

更新博客文章

  1. 使用MarkDown来写博客文章,可使用有道笔记或者马克飞象之类的编辑器,链接:https://maxiang.io/

  2. 在编辑器里面写好文章后,复制或另存为.md文件, 与普通的.md文件不同,要在文件开头添加下面代码:

    1
    2
    3
    4
    5
    title: #文章标题
    date: #文章日期
    tags: #文章标签
    categories: #文章分类
    ---
  3. 将写好的.md文件放入Hexo项目的source目录下的_posts文件夹中;

  4. 执行以下代码,重新在本地启动项目:

    1
    2
    3
    4
    5
    $ cd <folder> #切换到项目目录下
    $ npm install #install before hexo generate
    $ hexo clean #清除缓存文件 (db.json) 和已生成的静态文件 (public)
    $ hexo generate #生成静态文件
    $ hexo server -p 5000 #运行本地服务
  5. 浏览器输入http://localhost:5000就可以看到效果。

    遇到问题:

    1. https://segmentfault.com/q/1010000000618915

      问题描述:

      我在_config.yml 中设置的菜单有Home,Archive,Category,About,

      可是只有Home和Archive点进去才有内容,Category和About都错Can’t found,还需要其他哪里设置才能生效么?

      解决方式:

      在命令行里面输入:

      1
      hexo new page "about"

      然后你会发现source里面多了个目录about,里面有个index.md文件。其实你也可以手动建立。页面的格式和文章一样。

      接着把链接加上,themes//_config.yml里面的menu一项,添加一行About: /about。

      完事。

      参考:https://www.zhihu.com/question/33324071

    2. 页面国际化:https://hexo.io/zh-cn/docs/internationalization.html

      1
      2
      3
      4
      5
      6
      7
      # Site
      title: Hexo
      subtitle:
      description:
      author: John Doe
      language: zh-CN #设置themes下对应语言文件名,如themes\landscape\languages\zh-CN.yml
      timezone:

发布静态Html文件到码云Pages上

参考文档:http://git.mydoc.io/?t=154714

  1. 注册一个码云帐号,并创建一个项目;

  2. 创建完项目后得到项目的Https的地址后面要用;

    这里借用一个插件来帮助我们完成代码上传的工作,安装 hexo-deployer-git。安装代码如下:

    npm install hexo-deployer-git –save #把public里面生成的文件推上到码云上。

  3. 配置项目根目录_config.yml文件,修改deploy的值;

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repository: https://{用户名}:{密码}@git.oschina.net/{用户名}/{用户名}.git
    branch: master
  4. 修改完后在命令窗口执行下面命令:

    1
    2
    cd <folder> #切换到项目目录下
    hexo deploy #一键部署功能
  5. 登录码云,查看之前创建的项目中出现了本地项目中public文件夹中的文件,部署成功;

  6. 打开项目的Pages页,启动码云的pages服务,访问链接为启用时显示的网站地址;

    如果你想以根目录的形式访问自己的静态网站,只需要建立一个与自己个性地址同名的项目即可,如 http://git.oschina.net/ipvb 这个用户,想要创建一个自己的站点,但不想以子目录的方式访问,想以ipvb.oschina.io直接访问,那么他就可以创建一个名字为ipvb的项目 http://git.oschina.net/ipvb/ipvb 部署完成后,就可以以 http://ipvb.oschina.io 进行访问了。

Top

Struts2+DataTables动态生成数据表

Server-side processing

  • 新建返回参数变量、部分发送参数变量,以及set和get方法
  • 在struts的action方法中,根据传入的发送参数,生成返回参数变量值
    image

Html Datatables JS代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<script type="text/javascript">
$(document).ready(function () {
$("#companies").dataTable({
"processing": true,
"serverSide": true,
"ajax": "selectOptionAjaxRequest.action",
"columnDefs": [ { orderable: true, targets: [0,1,2] }],
"sPaginationType": "full_numbers",
"bFilter": false,
"columns": [
{ "data": "name" },
{ "data": "address" },
{ "data": "town" }
]
});
});
</script>

Struts Action Java代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.ibm.cxl.action;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import jquery.datatables.model.Company;
import jquery.datatables.model.DataRepository;
public class RptConfig01Action extends ActionSupport {
private static final long serialVersionUID = -7160474110317441632L;
private Integer draw=0, recordsTotal=1, recordsFiltered = 0, length = 0, start=0;
private List<Company> data=new ArrayList<Company>();
public Integer getDraw() {
return draw;
}
public void setDraw(Integer draw) {
this.draw = draw;
}
public Integer getRecordsTotal() {
return recordsTotal;
}
public void setRecordsTotal(Integer recordsTotal) {
this.recordsTotal = recordsTotal;
}
public Integer getRecordsFiltered() {
return recordsFiltered;
}
public void setRecordsFiltered(Integer recordsFiltered) {
this.recordsFiltered = recordsFiltered;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Integer getStart() {
return start;
}
public void setStart(Integer start) {
this.start = start;
}
@SuppressWarnings("unchecked")
public String execute() throws Exception {
recordsTotal=DataRepository.GetCompanies().size();
recordsFiltered = recordsTotal;
//print all parameters from the action context
Map<String, Object> map = ActionContext.getContext().getParameters();
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("key:"+ key +" value: " + Arrays.toString((String[])value));
}
final int sortColumnIndex = Integer.parseInt(((String[]) map.get("order[0][column]"))[0]);
final int sortDirection = ((String[]) map.get("order[0][dir]"))[0].equals("asc") ? -1 : 1;
for(Company c : DataRepository.GetCompanies()){
data.add(c);
}
Collections.sort(data, new Comparator<Company>(){
@Override
public int compare(Company c1, Company c2) {
switch(sortColumnIndex){
case 0:
return c1.getName().compareTo(c2.getName()) * sortDirection;
case 1:
return c1.getAddress().compareTo(c2.getAddress()) * sortDirection;
case 2:
return c1.getTown().compareTo(c2.getTown()) * sortDirection;
}
return 0;
}
});
if(recordsTotal< start + length) {
data = data.subList(start, length);
} else {
data = data.subList(start, start + length);
}
return SUCCESS;
}
public List<Company> getData() {
return data;
}
public void setData(List<Company> data) {
this.data = data;
}
}
Top