mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
refactor static final field name
This commit is contained in:
parent
29a40ded8b
commit
c2806b6a1c
@ -54,9 +54,9 @@ public class SentinelDataSourceHandler {
|
|||||||
private List<String> dataSourceBeanNameList = Collections
|
private List<String> dataSourceBeanNameList = Collections
|
||||||
.synchronizedList(new ArrayList<>());
|
.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
private final String DATATYPE_FIELD = "dataType";
|
private final String DATA_TYPE_FIELD = "dataType";
|
||||||
private final String CUSTOM_DATATYPE = "custom";
|
private final String CUSTOM_DATA_TYPE = "custom";
|
||||||
private final String CONVERTERCLASS_FIELD = "converterClass";
|
private final String CONVERTER_CLASS_FIELD = "converterClass";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SentinelProperties sentinelProperties;
|
private SentinelProperties sentinelProperties;
|
||||||
@ -132,8 +132,8 @@ public class SentinelDataSourceHandler {
|
|||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
}, HashMap::putAll);
|
}, HashMap::putAll);
|
||||||
propertyMap.put(CONVERTERCLASS_FIELD, dataSourceProperties.getConverterClass());
|
propertyMap.put(CONVERTER_CLASS_FIELD, dataSourceProperties.getConverterClass());
|
||||||
propertyMap.put(DATATYPE_FIELD, dataSourceProperties.getDataType());
|
propertyMap.put(DATA_TYPE_FIELD, dataSourceProperties.getDataType());
|
||||||
|
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||||
.genericBeanDefinition(dataSourceProperties.getFactoryBeanName());
|
.genericBeanDefinition(dataSourceProperties.getFactoryBeanName());
|
||||||
@ -141,76 +141,72 @@ public class SentinelDataSourceHandler {
|
|||||||
propertyMap.forEach((propertyName, propertyValue) -> {
|
propertyMap.forEach((propertyName, propertyValue) -> {
|
||||||
Field field = ReflectionUtils.findField(dataSourceProperties.getClass(),
|
Field field = ReflectionUtils.findField(dataSourceProperties.getClass(),
|
||||||
propertyName);
|
propertyName);
|
||||||
if (field != null) {
|
if (null == field) {
|
||||||
if (DATATYPE_FIELD.equals(propertyName)) {
|
return;
|
||||||
String dataType = StringUtils
|
}
|
||||||
.trimAllWhitespace(propertyValue.toString());
|
if (DATA_TYPE_FIELD.equals(propertyName)) {
|
||||||
if (CUSTOM_DATATYPE.equals(dataType)) {
|
String dataType = StringUtils.trimAllWhitespace(propertyValue.toString());
|
||||||
try {
|
if (CUSTOM_DATA_TYPE.equals(dataType)) {
|
||||||
if (StringUtils
|
try {
|
||||||
.isEmpty(dataSourceProperties.getConverterClass())) {
|
if (StringUtils
|
||||||
throw new RuntimeException(
|
.isEmpty(dataSourceProperties.getConverterClass())) {
|
||||||
"[Sentinel Starter] DataSource " + dataSourceName
|
|
||||||
+ "dataType is custom, please set converter-class "
|
|
||||||
+ "property");
|
|
||||||
}
|
|
||||||
// construct custom Converter with 'converterClass'
|
|
||||||
// configuration and register
|
|
||||||
String customConvertBeanName = "sentinel-"
|
|
||||||
+ dataSourceProperties.getConverterClass();
|
|
||||||
if (!beanFactory.containsBean(customConvertBeanName)) {
|
|
||||||
beanFactory.registerBeanDefinition(customConvertBeanName,
|
|
||||||
BeanDefinitionBuilder
|
|
||||||
.genericBeanDefinition(
|
|
||||||
Class.forName(dataSourceProperties
|
|
||||||
.getConverterClass()))
|
|
||||||
.getBeanDefinition());
|
|
||||||
}
|
|
||||||
builder.addPropertyReference("converter",
|
|
||||||
customConvertBeanName);
|
|
||||||
}
|
|
||||||
catch (ClassNotFoundException e) {
|
|
||||||
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
|
||||||
+ " handle "
|
|
||||||
+ dataSourceProperties.getClass().getSimpleName()
|
|
||||||
+ " error, class name: "
|
|
||||||
+ dataSourceProperties.getConverterClass());
|
|
||||||
throw new RuntimeException(
|
|
||||||
"[Sentinel Starter] DataSource " + dataSourceName
|
|
||||||
+ " handle "
|
|
||||||
+ dataSourceProperties.getClass()
|
|
||||||
.getSimpleName()
|
|
||||||
+ " error, class name: "
|
|
||||||
+ dataSourceProperties.getConverterClass(),
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!dataTypeList.contains(StringUtils
|
|
||||||
.trimAllWhitespace(propertyValue.toString()))) {
|
|
||||||
throw new RuntimeException("[Sentinel Starter] DataSource "
|
throw new RuntimeException("[Sentinel Starter] DataSource "
|
||||||
+ dataSourceName + " dataType: " + propertyValue
|
+ dataSourceName
|
||||||
+ " is not support now. please using these types: "
|
+ "dataType is custom, please set converter-class "
|
||||||
+ dataTypeList.toString());
|
+ "property");
|
||||||
}
|
}
|
||||||
// converter type now support xml or json.
|
// construct custom Converter with 'converterClass'
|
||||||
// The bean name of these converters wrapped by
|
// configuration and register
|
||||||
// 'sentinel-{converterType}-{ruleType}-converter'
|
String customConvertBeanName = "sentinel-"
|
||||||
builder.addPropertyReference("converter",
|
+ dataSourceProperties.getConverterClass();
|
||||||
"sentinel-" + propertyValue.toString() + "-"
|
if (!beanFactory.containsBean(customConvertBeanName)) {
|
||||||
+ dataSourceProperties.getRuleType().getName()
|
beanFactory.registerBeanDefinition(customConvertBeanName,
|
||||||
+ "-converter");
|
BeanDefinitionBuilder
|
||||||
|
.genericBeanDefinition(
|
||||||
|
Class.forName(dataSourceProperties
|
||||||
|
.getConverterClass()))
|
||||||
|
.getBeanDefinition());
|
||||||
|
}
|
||||||
|
builder.addPropertyReference("converter", customConvertBeanName);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
logger.error("[Sentinel Starter] DataSource " + dataSourceName
|
||||||
|
+ " handle "
|
||||||
|
+ dataSourceProperties.getClass().getSimpleName()
|
||||||
|
+ " error, class name: "
|
||||||
|
+ dataSourceProperties.getConverterClass());
|
||||||
|
throw new RuntimeException("[Sentinel Starter] DataSource "
|
||||||
|
+ dataSourceName + " handle "
|
||||||
|
+ dataSourceProperties.getClass().getSimpleName()
|
||||||
|
+ " error, class name: "
|
||||||
|
+ dataSourceProperties.getConverterClass(), e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (CONVERTERCLASS_FIELD.equals(propertyName)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// wired properties
|
if (!dataTypeList.contains(
|
||||||
Optional.ofNullable(propertyValue)
|
StringUtils.trimAllWhitespace(propertyValue.toString()))) {
|
||||||
.ifPresent(v -> builder.addPropertyValue(propertyName, v));
|
throw new RuntimeException("[Sentinel Starter] DataSource "
|
||||||
|
+ dataSourceName + " dataType: " + propertyValue
|
||||||
|
+ " is not support now. please using these types: "
|
||||||
|
+ dataTypeList.toString());
|
||||||
|
}
|
||||||
|
// converter type now support xml or json.
|
||||||
|
// The bean name of these converters wrapped by
|
||||||
|
// 'sentinel-{converterType}-{ruleType}-converter'
|
||||||
|
builder.addPropertyReference("converter",
|
||||||
|
"sentinel-" + propertyValue.toString() + "-"
|
||||||
|
+ dataSourceProperties.getRuleType().getName()
|
||||||
|
+ "-converter");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (CONVERTER_CLASS_FIELD.equals(propertyName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// wired properties
|
||||||
|
Optional.ofNullable(propertyValue)
|
||||||
|
.ifPresent(v -> builder.addPropertyValue(propertyName, v));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());
|
beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user