mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
统一Canal 依赖的Spring 版本,升级ibatis 至mybatis (#3182)
* fix issue:#561 增加一个外部参数控制,允许位点不存在时自动重置到当前位点 * Add MariaDB GTID support * 1. fix maven central repository url access error.(Update to https) 2. upgrade spring version to 5.0.5.RELEASE 3. upgrade ibatis to mybatis * fix unit test run error
This commit is contained in:
@@ -9,14 +9,14 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
|
||||
import org.mybatis.spring.support.SqlSessionDaoSupport;
|
||||
|
||||
/**
|
||||
* @author agapple 2017年10月14日 上午1:05:22
|
||||
* @since 1.0.25
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MetaBaseDAO extends SqlMapClientDaoSupport {
|
||||
public class MetaBaseDAO extends SqlSessionDaoSupport {
|
||||
|
||||
protected boolean isH2 = false;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MetaBaseDAO extends SqlMapClientDaoSupport {
|
||||
Connection conn = null;
|
||||
InputStream input = null;
|
||||
try {
|
||||
DataSource dataSource = getDataSource();
|
||||
DataSource dataSource = getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource();
|
||||
conn = dataSource.getConnection();
|
||||
String name = "mysql";
|
||||
isH2 = isH2(conn);
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.google.common.collect.Maps;
|
||||
public class MetaHistoryDAO extends MetaBaseDAO {
|
||||
|
||||
public Long insert(MetaHistoryDO metaDO) {
|
||||
return (Long) getSqlMapClientTemplate().insert("meta_history.insert", metaDO);
|
||||
return getSqlSession().getMapper(MetaHistoryMapper.class).insert(metaDO);
|
||||
}
|
||||
|
||||
public List<MetaHistoryDO> findByTimestamp(String destination, Long snapshotTimestamp, Long timestamp) {
|
||||
@@ -23,13 +23,13 @@ public class MetaHistoryDAO extends MetaBaseDAO {
|
||||
params.put("destination", destination);
|
||||
params.put("snapshotTimestamp", snapshotTimestamp == null ? 0L : snapshotTimestamp);
|
||||
params.put("timestamp", timestamp == null ? 0L : timestamp);
|
||||
return (List<MetaHistoryDO>) getSqlMapClientTemplate().queryForList("meta_history.findByTimestamp", params);
|
||||
return getSqlSession().getMapper(MetaHistoryMapper.class).findByTimestamp(params);
|
||||
}
|
||||
|
||||
public Integer deleteByName(String destination) {
|
||||
HashMap params = Maps.newHashMapWithExpectedSize(2);
|
||||
params.put("destination", destination);
|
||||
return getSqlMapClientTemplate().delete("meta_history.deleteByName", params);
|
||||
return getSqlSession().getMapper(MetaHistoryMapper.class).deleteByName(params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ public class MetaHistoryDAO extends MetaBaseDAO {
|
||||
long timestamp = System.currentTimeMillis() - interval * 1000;
|
||||
params.put("timestamp", timestamp);
|
||||
params.put("destination", destination);
|
||||
return getSqlMapClientTemplate().delete("meta_history.deleteByTimestamp", params);
|
||||
return getSqlSession().getMapper(MetaHistoryMapper.class).deleteByTimestamp(params);
|
||||
}
|
||||
|
||||
protected void initDao() throws Exception {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.alibaba.otter.canal.parse.inbound.mysql.tsdb.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MetaHistoryMapper {
|
||||
|
||||
List<MetaHistoryDO> findByTimestamp(Map<String, Object> map);
|
||||
|
||||
long insert(MetaHistoryDO metaHistoryDO);
|
||||
|
||||
int deleteByName(Map<String, Object> map);
|
||||
|
||||
int deleteByTimestamp(Map<String, Object> map);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* canal数据的存储
|
||||
*
|
||||
*
|
||||
* @author wanshao 2017年7月27日 下午10:51:55
|
||||
* @since 3.2.5
|
||||
*/
|
||||
@@ -14,25 +14,24 @@ import com.google.common.collect.Maps;
|
||||
public class MetaSnapshotDAO extends MetaBaseDAO {
|
||||
|
||||
public Long insert(MetaSnapshotDO snapshotDO) {
|
||||
return (Long) getSqlMapClientTemplate().insert("meta_snapshot.insert", snapshotDO);
|
||||
return getSqlSession().getMapper(MetaSnapshotMapper.class).insert(snapshotDO);
|
||||
}
|
||||
|
||||
public Long update(MetaSnapshotDO snapshotDO) {
|
||||
return (Long) getSqlMapClientTemplate().insert("meta_snapshot.update", snapshotDO);
|
||||
return getSqlSession().getMapper(MetaSnapshotMapper.class).update(snapshotDO);
|
||||
}
|
||||
|
||||
public MetaSnapshotDO findByTimestamp(String destination, Long timestamp) {
|
||||
HashMap params = Maps.newHashMapWithExpectedSize(2);
|
||||
params.put("timestamp", timestamp == null ? 0L : timestamp);
|
||||
params.put("destination", destination);
|
||||
|
||||
return (MetaSnapshotDO) getSqlMapClientTemplate().queryForObject("meta_snapshot.findByTimestamp", params);
|
||||
return getSqlSession().getMapper(MetaSnapshotMapper.class).findByTimestamp(params);
|
||||
}
|
||||
|
||||
public Integer deleteByName(String destination) {
|
||||
HashMap params = Maps.newHashMapWithExpectedSize(2);
|
||||
params.put("destination", destination);
|
||||
return getSqlMapClientTemplate().delete("meta_snapshot.deleteByName", params);
|
||||
return getSqlSession().getMapper(MetaSnapshotMapper.class).deleteByName(params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +42,7 @@ public class MetaSnapshotDAO extends MetaBaseDAO {
|
||||
long timestamp = System.currentTimeMillis() - interval * 1000;
|
||||
params.put("timestamp", timestamp);
|
||||
params.put("destination", destination);
|
||||
return getSqlMapClientTemplate().delete("meta_snapshot.deleteByTimestamp", params);
|
||||
return getSqlSession().getMapper(MetaSnapshotMapper.class).deleteByTimestamp(params);
|
||||
}
|
||||
|
||||
protected void initDao() throws Exception {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.alibaba.otter.canal.parse.inbound.mysql.tsdb.dao;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface MetaSnapshotMapper {
|
||||
|
||||
MetaSnapshotDO findByTimestamp(Map<String, Object> map);
|
||||
|
||||
long insert(MetaSnapshotDO metaSnapshotDO);
|
||||
|
||||
long update(MetaSnapshotDO metaSnapshotDO);
|
||||
|
||||
int deleteByName(Map<String, Object> map);
|
||||
|
||||
int deleteByTimestamp(Map<String, Object> map);
|
||||
}
|
||||
Reference in New Issue
Block a user