连接信息写DB优化为批量写入

This commit is contained in:
zengqiao
2021-05-07 13:51:34 +08:00
parent 6d19acaa6c
commit 663e871bed
4 changed files with 30 additions and 40 deletions

View File

@@ -13,8 +13,6 @@ import java.util.List;
public interface TopicConnectionDao {
int batchReplace(List<TopicConnectionDO> doList);
int replace(TopicConnectionDO topicConnectionDO);
List<TopicConnectionDO> getByTopicName(Long clusterId, String topicName, Date startTime, Date endTime);
List<TopicConnectionDO> getByAppId(String appId, Date startTime, Date endTime);

View File

@@ -27,29 +27,12 @@ public class TopicConnectionDaoImpl implements TopicConnectionDao {
@Override
public int batchReplace(List<TopicConnectionDO> doList) {
int count = 0;
for (TopicConnectionDO elem: doList) {
try {
count += sqlSession.insert("TopicConnectionDao.replace", elem);
} catch (DeadlockLoserDataAccessException e1) {
} catch (Exception e) {
LOGGER.error("add topic connection info, clusterId:{} topicName:{}."
, elem.getClusterId(), elem.getTopicName(), e);
}
}
return count;
}
@Override
public int replace(TopicConnectionDO topicConnectionDO) {
try {
return sqlSession.insert("TopicConnectionDao.replace", topicConnectionDO);
return sqlSession.insert("TopicConnectionDao.batchReplace", doList);
} catch (DeadlockLoserDataAccessException e1) {
return 0;
} catch (Exception e) {
LOGGER.error("add topic connection info, clusterId:{} topicName:{}."
, topicConnectionDO.getClusterId(), topicConnectionDO.getTopicName(), e);
LOGGER.error("add topic connections info failed", e);
}
return 0;
}