refactor static final field name
@@ -54,9 +54,9 @@ public class SentinelDataSourceHandler {
private List<String> dataSourceBeanNameList = Collections
.synchronizedList(new ArrayList<>());
- private final String DATATYPE_FIELD = "dataType";
- private final String CUSTOM_DATATYPE = "custom";
- private final String CONVERTERCLASS_FIELD = "converterClass";
+ private final String DATA_TYPE_FIELD = "dataType";
+ private final String CUSTOM_DATA_TYPE = "custom";
+ private final String CONVERTER_CLASS_FIELD = "converterClass";
@Autowired
private SentinelProperties sentinelProperties;
@@ -132,8 +132,8 @@ public class SentinelDataSourceHandler {
e);
}
}, HashMap::putAll);
- propertyMap.put(CONVERTERCLASS_FIELD, dataSourceProperties.getConverterClass());
- propertyMap.put(DATATYPE_FIELD, dataSourceProperties.getDataType());
+ propertyMap.put(CONVERTER_CLASS_FIELD, dataSourceProperties.getConverterClass());
+ propertyMap.put(DATA_TYPE_FIELD, dataSourceProperties.getDataType());
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition(dataSourceProperties.getFactoryBeanName());
@@ -141,16 +141,17 @@ public class SentinelDataSourceHandler {
propertyMap.forEach((propertyName, propertyValue) -> {
Field field = ReflectionUtils.findField(dataSourceProperties.getClass(),
propertyName);
- if (field != null) {
- if (DATATYPE_FIELD.equals(propertyName)) {
- String dataType = StringUtils
- .trimAllWhitespace(propertyValue.toString());
- if (CUSTOM_DATATYPE.equals(dataType)) {
+ if (null == field) {
+ return;
+ }
+ if (DATA_TYPE_FIELD.equals(propertyName)) {
+ String dataType = StringUtils.trimAllWhitespace(propertyValue.toString());
+ if (CUSTOM_DATA_TYPE.equals(dataType)) {
try {
if (StringUtils
.isEmpty(dataSourceProperties.getConverterClass())) {
- throw new RuntimeException(
- "[Sentinel Starter] DataSource " + dataSourceName
+ throw new RuntimeException("[Sentinel Starter] DataSource "
+ + dataSourceName
+ "dataType is custom, please set converter-class "
+ "property");
}
@@ -166,8 +167,7 @@ public class SentinelDataSourceHandler {
.getConverterClass()))
.getBeanDefinition());
}
- builder.addPropertyReference("converter",
- customConvertBeanName);
+ builder.addPropertyReference("converter", customConvertBeanName);
}
catch (ClassNotFoundException e) {
logger.error("[Sentinel Starter] DataSource " + dataSourceName
@@ -175,19 +175,16 @@ public class SentinelDataSourceHandler {
+ dataSourceProperties.getClass().getSimpleName()
+ " error, class name: "
+ dataSourceProperties.getConverterClass());
- throw new RuntimeException(
- "[Sentinel Starter] DataSource " + dataSourceName
- + " handle "
- + dataSourceProperties.getClass()
- .getSimpleName()
+ throw new RuntimeException("[Sentinel Starter] DataSource "
+ + dataSourceName + " handle "
+ + dataSourceProperties.getClass().getSimpleName()
+ " error, class name: "
- + dataSourceProperties.getConverterClass(),
- e);
+ + dataSourceProperties.getConverterClass(), e);
}
}
else {
- if (!dataTypeList.contains(StringUtils
- .trimAllWhitespace(propertyValue.toString()))) {
+ if (!dataTypeList.contains(
+ StringUtils.trimAllWhitespace(propertyValue.toString()))) {
throw new RuntimeException("[Sentinel Starter] DataSource "
+ dataSourceName + " dataType: " + propertyValue
+ " is not support now. please using these types: "
@@ -202,7 +199,7 @@ public class SentinelDataSourceHandler {
+ "-converter");
}
}
- else if (CONVERTERCLASS_FIELD.equals(propertyName)) {
+ else if (CONVERTER_CLASS_FIELD.equals(propertyName)) {
return;
}
else {
@@ -210,7 +207,6 @@ public class SentinelDataSourceHandler {
Optional.ofNullable(propertyValue)
.ifPresent(v -> builder.addPropertyValue(propertyName, v));
}
- }
});
beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());
