Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
njgzx
dataease
Commits
e8e8a9c3
提交
e8e8a9c3
authored
5月 17, 2021
作者:
junjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(backend):jdbc add doris
上级
83fa0950
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
53 行增加
和
32 行删除
+53
-32
JdbcProvider.java
...in/java/io/dataease/datasource/provider/JdbcProvider.java
+53
-32
没有找到文件。
backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java
浏览文件 @
e8e8a9c3
...
@@ -20,6 +20,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -20,6 +20,7 @@ public class JdbcProvider extends DatasourceProvider {
private
static
Map
<
String
,
ComboPooledDataSource
>
jdbcConnection
=
new
HashMap
<>();
private
static
Map
<
String
,
ComboPooledDataSource
>
jdbcConnection
=
new
HashMap
<>();
private
static
int
initPoolSize
=
5
;
private
static
int
initPoolSize
=
5
;
private
static
int
maxConnections
=
200
;
private
static
int
maxConnections
=
200
;
@Override
@Override
public
List
<
String
[]>
getData
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
public
List
<
String
[]>
getData
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
List
<
String
[]>
list
=
new
LinkedList
<>();
List
<
String
[]>
list
=
new
LinkedList
<>();
...
@@ -33,7 +34,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -33,7 +34,7 @@ public class JdbcProvider extends DatasourceProvider {
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
connection
.
close
();
connection
.
close
();
}
}
return
list
;
return
list
;
...
@@ -50,7 +51,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -50,7 +51,7 @@ public class JdbcProvider extends DatasourceProvider {
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
connection
.
close
();
connection
.
close
();
}
}
}
}
...
@@ -68,7 +69,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -68,7 +69,7 @@ public class JdbcProvider extends DatasourceProvider {
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
connection
.
close
();
connection
.
close
();
}
}
}
}
...
@@ -108,7 +109,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -108,7 +109,7 @@ public class JdbcProvider extends DatasourceProvider {
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
connection
.
close
();
connection
.
close
();
}
}
}
}
...
@@ -133,7 +134,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -133,7 +134,7 @@ public class JdbcProvider extends DatasourceProvider {
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
connection
.
close
();
connection
.
close
();
}
}
}
}
...
@@ -173,7 +174,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -173,7 +174,7 @@ public class JdbcProvider extends DatasourceProvider {
return
tables
;
return
tables
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR: "
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR: "
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
con
.
close
();
con
.
close
();
}
}
}
}
...
@@ -209,7 +210,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -209,7 +210,7 @@ public class JdbcProvider extends DatasourceProvider {
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
connection
.
close
();
connection
.
close
();
}
}
return
list
;
return
list
;
...
@@ -227,7 +228,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -227,7 +228,7 @@ public class JdbcProvider extends DatasourceProvider {
ps
.
close
();
ps
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR: "
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR: "
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
con
.
close
();
con
.
close
();
}
}
}
}
...
@@ -236,20 +237,21 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -236,20 +237,21 @@ public class JdbcProvider extends DatasourceProvider {
public
Long
count
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
public
Long
count
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
Connection
con
=
null
;
Connection
con
=
null
;
try
{
try
{
con
=
getConnectionFromPool
(
datasourceRequest
);
Statement
ps
=
con
.
createStatement
();
con
=
getConnectionFromPool
(
datasourceRequest
);
Statement
ps
=
con
.
createStatement
();
ResultSet
resultSet
=
ps
.
executeQuery
(
datasourceRequest
.
getQuery
());
ResultSet
resultSet
=
ps
.
executeQuery
(
datasourceRequest
.
getQuery
());
while
(
resultSet
.
next
())
{
while
(
resultSet
.
next
())
{
return
resultSet
.
getLong
(
1
);
return
resultSet
.
getLong
(
1
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"ERROR: "
+
e
.
getMessage
(),
e
);
throw
new
Exception
(
"ERROR: "
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
con
.
close
();
con
.
close
();
}
}
return
0L
;
return
0L
;
}
}
private
Connection
getConnectionFromPool
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
private
Connection
getConnectionFromPool
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
ComboPooledDataSource
dataSource
=
jdbcConnection
.
get
(
datasourceRequest
.
getDatasource
().
getId
());
ComboPooledDataSource
dataSource
=
jdbcConnection
.
get
(
datasourceRequest
.
getDatasource
().
getId
());
if
(
dataSource
==
null
)
{
if
(
dataSource
==
null
)
{
initDataSource
(
datasourceRequest
);
initDataSource
(
datasourceRequest
);
...
@@ -260,7 +262,7 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -260,7 +262,7 @@ public class JdbcProvider extends DatasourceProvider {
}
}
@Override
@Override
public
void
initDataSource
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
public
void
initDataSource
(
DatasourceRequest
datasourceRequest
)
throws
Exception
{
ComboPooledDataSource
dataSource
=
jdbcConnection
.
get
(
datasourceRequest
.
getDatasource
().
getId
());
ComboPooledDataSource
dataSource
=
jdbcConnection
.
get
(
datasourceRequest
.
getDatasource
().
getId
());
if
(
dataSource
==
null
)
{
if
(
dataSource
==
null
)
{
dataSource
=
new
ComboPooledDataSource
();
dataSource
=
new
ComboPooledDataSource
();
...
@@ -298,6 +300,13 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -298,6 +300,13 @@ public class JdbcProvider extends DatasourceProvider {
driver
=
mysqlConfigration
.
getDriver
();
driver
=
mysqlConfigration
.
getDriver
();
jdbcurl
=
mysqlConfigration
.
getJdbc
();
jdbcurl
=
mysqlConfigration
.
getJdbc
();
break
;
break
;
case
doris:
MysqlConfigration
dorisConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
username
=
dorisConfigration
.
getUsername
();
password
=
dorisConfigration
.
getPassword
();
driver
=
dorisConfigration
.
getDriver
();
jdbcurl
=
dorisConfigration
.
getJdbc
();
break
;
case
sqlServer:
case
sqlServer:
SqlServerConfigration
sqlServerConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfigration
.
class
);
SqlServerConfigration
sqlServerConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfigration
.
class
);
username
=
sqlServerConfigration
.
getUsername
();
username
=
sqlServerConfigration
.
getUsername
();
...
@@ -319,26 +328,33 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -319,26 +328,33 @@ public class JdbcProvider extends DatasourceProvider {
}
}
private
void
setCredential
(
DatasourceRequest
datasourceRequest
,
ComboPooledDataSource
dataSource
)
throws
PropertyVetoException
{
private
void
setCredential
(
DatasourceRequest
datasourceRequest
,
ComboPooledDataSource
dataSource
)
throws
PropertyVetoException
{
DatasourceTypes
datasourceType
=
DatasourceTypes
.
valueOf
(
datasourceRequest
.
getDatasource
().
getType
());
DatasourceTypes
datasourceType
=
DatasourceTypes
.
valueOf
(
datasourceRequest
.
getDatasource
().
getType
());
switch
(
datasourceType
)
{
switch
(
datasourceType
)
{
case
mysql:
case
mysql:
MysqlConfigration
mysqlConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
MysqlConfigration
mysqlConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
dataSource
.
setUser
(
mysqlConfigration
.
getUsername
());
dataSource
.
setUser
(
mysqlConfigration
.
getUsername
());
dataSource
.
setDriverClass
(
mysqlConfigration
.
getDriver
());
dataSource
.
setDriverClass
(
mysqlConfigration
.
getDriver
());
dataSource
.
setPassword
(
mysqlConfigration
.
getPassword
());
dataSource
.
setPassword
(
mysqlConfigration
.
getPassword
());
dataSource
.
setJdbcUrl
(
mysqlConfigration
.
getJdbc
());
dataSource
.
setJdbcUrl
(
mysqlConfigration
.
getJdbc
());
break
;
break
;
case
sqlServer:
case
doris:
SqlServerConfigration
sqlServerConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfigration
.
class
);
MysqlConfigration
dorisConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
dataSource
.
setUser
(
sqlServerConfigration
.
getUsername
());
dataSource
.
setUser
(
dorisConfigration
.
getUsername
());
dataSource
.
setDriverClass
(
sqlServerConfigration
.
getDriver
());
dataSource
.
setDriverClass
(
dorisConfigration
.
getDriver
());
dataSource
.
setPassword
(
sqlServerConfigration
.
getPassword
());
dataSource
.
setPassword
(
dorisConfigration
.
getPassword
());
dataSource
.
setJdbcUrl
(
sqlServerConfigration
.
getJdbc
());
dataSource
.
setJdbcUrl
(
dorisConfigration
.
getJdbc
());
break
;
break
;
default
:
case
sqlServer:
break
;
SqlServerConfigration
sqlServerConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfigration
.
class
);
}
dataSource
.
setUser
(
sqlServerConfigration
.
getUsername
());
dataSource
.
setDriverClass
(
sqlServerConfigration
.
getDriver
());
dataSource
.
setPassword
(
sqlServerConfigration
.
getPassword
());
dataSource
.
setJdbcUrl
(
sqlServerConfigration
.
getJdbc
());
break
;
default
:
break
;
}
}
}
private
String
getDatabase
(
DatasourceRequest
datasourceRequest
)
{
private
String
getDatabase
(
DatasourceRequest
datasourceRequest
)
{
...
@@ -347,6 +363,9 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -347,6 +363,9 @@ public class JdbcProvider extends DatasourceProvider {
case
mysql:
case
mysql:
MysqlConfigration
mysqlConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
MysqlConfigration
mysqlConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
return
mysqlConfigration
.
getDataBase
();
return
mysqlConfigration
.
getDataBase
();
case
doris:
MysqlConfigration
dorisConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfigration
.
class
);
return
dorisConfigration
.
getDataBase
();
case
sqlServer:
case
sqlServer:
SqlServerConfigration
sqlServerConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfigration
.
class
);
SqlServerConfigration
sqlServerConfigration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfigration
.
class
);
return
sqlServerConfigration
.
getDataBase
();
return
sqlServerConfigration
.
getDataBase
();
...
@@ -360,6 +379,8 @@ public class JdbcProvider extends DatasourceProvider {
...
@@ -360,6 +379,8 @@ public class JdbcProvider extends DatasourceProvider {
switch
(
datasourceType
)
{
switch
(
datasourceType
)
{
case
mysql:
case
mysql:
return
"show tables;"
;
return
"show tables;"
;
case
doris:
return
"show tables;"
;
case
sqlServer:
case
sqlServer:
return
"SELECT TABLE_NAME FROM fit2cloud2.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';"
;
return
"SELECT TABLE_NAME FROM fit2cloud2.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';"
;
default
:
default
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论