Skip to content

Commit ea922f1

Browse files
author
Evan Hu
committed
key
1 parent d488825 commit ea922f1

20 files changed

+1079
-1169
lines changed
Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/**
2-
* 创建日期: 2017年08月21日 17:47
3-
* 创建作者: 杨 强 <[email protected]>
4-
*/
1+
52
package info.xiaomo.gengine.config;
63

74
import java.util.HashMap;
@@ -11,46 +8,48 @@
118
import org.slf4j.LoggerFactory;
129

1310
/**
11+
* 创建日期: 2017年08月21日 17:47
12+
* 创建作者: 杨 强 <[email protected]>
1413
* 抽象的配置数据管理器
15-
*
16-
* @author YangQiang
1714
*/
1815
public abstract class AbstractConfigDataManager implements IConfigDataManager {
19-
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractConfigDataManager.class);
20-
protected Map<String, IConfigWrapper> configs = new HashMap<>(10);
21-
protected Map<String, Object> caches = new HashMap<>(10);
16+
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractConfigDataManager.class);
17+
protected Map<String, IConfigWrapper> configs = new HashMap<>(10);
18+
protected Map<String, Object> caches = new HashMap<>(10);
2219

23-
@Override
24-
public <T> T getConfig(Class<T> clz, Object... primaryKey) {
25-
IConfigWrapper wrapper = configs.get(clz.getName());
26-
if (wrapper == null) {
27-
return null;
28-
}
29-
StringBuilder key = new StringBuilder();
30-
if (primaryKey != null) {
31-
for (int i = 0; i < primaryKey.length; i++) {
32-
Object tempKey = primaryKey[i];
33-
if (i == 0) {
34-
key.append(tempKey.toString());
35-
} else {
36-
key.append(wrapper.getKeyDelimiter()).append(tempKey.toString());
37-
}
38-
}
39-
}
40-
return (T) wrapper.getConfig(key.toString());
41-
}
20+
@Override
21+
@SuppressWarnings("unchecked")
22+
public <T> T getConfig(Class<T> clz, Object... primaryKey) {
23+
IConfigWrapper wrapper = configs.get(clz.getName());
24+
if (wrapper == null) {
25+
return null;
26+
}
27+
StringBuilder key = new StringBuilder();
28+
if (primaryKey != null) {
29+
for (int i = 0; i < primaryKey.length; i++) {
30+
Object tempKey = primaryKey[i];
31+
if (i == 0) {
32+
key.append(tempKey.toString());
33+
} else {
34+
key.append(wrapper.getKeyDelimiter()).append(tempKey.toString());
35+
}
36+
}
37+
}
38+
return (T) wrapper.getConfig(key.toString());
39+
}
4240

43-
@Override
44-
public <T> List<T> getConfigs(Class<T> clz) {
45-
IConfigWrapper wrapper = configs.get(clz.getName());
46-
if (wrapper == null) {
47-
return null;
48-
}
49-
return wrapper.getList();
50-
}
41+
@Override
42+
public <T> List<T> getConfigs(Class<T> clz) {
43+
IConfigWrapper wrapper = configs.get(clz.getName());
44+
if (wrapper == null) {
45+
return null;
46+
}
47+
return wrapper.getList();
48+
}
5149

52-
@Override
53-
public <T> T getConfigCache(Class<T> clz) {
54-
return (T) caches.get(clz);
55-
}
50+
@Override
51+
@SuppressWarnings("unchecked")
52+
public <T> T getConfigCache(Class<T> clz) {
53+
return (T) caches.get(clz);
54+
}
5655
}

src/main/java/info/xiaomo/gengine/config/ICellReader.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,33 @@
1010
*/
1111
public interface ICellReader<T, R> extends IReader<T, R> {
1212

13-
/**
14-
* 获取默认值
15-
*
16-
* @param t t
17-
* @return R
18-
*/
19-
R getDefaultValue(T t);
13+
/**
14+
* 获取默认值
15+
*
16+
* @param t t
17+
* @return R
18+
*/
19+
R getDefaultValue(T t);
2020

21-
/**
22-
* 获取转换器
23-
* @return IConverter
24-
*/
25-
IConverter<T, R> getConverter();
21+
/**
22+
* 获取转换器
23+
*
24+
* @return IConverter
25+
*/
26+
IConverter<T, R> getConverter();
2627

27-
/**
28-
* 读取
29-
* @param t t
30-
* @return R
31-
*/
32-
@Override
33-
default R read(T t) {
34-
IConverter<T, R> converter = getConverter();
35-
if (converter != null) {
36-
return converter.convert(t);
37-
}
38-
return getDefaultValue(t);
39-
}
28+
/**
29+
* 读取
30+
*
31+
* @param t t
32+
* @return R
33+
*/
34+
@Override
35+
default R read(T t) {
36+
IConverter<T, R> converter = getConverter();
37+
if (converter != null) {
38+
return converter.convert(t);
39+
}
40+
return getDefaultValue(t);
41+
}
4042
}

