Skip to content

Commit 14e9056

Browse files
author
Evan Hu
committed
util
1 parent 0fae152 commit 14e9056

File tree

7 files changed

+1131
-652
lines changed

7 files changed

+1131
-652
lines changed

src/main/java/info/xiaomo/gengine/network/Session.java renamed to src/main/java/info/xiaomo/gengine/network/ISession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* desc :
1818
* Copyright(©) 2017 by xiaomo.
1919
*/
20-
public interface Session {
20+
public interface ISession {
2121

2222
/**
2323
* channel

src/main/java/info/xiaomo/gengine/network/SessionKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author xiaomo
77
*/
88
public class SessionKey {
9-
public static final AttributeKey<Session> SESSION = AttributeKey.newInstance("SESSION");
9+
public static final AttributeKey<ISession> SESSION = AttributeKey.newInstance("SESSION");
1010

1111
public static final AttributeKey<Boolean> LOGOUT_HANDLED = AttributeKey.newInstance("LOGOUT_HANDLED");
1212
}

src/main/java/info/xiaomo/gengine/network/pool/MessageAndHandlerPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class MessageAndHandlerPool implements IMessageAndHandler {
2626
/**
2727
* 消息类字典
2828
*/
29-
private final Map<Integer, AbstractMessage> messages = new HashMap<>(10);
29+
public final Map<Integer, AbstractMessage> messages = new HashMap<>(10);
3030

3131
/**
3232
* 类和

src/main/java/info/xiaomo/gengine/network/pool/MessageRouter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public void consume(AbstractMessage msg, Channel channel) {
4141
return;
4242
}
4343

44-
Session session = AttributeUtil.get(channel, SessionKey.SESSION);
44+
ISession ISession = AttributeUtil.get(channel, SessionKey.SESSION);
4545

46-
if (session == null) {
46+
if (ISession == null) {
4747
return;
4848
}
4949

5050
AbstractHandler handler = msgPool.getHandler(msg.getClass().getName());
5151
handler.setMessage(msg);
52-
handler.setParam(session);
52+
handler.setParam(ISession);
5353
log.debug("收到消息:" + msg);
5454

5555
processor.process(handler);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package info.xiaomo.gengine.utils;
2+
3+
4+
5+
import java.sql.SQLException;
6+
import java.util.List;
7+
import info.xiaomo.gengine.persist.mysql.jdbc.JdbcTemplate;
8+
import info.xiaomo.gengine.persist.mysql.jdbc.RowMapper;
9+
10+
/**
11+
* @author xiaomo
12+
*/
13+
public class JdbcUtil {
14+
15+
private static JdbcTemplate template;
16+
17+
public static void init(JdbcTemplate template) {
18+
JdbcUtil.template = template;
19+
}
20+
21+
public static JdbcTemplate getTemplate() {
22+
return template;
23+
}
24+
25+
public static <T> T query(String sql, RowMapper<T> mapper, Object... parameters) {
26+
if (template == null) {
27+
throw new RuntimeException("jdbc模板类未初始化");
28+
}
29+
return template.query(sql, mapper, parameters);
30+
}
31+
32+
public static <T> List<T> queryList(String sql, RowMapper<T> mapper, Object... parameters) {
33+
if (template == null) {
34+
throw new RuntimeException("jdbc模板类未初始化");
35+
}
36+
return template.queryList(sql, mapper, parameters);
37+
}
38+
39+
public static int update(String sql, Object... parameters) {
40+
if (template == null) {
41+
throw new RuntimeException("jdbc模板类未初始化");
42+
}
43+
44+
return template.update(sql, parameters);
45+
}
46+
47+
public static void batchUpdate(String sql, List<Object[]> parameters) {
48+
49+
if (template == null) {
50+
throw new RuntimeException("jdbc模板类未初始化");
51+
}
52+
template.batchUpdate(sql, parameters);
53+
}
54+
55+
56+
/**
57+
* 该表是否存在
58+
*
59+
* @param tableName tableName
60+
* @return boolean
61+
*/
62+
public static boolean hasTable(String tableName) {
63+
try {
64+
return template.hasTable(tableName);
65+
} catch (SQLException e) {
66+
e.printStackTrace();
67+
}
68+
return false;
69+
}
70+
71+
public static void createTable(String sql) {
72+
if (template == null) {
73+
throw new RuntimeException("jdbc模板类未初始化");
74+
}
75+
template.createTable(sql);
76+
}
77+
}

0 commit comments

Comments
 (0)