mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
关系型数据同步adapter, 支持 mysql oracle postgresql sqlserver
This commit is contained in:
@@ -15,14 +15,14 @@ public class ConfigLoadTest {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
AdapterConfigs.put("rdb", "mytest_user.yml");
|
||||
AdapterConfigs.put("oracle", "mytest_user.yml");
|
||||
// 加载数据源连接池
|
||||
DatasourceConfig.DATA_SOURCES.put("defaultDS", TestConstant.dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoad() {
|
||||
Map<String, MappingConfig> configMap = MappingConfigLoader.load();
|
||||
Map<String, MappingConfig> configMap = MappingConfigLoader.load("oracle");
|
||||
|
||||
Assert.assertFalse(configMap.isEmpty());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.otter.canal.client.adapter.rdb.test.sync;
|
||||
|
||||
import com.alibaba.otter.canal.client.adapter.rdb.RdbAdapter;
|
||||
import com.alibaba.otter.canal.client.adapter.rdb.adapters.OracleAdapter;
|
||||
import com.alibaba.otter.canal.client.adapter.rdb.test.TestConstant;
|
||||
import com.alibaba.otter.canal.client.adapter.support.DatasourceConfig;
|
||||
import com.alibaba.otter.canal.client.adapter.support.OuterAdapterConfig;
|
||||
@@ -13,7 +14,7 @@ public class Common {
|
||||
DatasourceConfig.DATA_SOURCES.put("defaultDS", TestConstant.dataSource);
|
||||
|
||||
OuterAdapterConfig outerAdapterConfig = new OuterAdapterConfig();
|
||||
outerAdapterConfig.setName("rdb");
|
||||
outerAdapterConfig.setName("oracle");
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("jdbc.driveClassName", "oracle.jdbc.OracleDriver");
|
||||
properties.put("jdbc.url", "jdbc:oracle:thin:@127.0.0.1:49161:XE");
|
||||
@@ -21,7 +22,7 @@ public class Common {
|
||||
properties.put("jdbc.password", "m121212");
|
||||
outerAdapterConfig.setProperties(properties);
|
||||
|
||||
RdbAdapter adapter = new RdbAdapter();
|
||||
RdbAdapter adapter = new OracleAdapter();
|
||||
adapter.init(outerAdapterConfig);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.alibaba.otter.canal.client.adapter.rdb.test.sync;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Reader;
|
||||
import java.sql.Clob;
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -18,7 +15,7 @@ public class OracleSyncTest {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
AdapterConfigs.put("rdb", "mytest_user.yml");
|
||||
AdapterConfigs.put("oracle", "mytest_user.yml");
|
||||
rdbAdapter = Common.init();
|
||||
}
|
||||
|
||||
@@ -43,5 +40,27 @@ public class OracleSyncTest {
|
||||
rdbAdapter.sync(dml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test02() {
|
||||
Dml dml = new Dml();
|
||||
dml.setDestination("example");
|
||||
dml.setTs(new Date().getTime());
|
||||
dml.setType("UPDATE");
|
||||
dml.setDatabase("mytest");
|
||||
dml.setTable("user");
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
dataList.add(data);
|
||||
data.put("id", 1L);
|
||||
data.put("name", "Eric2");
|
||||
dml.setData(dataList);
|
||||
List<Map<String, Object>> oldList = new ArrayList<>();
|
||||
Map<String, Object> old = new LinkedHashMap<>();
|
||||
oldList.add(old);
|
||||
old.put("name", "Eric");
|
||||
dml.setOld(oldList);
|
||||
|
||||
rdbAdapter.sync(dml);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ dbMapping:
|
||||
database: mytest
|
||||
table: user
|
||||
targetTable: mytest.tb_user
|
||||
commitBatch: 3000
|
||||
targetPk:
|
||||
id: id
|
||||
mapAll: true
|
||||
# targetColumns:
|
||||
# id:
|
||||
Reference in New Issue
Block a user