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
a8ee3197
Commit
a8ee3197
authored
Apr 18, 2020
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.0.0项目初始化
parent
8d379f97
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
212 additions
and
6 deletions
+212
-6
DataRedisSerializer.java
...cn/datax/common/redis/serializer/DataRedisSerializer.java
+40
-0
RedisCacheConfig.java
...n/datax/service/data/factory/config/RedisCacheConfig.java
+69
-0
DataSetServiceImpl.java
...service/data/factory/service/impl/DataSetServiceImpl.java
+8
-1
DataSourceServiceImpl.java
...vice/data/factory/service/impl/DataSourceServiceImpl.java
+8
-3
RedisCacheConfig.java
...cn/datax/service/data/market/config/RedisCacheConfig.java
+70
-0
ApiMaskServiceImpl.java
.../service/data/market/service/impl/ApiMaskServiceImpl.java
+9
-1
DataApiServiceImpl.java
.../service/data/market/service/impl/DataApiServiceImpl.java
+8
-1
No files found.
datax-common/datax-common-redis/src/main/java/cn/datax/common/redis/serializer/DataRedisSerializer.java
0 → 100644
View file @
a8ee3197
package
cn
.
datax
.
common
.
redis
.
serializer
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.data.redis.serializer.SerializationException
;
import
java.io.*
;
public
class
DataRedisSerializer
implements
RedisSerializer
<
Object
>
{
@Override
public
byte
[]
serialize
(
Object
o
)
throws
SerializationException
{
ByteArrayOutputStream
byteOut
=
new
ByteArrayOutputStream
();
ObjectOutputStream
objOut
;
try
{
objOut
=
new
ObjectOutputStream
(
byteOut
);
objOut
.
writeObject
(
o
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
byteOut
.
toByteArray
();
}
@Override
public
Object
deserialize
(
byte
[]
bytes
)
throws
SerializationException
{
if
(
bytes
==
null
)
{
return
null
;
}
ByteArrayInputStream
byteIn
=
new
ByteArrayInputStream
(
bytes
);
ObjectInputStream
objIn
;
Object
obj
;
try
{
objIn
=
new
ObjectInputStream
(
byteIn
);
obj
=
objIn
.
readObject
();
}
catch
(
IOException
|
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
obj
;
}
}
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/config/RedisCacheConfig.java
0 → 100644
View file @
a8ee3197
package
cn
.
datax
.
service
.
data
.
factory
.
config
;
import
cn.datax.common.redis.serializer.DataRedisSerializer
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.interceptor.KeyGenerator
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.serializer.RedisSerializationContext
;
import
java.lang.reflect.Method
;
import
java.time.Duration
;
import
java.util.HashMap
;
import
java.util.Map
;
@Configuration
@EnableCaching
public
class
RedisCacheConfig
extends
CachingConfigurerSupport
{
/**
* 在没有指定缓存Key的情况下,key生成策略
* @return
*/
@Bean
public
KeyGenerator
keyGenerator
()
{
return
new
KeyGenerator
()
{
@Override
public
Object
generate
(
Object
target
,
Method
method
,
Object
...
params
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
target
.
getClass
().
getName
());
sb
.
append
(
"#"
+
method
.
getName
());
for
(
Object
obj
:
params
)
{
sb
.
append
(
obj
.
toString
());
}
return
sb
.
toString
();
}
};
}
@Bean
public
CacheManager
cacheManager
(
RedisConnectionFactory
redisConnectionFactory
)
{
return
new
RedisCacheManager
(
RedisCacheWriter
.
nonLockingRedisCacheWriter
(
redisConnectionFactory
),
this
.
redisCacheConfigurationWithTtl
(
30
),
this
.
redisCacheConfigurationMap
()
);
}
private
Map
<
String
,
RedisCacheConfiguration
>
redisCacheConfigurationMap
()
{
Map
<
String
,
RedisCacheConfiguration
>
redisCacheConfigurationMap
=
new
HashMap
<>();
redisCacheConfigurationMap
.
put
(
"data:factory:sources"
,
redisCacheConfigurationWithTtl
(
30
));
redisCacheConfigurationMap
.
put
(
"data:factory:sets"
,
redisCacheConfigurationWithTtl
(
30
));
return
redisCacheConfigurationMap
;
}
private
RedisCacheConfiguration
redisCacheConfigurationWithTtl
(
Integer
minutes
)
{
DataRedisSerializer
serializer
=
new
DataRedisSerializer
();
RedisCacheConfiguration
redisCacheConfiguration
=
RedisCacheConfiguration
.
defaultCacheConfig
()
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
serializer
))
.
entryTtl
(
Duration
.
ofMinutes
(
minutes
));
return
redisCacheConfiguration
;
}
}
\ No newline at end of file
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/service/impl/DataSetServiceImpl.java
View file @
a8ee3197
...
...
@@ -8,6 +8,10 @@ import cn.datax.service.data.factory.mapstruct.DataSetMapper;
import
cn.datax.service.data.factory.dao.DataSetDao
;
import
cn.datax.common.base.BaseServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -20,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author yuwei
* @since 2020-03-20
*/
@CacheConfig
(
cacheNames
=
"data:factory:sets"
)
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
DataSetServiceImpl
extends
BaseServiceImpl
<
DataSetDao
,
DataSetEntity
>
implements
DataSetService
{
...
...
@@ -37,6 +42,7 @@ public class DataSetServiceImpl extends BaseServiceImpl<DataSetDao, DataSetEntit
dataSetDao
.
insert
(
dataSet
);
}
@CachePut
(
key
=
"#p0.id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateDataSet
(
DataSetDto
dataSetDto
)
{
...
...
@@ -44,12 +50,13 @@ public class DataSetServiceImpl extends BaseServiceImpl<DataSetDao, DataSetEntit
dataSetDao
.
updateById
(
dataSet
);
}
@
Override
@
Cacheable
(
key
=
"#id"
,
unless
=
"#result == null"
)
public
DataSetVo
getDataSetById
(
String
id
)
{
DataSetEntity
dataSetEntity
=
super
.
getById
(
id
);
return
dataSetMapper
.
toVO
(
dataSetEntity
);
}
@CacheEvict
(
key
=
"#id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteDataSetById
(
String
id
)
{
...
...
datax-modules/data-factory-service-parent/data-factory-service/src/main/java/cn/datax/service/data/factory/service/impl/DataSourceServiceImpl.java
View file @
a8ee3197
...
...
@@ -12,12 +12,14 @@ import cn.datax.service.data.factory.service.DataSourceService;
import
cn.datax.service.data.factory.mapstruct.DataSourceMapper
;
import
cn.datax.common.base.BaseServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.Serializable
;
/**
* <p>
* 数据源信息表 服务实现类
...
...
@@ -26,6 +28,7 @@ import java.io.Serializable;
* @author yuwei
* @since 2020-03-14
*/
@CacheConfig
(
cacheNames
=
"data:factory:sources"
)
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
DataSourceServiceImpl
extends
BaseServiceImpl
<
DataSourceDao
,
DataSourceEntity
>
implements
DataSourceService
{
...
...
@@ -46,6 +49,7 @@ public class DataSourceServiceImpl extends BaseServiceImpl<DataSourceDao, DataSo
dataSourceDao
.
insert
(
dataSource
);
}
@CachePut
(
key
=
"#p0.id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateDataSource
(
DataSourceDto
dataSourceDto
)
{
...
...
@@ -53,12 +57,13 @@ public class DataSourceServiceImpl extends BaseServiceImpl<DataSourceDao, DataSo
dataSourceDao
.
updateById
(
dataSource
);
}
@
Override
@
Cacheable
(
key
=
"#id"
,
unless
=
"#result == null"
)
public
DataSourceVo
getDataSourceById
(
String
id
)
{
DataSourceEntity
dataSourceEntity
=
super
.
getById
(
id
);
return
dataSourceMapper
.
toVO
(
dataSourceEntity
);
}
@CacheEvict
(
key
=
"#id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteDataSourceById
(
String
id
)
{
...
...
datax-modules/data-market-service-parent/data-market-service/src/main/java/cn/datax/service/data/market/config/RedisCacheConfig.java
0 → 100644
View file @
a8ee3197
package
cn
.
datax
.
service
.
data
.
market
.
config
;
import
cn.datax.common.redis.serializer.DataRedisSerializer
;
import
com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.interceptor.KeyGenerator
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.serializer.RedisSerializationContext
;
import
java.lang.reflect.Method
;
import
java.time.Duration
;
import
java.util.HashMap
;
import
java.util.Map
;
@Configuration
@EnableCaching
public
class
RedisCacheConfig
extends
CachingConfigurerSupport
{
/**
* 在没有指定缓存Key的情况下,key生成策略
* @return
*/
@Bean
public
KeyGenerator
keyGenerator
()
{
return
new
KeyGenerator
()
{
@Override
public
Object
generate
(
Object
target
,
Method
method
,
Object
...
params
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
target
.
getClass
().
getName
());
sb
.
append
(
"#"
+
method
.
getName
());
for
(
Object
obj
:
params
)
{
sb
.
append
(
obj
.
toString
());
}
return
sb
.
toString
();
}
};
}
@Bean
public
CacheManager
cacheManager
(
RedisConnectionFactory
redisConnectionFactory
)
{
return
new
RedisCacheManager
(
RedisCacheWriter
.
nonLockingRedisCacheWriter
(
redisConnectionFactory
),
this
.
redisCacheConfigurationWithTtl
(
30
),
this
.
redisCacheConfigurationMap
()
);
}
private
Map
<
String
,
RedisCacheConfiguration
>
redisCacheConfigurationMap
()
{
Map
<
String
,
RedisCacheConfiguration
>
redisCacheConfigurationMap
=
new
HashMap
<>();
redisCacheConfigurationMap
.
put
(
"data:market:apis"
,
redisCacheConfigurationWithTtl
(
30
));
redisCacheConfigurationMap
.
put
(
"data:market:api:masks"
,
redisCacheConfigurationWithTtl
(
30
));
return
redisCacheConfigurationMap
;
}
private
RedisCacheConfiguration
redisCacheConfigurationWithTtl
(
Integer
minutes
)
{
DataRedisSerializer
serializer
=
new
DataRedisSerializer
();
RedisCacheConfiguration
redisCacheConfiguration
=
RedisCacheConfiguration
.
defaultCacheConfig
()
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
serializer
))
.
entryTtl
(
Duration
.
ofMinutes
(
minutes
));
return
redisCacheConfiguration
;
}
}
\ No newline at end of file
datax-modules/data-market-service-parent/data-market-service/src/main/java/cn/datax/service/data/market/service/impl/ApiMaskServiceImpl.java
View file @
a8ee3197
...
...
@@ -9,6 +9,10 @@ import cn.datax.service.data.market.mapstruct.ApiMaskMapper;
import
cn.datax.service.data.market.service.ApiMaskService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -21,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author yuwei
* @since 2020-04-14
*/
@CacheConfig
(
cacheNames
=
"data:api:masks"
)
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
ApiMaskServiceImpl
extends
BaseServiceImpl
<
ApiMaskDao
,
ApiMaskEntity
>
implements
ApiMaskService
{
...
...
@@ -38,6 +43,7 @@ public class ApiMaskServiceImpl extends BaseServiceImpl<ApiMaskDao, ApiMaskEntit
apiMaskDao
.
insert
(
apiMask
);
}
@CachePut
(
key
=
"#p0.id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateApiMask
(
ApiMaskDto
apiMaskDto
)
{
...
...
@@ -45,18 +51,20 @@ public class ApiMaskServiceImpl extends BaseServiceImpl<ApiMaskDao, ApiMaskEntit
apiMaskDao
.
updateById
(
apiMask
);
}
@
Override
@
Cacheable
(
key
=
"#id"
)
public
ApiMaskVo
getApiMaskById
(
String
id
)
{
ApiMaskEntity
apiMaskEntity
=
super
.
getById
(
id
);
return
apiMaskMapper
.
toVO
(
apiMaskEntity
);
}
@Cacheable
(
key
=
"#apiId"
)
@Override
public
ApiMaskVo
getApiMaskByApiId
(
String
apiId
)
{
ApiMaskEntity
apiMaskEntity
=
apiMaskDao
.
selectOne
(
new
QueryWrapper
<
ApiMaskEntity
>().
eq
(
"api_id"
,
apiId
));
return
apiMaskMapper
.
toVO
(
apiMaskEntity
);
}
@CacheEvict
(
key
=
"#id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteApiMaskById
(
String
id
)
{
...
...
datax-modules/data-market-service-parent/data-market-service/src/main/java/cn/datax/service/data/market/service/impl/DataApiServiceImpl.java
View file @
a8ee3197
...
...
@@ -28,6 +28,10 @@ import net.sf.jsqlparser.util.SelectUtils;
import
net.sf.jsqlparser.util.deparser.ExpressionDeParser
;
import
net.sf.jsqlparser.util.deparser.SelectDeParser
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -44,6 +48,7 @@ import java.util.stream.Collectors;
* @author yuwei
* @since 2020-03-31
*/
@CacheConfig
(
cacheNames
=
"data:market:apis"
)
@Slf4j
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
...
...
@@ -62,6 +67,7 @@ public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntit
dataApiDao
.
insert
(
dataApi
);
}
@CachePut
(
key
=
"#p0.id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateDataApi
(
DataApiDto
dataApiDto
)
{
...
...
@@ -83,12 +89,13 @@ public class DataApiServiceImpl extends BaseServiceImpl<DataApiDao, DataApiEntit
return
dataApi
;
}
@
Override
@
Cacheable
(
key
=
"#id"
,
unless
=
"#result == null"
)
public
DataApiVo
getDataApiById
(
String
id
)
{
DataApiEntity
dataApiEntity
=
super
.
getById
(
id
);
return
dataApiMapper
.
toVO
(
dataApiEntity
);
}
@CacheEvict
(
key
=
"#id"
)
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteDataApiById
(
String
id
)
{
...
...
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