src/main/java/info/xiaomo/gengine/persist/mongo/AbsMongoManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
/**
1111
* mongodb 管理类
12-
*
13-
*
14-
* 2017-04-14
12+
* <p>
13+
* <p>
14+
* 2017-04-14
1515
*/
1616
public abstract class AbsMongoManager {
1717

src/main/java/info/xiaomo/gengine/persist/mongo/IConfigChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* 配置实体检测接口
77
* <br>
88
* 配置文件之间存在依赖关系,在加载检测策划配置数据是否正确
9-
*
10-
*
11-
* 2017年10月18日 下午4:25:11
9+
* <p>
10+
* <p>
11+
* 2017年10月18日 下午4:25:11
1212
*/
1313
public interface IConfigChecker {
1414
default <V> boolean check(Map<Integer, V> source) throws Exception {
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package info.xiaomo.gengine.persist.mongo;
22

3+
import lombok.Data;
34
import org.simpleframework.xml.Element;
45

56
/**
67
* Mongo配置文件
7-
*
8-
*
98
*/
9+
@Data
1010
public class MongoClientConfig {
1111

1212
/**
@@ -20,21 +20,5 @@ public class MongoClientConfig {
2020
@Element(required = true)
2121
private String url = "mongodb://127.0.0.1:27017/?replicaSet=rs_lztb";
2222

23-
public String getDbName() {
24-
return dbName;
25-
}
26-
27-
public void setDbName(String dbName) {
28-
this.dbName = dbName;
29-
}
30-
31-
public String getUrl() {
32-
return url;
33-
}
34-
35-
public void setUrl(String url) {
36-
this.url = url;
37-
}
38-
3923

4024
}

src/main/java/info/xiaomo/gengine/persist/mongo/dao/GuildDao.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,39 @@
66

77
/**
88
* 公会
9-
*
10-
* 2017年9月22日 上午10:38:16
9+
* <p>
10+
* 2017年9月22日 上午10:38:16
1111
*/
1212
public class GuildDao extends BasicDAO<BaseGuild, Long> {
13-
private static volatile GuildDao guildDao;
13+
private static volatile GuildDao guildDao;
1414

15-
public GuildDao(AbsMongoManager mongoManager) {
16-
super(
17-
BaseGuild.class,
18-
mongoManager.getMongoClient(),
19-
mongoManager.getMorphia(),
20-
mongoManager.getMongoConfig().getDbName());
21-
}
15+
public GuildDao(AbsMongoManager mongoManager) {
16+
super(
17+
BaseGuild.class,
18+
mongoManager.getMongoClient(),
19+
mongoManager.getMorphia(),
20+
mongoManager.getMongoConfig().getDbName());
21+
}
2222

23-
public static GuildDao getDB(AbsMongoManager mongoManager) {
24-
if (guildDao == null) {
25-
synchronized (GuildDao.class) {
26-
if (guildDao == null) {
27-
guildDao = new GuildDao(mongoManager);
28-
}
29-
}
30-
}
31-
return guildDao;
32-
}
23+
public static GuildDao getDB(AbsMongoManager mongoManager) {
24+
if (guildDao == null) {
25+
synchronized (GuildDao.class) {
26+
if (guildDao == null) {
27+
guildDao = new GuildDao(mongoManager);
28+
}
29+
}
30+
}
31+
return guildDao;
32+
}
3333

34-
/**
35-
* 存储
36-
*
37-
* 2017年9月22日 上午10:45:52
38-
* @param baseGuild
39-
*/
40-
public static void saveGuild(BaseGuild baseGuild) {
41-
guildDao.save(baseGuild);
42-
}
34+
/**
35+
* 存储
36+
* <p>
37+
* 2017年9月22日 上午10:45:52
38+
*
39+
* @param baseGuild
40+
*/
41+
public static void saveGuild(BaseGuild baseGuild) {
42+
guildDao.save(baseGuild);
43+
}
4344
}

0 commit comments

Comments
 (0)