Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrain2012 committed Nov 27, 2019
1 parent f9d5c86 commit b0ca8ed
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions broker/src/main/java/io/moquette/persistence/DatabaseStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,12 @@ MessageBundle getMessage(long messageId) {
String sql = "select `_from`, `_type`, `_target`, `_line`, `_data`, `_dt` from " + MessageShardingUtil.getMessageTable(messageId) +" where _mid = ? limit 1";
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = DBUtil.getConnection();
statement = connection.prepareStatement(sql);
statement.setLong(1, messageId);
ResultSet resultSet = statement.executeQuery();
resultSet = statement.executeQuery();
if (resultSet.next()) {
WFCMessage.Message.Builder builder = WFCMessage.Message.newBuilder();
builder.setMessageId(messageId);
Expand All @@ -663,12 +664,11 @@ MessageBundle getMessage(long messageId) {
WFCMessage.Message message = builder.build();
return new MessageBundle(messageId, message.getFromUser(), null, message);
}
resultSet.close();
} catch (SQLException | IOException e) {
e.printStackTrace();
Utility.printExecption(LOG, e);
} finally {
DBUtil.closeDB(connection, statement);
DBUtil.closeDB(connection, statement, resultSet);
}
return null;
}
Expand Down Expand Up @@ -1031,12 +1031,13 @@ List<MemorySessionStore.Session> getUserActivedSessions(String uid) {
Connection connection = null;
PreparedStatement statement = null;
List<MemorySessionStore.Session> result = new ArrayList<>();
ResultSet resultSet = null;
try {
connection = DBUtil.getConnection();
statement = connection.prepareStatement(sql);
statement.setString(1, uid);

ResultSet resultSet = statement.executeQuery();
resultSet = statement.executeQuery();
while (resultSet.next()) {
int index = 1;
String cid = resultSet.getString(index++);
Expand All @@ -1060,12 +1061,11 @@ List<MemorySessionStore.Session> getUserActivedSessions(String uid) {
session.setUpdateDt(resultSet.getLong(index++));
result.add(session);
}
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
Utility.printExecption(LOG, e);
} finally {
DBUtil.closeDB(connection, statement);
DBUtil.closeDB(connection, statement, resultSet);
}
return result;
}
Expand All @@ -1074,12 +1074,13 @@ MemorySessionStore.Session getSession(String uid, String clientId, ClientSession
String sql = "select `_package_name`,`_token`,`_voip_token`,`_secret`,`_db_secret`,`_platform`,`_push_type`,`_device_name`,`_device_version`,`_phone_name`,`_language`,`_carrier_name`, `_dt`, `_deleted` from t_user_session where `_uid` = ? and `_cid` = ? limit 1";
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = DBUtil.getConnection();
statement = connection.prepareStatement(sql);
statement.setString(1, uid);
statement.setString(2, clientId);
ResultSet resultSet = statement.executeQuery();
resultSet = statement.executeQuery();
if (resultSet.next()) {
MemorySessionStore.Session session = new MemorySessionStore.Session(uid, clientId, clientSession);

Expand All @@ -1101,12 +1102,11 @@ MemorySessionStore.Session getSession(String uid, String clientId, ClientSession
session.setDeleted(resultSet.getInt(index));
return session;
}
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
Utility.printExecption(LOG, e);
} finally {
DBUtil.closeDB(connection, statement);
DBUtil.closeDB(connection, statement, resultSet);
}
return null;
}
Expand Down

0 comments on commit b0ca8ed

Please sign in to comment.