Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
njgzx
dataease
Commits
7f3f5503
提交
7f3f5503
authored
10月 21, 2021
作者:
taojinlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 支持mongo
上级
a4d3dbe5
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
64 行增加
和
22 行删除
+64
-22
DatasourceTypes.java
...ava/io/dataease/datasource/constants/DatasourceTypes.java
+1
-0
MongodbConfiguration.java
...java/io/dataease/datasource/dto/MongodbConfiguration.java
+19
-0
JdbcProvider.java
...in/java/io/dataease/datasource/provider/JdbcProvider.java
+44
-22
没有找到文件。
backend/src/main/java/io/dataease/datasource/constants/DatasourceTypes.java
浏览文件 @
7f3f5503
...
...
@@ -9,6 +9,7 @@ public enum DatasourceTypes {
sqlServer
(
"sqlServer"
,
"sqlServer"
,
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
,
"\""
,
"\""
,
"\""
,
"\""
),
de_doris
(
"de_doris"
,
"de_doris"
,
"com.mysql.jdbc.Driver"
,
"`"
,
"`"
,
""
,
""
),
oracle
(
"oracle"
,
"oracle"
,
"oracle.jdbc.driver.OracleDriver"
,
"\""
,
"\""
,
"\""
,
"\""
),
mongo
(
"mongo"
,
"mongodb"
,
"com.mongodb.jdbc.MongoDriver"
,
"`"
,
"`"
,
"'"
,
"'"
),
ck
(
"ch"
,
"ch"
,
"ru.yandex.clickhouse.ClickHouseDriver"
,
"`"
,
"`"
,
"'"
,
"'"
),
es
(
"es"
,
"es"
,
""
,
"\""
,
"\""
,
"\""
,
"\""
);
...
...
backend/src/main/java/io/dataease/datasource/dto/MongodbConfiguration.java
0 → 100644
浏览文件 @
7f3f5503
package
io
.
dataease
.
datasource
.
dto
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
MongodbConfiguration
extends
JdbcConfiguration
{
private
String
driver
=
"mongodb.jdbc.MongoDriver"
;
private
String
connectionType
;
public
String
getJdbc
()
{
return
"jdbc:mongodb://HOSTNAME:PORT/DATABASE"
.
replace
(
"HOSTNAME"
,
getHost
().
trim
())
.
replace
(
"PORT"
,
getPort
().
toString
().
trim
())
.
replace
(
"DATABASE"
,
getDataBase
().
trim
());
}
}
backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java
浏览文件 @
7f3f5503
package
io
.
dataease
.
datasource
.
provider
;
import
com.alibaba.druid.filter.Filter
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.wall.WallFilter
;
import
com.google.gson.Gson
;
import
io.dataease.datasource.constants.DatasourceTypes
;
import
io.dataease.datasource.dto.*
;
...
...
@@ -9,9 +11,11 @@ import io.dataease.exception.DataEaseException;
import
io.dataease.i18n.Translator
;
import
io.dataease.provider.QueryProvider
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.beans.PropertyVetoException
;
import
java.io.File
;
import
java.io.IOException
;
...
...
@@ -25,6 +29,9 @@ public class JdbcProvider extends DatasourceProvider {
public
ExtendedJdbcClassLoader
extendedJdbcClassLoader
;
static
private
String
FILE_PATH
=
"/opt/dataease/drivers"
;
// @Resource
// private WallFilter wallFilter;
@PostConstruct
public
void
init
()
throws
Exception
{
ClassLoader
classLoader
=
Thread
.
currentThread
().
getContextClassLoader
();
...
...
@@ -63,7 +70,9 @@ public class JdbcProvider extends DatasourceProvider {
public
List
<
String
[]>
getData
(
DatasourceRequest
dsr
)
throws
Exception
{
List
<
String
[]>
list
=
new
LinkedList
<>();
try
(
Connection
connection
=
getConnectionFromPool
(
dsr
);
Statement
stat
=
connection
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
dsr
.
getQuery
())){
list
=
fetchResult
(
rs
);
if
(
dsr
.
isPageable
()
&&
dsr
.
getDatasource
().
getType
().
equalsIgnoreCase
(
DatasourceTypes
.
sqlServer
.
name
())){
Integer
realSize
=
dsr
.
getPage
()
*
dsr
.
getPageSize
()
<
list
.
size
()
?
dsr
.
getPage
()
*
dsr
.
getPageSize
():
list
.
size
();
list
=
list
.
subList
((
dsr
.
getPage
()
-
1
)
*
dsr
.
getPageSize
(),
realSize
);
...
...
@@ -318,6 +327,13 @@ public class JdbcProvider extends DatasourceProvider {
driver
=
chConfiguration
.
getDriver
();
jdbcurl
=
chConfiguration
.
getJdbc
();
break
;
case
mongo:
MongodbConfiguration
mongodbConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MongodbConfiguration
.
class
);
username
=
mongodbConfiguration
.
getUsername
();
password
=
mongodbConfiguration
.
getPassword
();
driver
=
mongodbConfiguration
.
getDriver
();
jdbcurl
=
mongodbConfiguration
.
getJdbc
();
break
;
default
:
break
;
}
...
...
@@ -332,13 +348,19 @@ public class JdbcProvider extends DatasourceProvider {
return
conn
;
}
private
void
addToPool
(
DatasourceRequest
datasourceRequest
)
throws
PropertyVetoException
{
DruidDataSource
dataSource
=
new
DruidDataSource
();
JdbcConfiguration
jdbcConfiguration
=
setCredential
(
datasourceRequest
,
dataSource
);
dataSource
.
setInitialSize
(
jdbcConfiguration
.
getInitialPoolSize
());
// 初始连接数
dataSource
.
setMinIdle
(
jdbcConfiguration
.
getMinPoolSize
());
// 最小连接数
dataSource
.
setMaxActive
(
jdbcConfiguration
.
getMaxPoolSize
());
// 最大连接数
jdbcConnection
.
put
(
datasourceRequest
.
getDatasource
().
getId
(),
dataSource
);
private
void
addToPool
(
DatasourceRequest
datasourceRequest
)
throws
PropertyVetoException
,
SQLException
{
DruidDataSource
druidDataSource
=
new
DruidDataSource
();
JdbcConfiguration
jdbcConfiguration
=
setCredential
(
datasourceRequest
,
druidDataSource
);
druidDataSource
.
setInitialSize
(
jdbcConfiguration
.
getInitialPoolSize
());
// 初始连接数
druidDataSource
.
setMinIdle
(
jdbcConfiguration
.
getMinPoolSize
());
// 最小连接数
druidDataSource
.
setMaxActive
(
jdbcConfiguration
.
getMaxPoolSize
());
// 最大连接数
if
(
datasourceRequest
.
getDatasource
().
getType
().
equals
(
DatasourceTypes
.
mongo
.
name
())){
WallFilter
wallFilter
=
new
WallFilter
();
wallFilter
.
setDbType
(
DatasourceTypes
.
mysql
.
name
());
druidDataSource
.
setProxyFilters
(
Arrays
.
asList
(
new
Filter
[]{
wallFilter
}));
}
druidDataSource
.
init
();
jdbcConnection
.
put
(
datasourceRequest
.
getDatasource
().
getId
(),
druidDataSource
);
}
...
...
@@ -351,47 +373,47 @@ public class JdbcProvider extends DatasourceProvider {
case
de_doris:
case
ds_doris:
MysqlConfiguration
mysqlConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MysqlConfiguration
.
class
);
dataSource
.
setUsername
(
mysqlConfiguration
.
getUsername
());
dataSource
.
setDriverClassLoader
(
extendedJdbcClassLoader
);
dataSource
.
setPassword
(
mysqlConfiguration
.
getPassword
());
dataSource
.
setUrl
(
mysqlConfiguration
.
getJdbc
());
dataSource
.
setDriverClassName
(
mysqlConfiguration
.
getDriver
());
jdbcConfiguration
=
mysqlConfiguration
;
break
;
case
sqlServer:
SqlServerConfiguration
sqlServerConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
SqlServerConfiguration
.
class
);
dataSource
.
setUsername
(
sqlServerConfiguration
.
getUsername
());
dataSource
.
setDriverClassLoader
(
extendedJdbcClassLoader
);
dataSource
.
setPassword
(
sqlServerConfiguration
.
getPassword
());
dataSource
.
setDriverClassName
(
sqlServerConfiguration
.
getDriver
());
dataSource
.
setUrl
(
sqlServerConfiguration
.
getJdbc
());
jdbcConfiguration
=
sqlServerConfiguration
;
break
;
case
oracle:
OracleConfiguration
oracleConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
OracleConfiguration
.
class
);
dataSource
.
setUsername
(
oracleConfiguration
.
getUsername
());
dataSource
.
setDriverClassLoader
(
extendedJdbcClassLoader
);
dataSource
.
setPassword
(
oracleConfiguration
.
getPassword
());
dataSource
.
setDriverClassName
(
oracleConfiguration
.
getDriver
());
dataSource
.
setUrl
(
oracleConfiguration
.
getJdbc
());
jdbcConfiguration
=
oracleConfiguration
;
break
;
case
pg:
PgConfiguration
pgConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
PgConfiguration
.
class
);
dataSource
.
setUsername
(
pgConfiguration
.
getUsername
());
dataSource
.
setDriverClassLoader
(
extendedJdbcClassLoader
);
dataSource
.
setPassword
(
pgConfiguration
.
getPassword
());
dataSource
.
setDriverClassName
(
pgConfiguration
.
getDriver
());
dataSource
.
setUrl
(
pgConfiguration
.
getJdbc
());
jdbcConfiguration
=
pgConfiguration
;
break
;
case
ck:
CHConfiguration
chConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
CHConfiguration
.
class
);
dataSource
.
setUsername
(
chConfiguration
.
getUsername
());
dataSource
.
setDriverClassLoader
(
extendedJdbcClassLoader
);
dataSource
.
setPassword
(
chConfiguration
.
getPassword
());
dataSource
.
setDriverClassName
(
chConfiguration
.
getDriver
());
dataSource
.
setUrl
(
chConfiguration
.
getJdbc
());
jdbcConfiguration
=
chConfiguration
;
break
;
case
mongo:
MongodbConfiguration
mongodbConfiguration
=
new
Gson
().
fromJson
(
datasourceRequest
.
getDatasource
().
getConfiguration
(),
MongodbConfiguration
.
class
);
dataSource
.
setDriverClassName
(
mongodbConfiguration
.
getDriver
());
dataSource
.
setUrl
(
mongodbConfiguration
.
getJdbc
());
jdbcConfiguration
=
mongodbConfiguration
;
break
;
default
:
break
;
}
dataSource
.
setUsername
(
jdbcConfiguration
.
getUsername
());
dataSource
.
setDriverClassLoader
(
extendedJdbcClassLoader
);
dataSource
.
setPassword
(
jdbcConfiguration
.
getPassword
());
return
jdbcConfiguration
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论