Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
datax-cloud
Commits
7d6f4e3c
Commit
7d6f4e3c
authored
Mar 17, 2020
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
cc3a7120
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
13 deletions
+53
-13
EnableDatabase.java
...a/cn/datax/common/database/annotation/EnableDatabase.java
+14
-0
AutoConfiguration.java
...va/cn/datax/common/database/config/AutoConfiguration.java
+21
-0
DataFactoryApplication.java
...cn/datax/service/data/factory/DataFactoryApplication.java
+2
-0
DataSourceController.java
...service/data/factory/controller/DataSourceController.java
+9
-1
DataSourceService.java
...datax/service/data/factory/service/DataSourceService.java
+2
-1
DataSourceServiceImpl.java
...vice/data/factory/service/impl/DataSourceServiceImpl.java
+5
-11
No files found.
datax-common/datax-common-database/src/main/java/cn/datax/common/database/annotation/EnableDatabase.java
0 → 100644
View file @
7d6f4e3c
package
cn
.
datax
.
common
.
database
.
annotation
;
import
cn.datax.common.database.config.AutoConfiguration
;
import
org.springframework.context.annotation.Import
;
import
java.lang.annotation.*
;
@Target
({
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@Import
({
AutoConfiguration
.
class
})
public
@interface
EnableDatabase
{
}
datax-common/datax-common-database/src/main/java/cn/datax/common/database/config/AutoConfiguration.java
0 → 100644
View file @
7d6f4e3c
package
cn
.
datax
.
common
.
database
.
config
;
import
cn.datax.common.database.DataSourceFactory
;
import
cn.datax.common.database.datasource.CacheDataSourceFactoryBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
/**
* 扫描注入bean
*
* @author yuwei
* @since 2019/10/30
*/
@ComponentScan
({
"cn.datax.common.database"
})
public
class
AutoConfiguration
{
@Bean
public
DataSourceFactory
dataSourceFactory
(){
return
new
CacheDataSourceFactoryBean
();
}
}
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/DataFactoryApplication.java
View file @
7d6f4e3c
package
cn
.
datax
.
service
.
data
.
factory
;
package
cn
.
datax
.
service
.
data
.
factory
;
import
cn.datax.common.database.annotation.EnableDatabase
;
import
cn.datax.common.log.annotation.EnableDataLog
;
import
cn.datax.common.log.annotation.EnableDataLog
;
import
cn.datax.common.mybatis.annotation.EnableDataMybatis
;
import
cn.datax.common.mybatis.annotation.EnableDataMybatis
;
import
cn.datax.common.redis.annotation.EnableDataRedis
;
import
cn.datax.common.redis.annotation.EnableDataRedis
;
...
@@ -13,6 +14,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
...
@@ -13,6 +14,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
@EnableDataRedis
@EnableDataRedis
@EnableDataLog
@EnableDataLog
@EnableDataFeignClients
@EnableDataFeignClients
@EnableDatabase
@SpringCloudApplication
@SpringCloudApplication
public
class
DataFactoryApplication
{
public
class
DataFactoryApplication
{
...
...
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/controller/DataSourceController.java
View file @
7d6f4e3c
...
@@ -2,6 +2,7 @@ package cn.datax.service.data.factory.controller;
...
@@ -2,6 +2,7 @@ package cn.datax.service.data.factory.controller;
import
cn.datax.common.core.JsonPage
;
import
cn.datax.common.core.JsonPage
;
import
cn.datax.common.core.R
;
import
cn.datax.common.core.R
;
import
cn.datax.common.database.DbQuery
;
import
cn.datax.common.validate.ValidationGroups
;
import
cn.datax.common.validate.ValidationGroups
;
import
cn.datax.service.data.factory.api.dto.DataSourceDto
;
import
cn.datax.service.data.factory.api.dto.DataSourceDto
;
import
cn.datax.service.data.factory.api.entity.DataSourceEntity
;
import
cn.datax.service.data.factory.api.entity.DataSourceEntity
;
...
@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
import
cn.datax.common.base.BaseController
;
import
cn.datax.common.base.BaseController
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -140,7 +142,13 @@ public class DataSourceController extends BaseController {
...
@@ -140,7 +142,13 @@ public class DataSourceController extends BaseController {
@ApiImplicitParam
(
name
=
"dataSource"
,
value
=
"详细实体dataSource"
,
required
=
true
,
dataType
=
"DataSourceDto"
)
@ApiImplicitParam
(
name
=
"dataSource"
,
value
=
"详细实体dataSource"
,
required
=
true
,
dataType
=
"DataSourceDto"
)
@PostMapping
(
"/checkConnection"
)
@PostMapping
(
"/checkConnection"
)
public
R
checkConnection
(
@RequestBody
@Validated
({
ValidationGroups
.
Insert
.
class
})
DataSourceDto
dataSource
)
{
public
R
checkConnection
(
@RequestBody
@Validated
({
ValidationGroups
.
Insert
.
class
})
DataSourceDto
dataSource
)
{
Boolean
valid
=
dataSourceService
.
checkConnection
(
dataSource
);
DbQuery
dbQuery
=
dataSourceService
.
checkConnection
(
dataSource
);
boolean
valid
=
false
;
try
{
valid
=
dbQuery
.
valid
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
valid
?
R
.
ok
()
:
R
.
error
(
"数据库连接有误,请检查数据库配置是否正确"
);
return
valid
?
R
.
ok
()
:
R
.
error
(
"数据库连接有误,请检查数据库配置是否正确"
);
}
}
}
}
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/service/DataSourceService.java
View file @
7d6f4e3c
package
cn
.
datax
.
service
.
data
.
factory
.
service
;
package
cn
.
datax
.
service
.
data
.
factory
.
service
;
import
cn.datax.common.database.DbQuery
;
import
cn.datax.service.data.factory.api.dto.DataSourceDto
;
import
cn.datax.service.data.factory.api.dto.DataSourceDto
;
import
cn.datax.service.data.factory.api.entity.DataSourceEntity
;
import
cn.datax.service.data.factory.api.entity.DataSourceEntity
;
import
cn.datax.common.base.BaseService
;
import
cn.datax.common.base.BaseService
;
...
@@ -23,7 +24,7 @@ public interface DataSourceService extends BaseService<DataSourceEntity> {
...
@@ -23,7 +24,7 @@ public interface DataSourceService extends BaseService<DataSourceEntity> {
void
deleteDataSourceById
(
String
id
);
void
deleteDataSourceById
(
String
id
);
Boolean
checkConnection
(
DataSourceDto
dataSource
);
DbQuery
checkConnection
(
DataSourceDto
dataSource
);
List
<
Map
<
String
,
Object
>>
getDbTypes
();
List
<
Map
<
String
,
Object
>>
getDbTypes
();
}
}
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/service/impl/DataSourceServiceImpl.java
View file @
7d6f4e3c
...
@@ -4,7 +4,6 @@ import cn.datax.common.database.DataSourceFactory;
...
@@ -4,7 +4,6 @@ import cn.datax.common.database.DataSourceFactory;
import
cn.datax.common.database.DbQuery
;
import
cn.datax.common.database.DbQuery
;
import
cn.datax.common.database.constants.DbQueryProperty
;
import
cn.datax.common.database.constants.DbQueryProperty
;
import
cn.datax.common.database.constants.DbType
;
import
cn.datax.common.database.constants.DbType
;
import
cn.datax.common.database.datasource.CacheDataSourceFactoryBean
;
import
cn.datax.service.data.factory.api.dto.DataSourceDto
;
import
cn.datax.service.data.factory.api.dto.DataSourceDto
;
import
cn.datax.service.data.factory.api.entity.DbSchema
;
import
cn.datax.service.data.factory.api.entity.DbSchema
;
import
cn.datax.service.data.factory.api.entity.DataSourceEntity
;
import
cn.datax.service.data.factory.api.entity.DataSourceEntity
;
...
@@ -17,7 +16,6 @@ import org.springframework.stereotype.Service;
...
@@ -17,7 +16,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.sql.SQLException
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -42,6 +40,9 @@ public class DataSourceServiceImpl extends BaseServiceImpl<DataSourceDao, DataSo
...
@@ -42,6 +40,9 @@ public class DataSourceServiceImpl extends BaseServiceImpl<DataSourceDao, DataSo
@Autowired
@Autowired
private
DataSourceMapper
dataSourceMapper
;
private
DataSourceMapper
dataSourceMapper
;
@Autowired
private
DataSourceFactory
dataSourceFactory
;
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
saveDataSource
(
DataSourceDto
dataSourceDto
)
{
public
void
saveDataSource
(
DataSourceDto
dataSourceDto
)
{
...
@@ -63,19 +64,12 @@ public class DataSourceServiceImpl extends BaseServiceImpl<DataSourceDao, DataSo
...
@@ -63,19 +64,12 @@ public class DataSourceServiceImpl extends BaseServiceImpl<DataSourceDao, DataSo
}
}
@Override
@Override
public
Boolean
checkConnection
(
DataSourceDto
dataSourceDto
)
{
public
DbQuery
checkConnection
(
DataSourceDto
dataSourceDto
)
{
DataSourceEntity
dataSource
=
dataSourceMapper
.
toEntity
(
dataSourceDto
);
DataSourceEntity
dataSource
=
dataSourceMapper
.
toEntity
(
dataSourceDto
);
DbSchema
dbSchema
=
dataSource
.
getDbSchema
();
DbSchema
dbSchema
=
dataSource
.
getDbSchema
();
DataSourceFactory
dataSourceFactory
=
new
CacheDataSourceFactoryBean
();
DbQueryProperty
dbQueryProperty
=
new
DbQueryProperty
(
dataSource
.
getDbType
(),
dbSchema
.
getJdbcUrl
(),
dbSchema
.
getUsername
(),
dbSchema
.
getPassword
());
DbQueryProperty
dbQueryProperty
=
new
DbQueryProperty
(
dataSource
.
getDbType
(),
dbSchema
.
getJdbcUrl
(),
dbSchema
.
getUsername
(),
dbSchema
.
getPassword
());
DbQuery
dbQuery
=
dataSourceFactory
.
createDbQuery
(
dbQueryProperty
);
DbQuery
dbQuery
=
dataSourceFactory
.
createDbQuery
(
dbQueryProperty
);
boolean
valid
=
false
;
return
dbQuery
;
try
{
valid
=
dbQuery
.
valid
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
valid
;
}
}
@Override
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment