org.yx.db.conn.CommonConfigFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sumk Show documentation
Show all versions of sumk Show documentation
A quick developing framewort for internet company
/**
* Copyright (C) 2016 - 2030 youtongluan.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.yx.db.conn;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.yx.annotation.Bean;
import org.yx.conf.AppInfo;
import org.yx.log.Logs;
import org.yx.util.CollectionUtil;
@Bean
public class CommonConfigFactory implements DBConfigFactory {
protected Map> parseFromAppInfo(String dbName) {
Map map = AppInfo.subMap("s.db." + dbName + ".");
if (map.isEmpty()) {
return null;
}
Map configMap = CollectionUtil.flatMapToTree(map);
return pureMap(configMap);
}
@Override
public List create(String name) throws Exception {
Map> maps = parseFromAppInfo(name);
List list = new ArrayList<>();
if (maps == null || maps.isEmpty()) {
return list;
}
for (Map map : maps.values()) {
list.add(DBConfig.create(map));
}
return list;
}
public static Map> pureMap(Map objectMap) {
if (objectMap == null || objectMap.isEmpty()) {
return Collections.emptyMap();
}
final Map> ret = new HashMap>();
objectMap.forEach((catagory, value) -> {
if (!Map.class.isInstance(value)) {
Logs.db().info("{} is not valid config, value : {}", catagory, value);
return;
}
@SuppressWarnings("unchecked")
Map config = (Map) value;
Map real = new HashMap<>();
config.forEach((propertyName, v) -> {
if (!String.class.isInstance(v)) {
Logs.db().info("{}.{} is not valid config,value:{}", catagory, propertyName, v);
return;
}
real.put(propertyName, (String) v);
});
if (real.size() > 0) {
ret.put(catagory, real);
}
});
return ret;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy