Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
634d315f
Commit
634d315f
authored
Dec 25, 2019
by
李秋伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature_protocol' into 'master'
优化提示信息 See merge request mall/arch/matrix!44
parents
d8e55826
511ef2ca
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
32 deletions
+32
-32
FieldUtil.java
common-util/src/main/java/com/secoo/mall/common/util/reflect/FieldUtil.java
+7
-0
ApolloDataSourceProvider.java
matrix-datasource/matrix-datasource-core/src/main/java/com/secoo/mall/datasource/provider/ApolloDataSourceProvider.java
+24
-31
MatrixDruidDataSourceProperties.java
matrix-datasource/matrix-datasource-druid/src/main/java/com/secoo/mall/datasource/properties/MatrixDruidDataSourceProperties.java
+1
-1
No files found.
common-util/src/main/java/com/secoo/mall/common/util/reflect/FieldUtil.java
0 → 100644
View file @
634d315f
package
com
.
secoo
.
mall
.
common
.
util
.
reflect
;
import
org.apache.commons.lang3.reflect.FieldUtils
;
public
class
FieldUtil
extends
FieldUtils
{
}
matrix-datasource/matrix-datasource-core/src/main/java/com/secoo/mall/datasource/provider/ApolloDataSourceProvider.java
View file @
634d315f
...
...
@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.ConfigService;
import
com.google.common.collect.Lists
;
import
com.secoo.mall.common.core.exception.BusinessException
;
import
com.secoo.mall.common.util.colletion.CollectionUtil
;
import
com.secoo.mall.common.util.reflect.FieldUtil
;
import
com.secoo.mall.common.util.string.StringUtil
;
import
com.secoo.mall.datasource.config.MatrixDataSourceConfig
;
import
com.secoo.mall.datasource.constant.DataSourceConstant
;
...
...
@@ -42,28 +43,33 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
if
(
CollectionUtil
.
isEmpty
(
propertyNames
))
{
throw
new
BusinessException
(
DataSourceError
.
APOLLO_CONFIG_NOT_EXIST
);
}
//用数据源名字为key,进行分组
Map
<
String
,
List
<
String
>>
propertyMap
=
propertyNames
.
stream
().
filter
(
pro
->
pro
.
contains
(
MatrixDataSourceProperties
.
PREFIX
)).
map
(
pro
->
pro
.
replace
(
MatrixDataSourceProperties
.
PREFIX
,
""
))
//用数据源名字为key,进行
属性
分组
Map
<
String
,
List
<
String
>>
dsP
propertyMap
=
propertyNames
.
stream
().
filter
(
pro
->
pro
.
contains
(
MatrixDataSourceProperties
.
PREFIX
)).
map
(
pro
->
pro
.
replace
(
MatrixDataSourceProperties
.
PREFIX
,
""
))
.
collect
(
Collectors
.
groupingBy
(
str
->
str
.
split
(
DataSourceConstant
.
PROPETY_SPLIT_CHAR
)[
1
]));
Map
<
String
,
Class
>
fieldMap
=
getFieldMap
();
//获取对象的所有字段的信息用于反射
Map
<
String
,
Class
>
fieldMap
=
FieldUtil
.
getAllFieldsList
(
getEntryClass
()).
stream
().
collect
(
Collectors
.
toMap
(
Field:
:
getName
,
Field:
:
getType
,
(
key1
,
key2
)
->
key1
));
Set
<
String
>
notSupportPropertySet
=
new
HashSet
<>();
try
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
propertyMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
dsP
propertyMap
.
entrySet
())
{
String
dsName
=
entry
.
getKey
();
T
matrixDataSourceProperties
=
getEntryClass
().
newInstance
();
matrixDataSourceProperties
.
setName
(
dsName
);
for
(
String
property
:
entry
.
getValue
())
{
String
propertyFullPath
=
MatrixDataSourceProperties
.
PREFIX
+
property
;
Object
value
=
decryptPropertyItemValue
(
appConfig
.
getProperty
(
propertyFullPath
,
""
));
//得到实际的属性,首字母大写
String
beanProperty
=
property
.
split
(
DataSourceConstant
.
PROPETY_SPLIT_CHAR
)[
2
];
//转换为真实类型数据
if
(
fieldMap
.
containsKey
(
beanProperty
)){
value
=
MethodUtils
.
invokeExactStaticMethod
(
fieldMap
.
get
(
beanProperty
),
"valueOf"
,
value
);
for
(
String
configPropertyKey
:
entry
.
getValue
())
{
String
configPropertyFullPath
=
MatrixDataSourceProperties
.
PREFIX
+
configPropertyKey
;
Object
value
=
decryptPropertyItemValue
(
appConfig
.
getProperty
(
configPropertyFullPath
,
""
));
//得到实际类的字段
String
beanFieldName
=
configPropertyKey
.
split
(
DataSourceConstant
.
PROPETY_SPLIT_CHAR
)[
2
];
if
(!
fieldMap
.
containsKey
(
beanFieldName
))
{
notSupportPropertySet
.
add
(
beanFieldName
);
continue
;
}
//非String类型的需要进行真实类型数据转换
if
(!
fieldMap
.
get
(
beanFieldName
).
isAssignableFrom
(
String
.
class
))
{
value
=
MethodUtils
.
invokeExactStaticMethod
(
fieldMap
.
get
(
beanFieldName
),
"valueOf"
,
value
);
}
MethodUtils
.
invokeExactMethod
(
matrixDataSourceProperties
,
"set"
+
StringUtil
.
capitalize
(
bean
Property
),
value
);
MethodUtils
.
invokeExactMethod
(
matrixDataSourceProperties
,
"set"
+
StringUtil
.
capitalize
(
bean
FieldName
),
value
);
}
log
.
info
(
"init datasource name:{}"
,
dsName
);
list
.
add
(
matrixDataSourceProperties
);
...
...
@@ -72,7 +78,10 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
log
.
error
(
"e:"
,
e
);
throw
new
BusinessException
(
DataSourceError
.
APOLLO_CONFIG_NOT_EXIST
);
}
//存在不支持的属性
if
(
CollectionUtil
.
isNotEmpty
(
notSupportPropertySet
))
{
log
.
warn
(
"Matrix not support the property:{}. See for details:http://confluence.siku.cn/pages/viewpage.action?pageId=18910893"
,
notSupportPropertySet
);
}
return
list
;
}
...
...
@@ -83,21 +92,5 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
SysUtil
.
setProperty
(
"accessToken"
,
acccessToken
);
}
private
Map
<
String
,
Class
>
getFieldMap
()
{
List
<
Field
>
fieldList
=
new
ArrayList
<>();
Class
tempClass
=
getEntryClass
();
while
(
tempClass
!=
null
)
{
fieldList
.
addAll
(
Arrays
.
asList
(
tempClass
.
getDeclaredFields
()));
tempClass
=
tempClass
.
getSuperclass
();
}
Map
<
String
,
Class
>
map
=
new
HashMap
<>();
//过滤String
fieldList
=
fieldList
.
stream
().
filter
(
field
->
!
field
.
getType
().
getSimpleName
().
contains
(
"String"
)).
collect
(
Collectors
.
toList
());
for
(
Field
field
:
fieldList
)
{
map
.
put
(
field
.
getName
(),
field
.
getType
());
}
return
map
;
}
}
matrix-datasource/matrix-datasource-druid/src/main/java/com/secoo/mall/datasource/properties/MatrixDruidDataSourceProperties.java
View file @
634d315f
...
...
@@ -9,7 +9,7 @@ import java.util.Properties;
public
class
MatrixDruidDataSourceProperties
extends
MatrixDataSourceProperties
{
public
static
final
String
PREFIX
=
MatrixDataSourceProperties
.
PREFIX
+
".druid"
;
private
Integer
initialSize
;
private
Long
timeBetweenEvictionRunsMillis
=
DruidAbstractDataSource
.
DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS
;
private
Long
timeBetweenLogStatsMillis
;
private
Integer
statSqlMaxSize
;
...
...
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