1
0
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:
fangjian0423 2019-01-11 15:43:18 +08:00
parent 29a40ded8b
commit c2806b6a1c

View File

@ -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,16 +141,17 @@ 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());
if (CUSTOM_DATA_TYPE.equals(dataType)) {
try { try {
if (StringUtils if (StringUtils
.isEmpty(dataSourceProperties.getConverterClass())) { .isEmpty(dataSourceProperties.getConverterClass())) {
throw new RuntimeException( throw new RuntimeException("[Sentinel Starter] DataSource "
"[Sentinel Starter] DataSource " + dataSourceName + dataSourceName
+ "dataType is custom, please set converter-class " + "dataType is custom, please set converter-class "
+ "property"); + "property");
} }
@ -166,8 +167,7 @@ public class SentinelDataSourceHandler {
.getConverterClass())) .getConverterClass()))
.getBeanDefinition()); .getBeanDefinition());
} }
builder.addPropertyReference("converter", builder.addPropertyReference("converter", customConvertBeanName);
customConvertBeanName);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException e) {
logger.error("[Sentinel Starter] DataSource " + dataSourceName logger.error("[Sentinel Starter] DataSource " + dataSourceName
@ -175,19 +175,16 @@ public class SentinelDataSourceHandler {
+ dataSourceProperties.getClass().getSimpleName() + dataSourceProperties.getClass().getSimpleName()
+ " error, class name: " + " error, class name: "
+ dataSourceProperties.getConverterClass()); + dataSourceProperties.getConverterClass());
throw new RuntimeException( throw new RuntimeException("[Sentinel Starter] DataSource "
"[Sentinel Starter] DataSource " + dataSourceName + dataSourceName + " handle "
+ " handle " + dataSourceProperties.getClass().getSimpleName()
+ dataSourceProperties.getClass()
.getSimpleName()
+ " error, class name: " + " error, class name: "
+ dataSourceProperties.getConverterClass(), + dataSourceProperties.getConverterClass(), e);
e);
} }
} }
else { else {
if (!dataTypeList.contains(StringUtils if (!dataTypeList.contains(
.trimAllWhitespace(propertyValue.toString()))) { StringUtils.trimAllWhitespace(propertyValue.toString()))) {
throw new RuntimeException("[Sentinel Starter] DataSource " throw new RuntimeException("[Sentinel Starter] DataSource "
+ dataSourceName + " dataType: " + propertyValue + dataSourceName + " dataType: " + propertyValue
+ " is not support now. please using these types: " + " is not support now. please using these types: "
@ -202,7 +199,7 @@ public class SentinelDataSourceHandler {
+ "-converter"); + "-converter");
} }
} }
else if (CONVERTERCLASS_FIELD.equals(propertyName)) { else if (CONVERTER_CLASS_FIELD.equals(propertyName)) {
return; return;
} }
else { else {
@ -210,7 +207,6 @@ public class SentinelDataSourceHandler {
Optional.ofNullable(propertyValue) Optional.ofNullable(propertyValue)
.ifPresent(v -> builder.addPropertyValue(propertyName, v)); .ifPresent(v -> builder.addPropertyValue(propertyName, v));
} }
}
}); });
beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition()); beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());