info.put("replication.mapper.schema.AIS", "AIS1");
info.put("replication.mapper.table.AIS.C_OUTS", "C_INS");
info.put("replication.mapper.column.AIS.C_OUTS.COM_MESSAGEID", "COM_RECORDID");
DefaultMapper mapper = new DefaultMapper();
try {
mapper.init(info);
}
catch (Exception ex) {
ex.printStackTrace();
assertTrue("An exception should not occur when initiating the mapper '" + ex.getMessage(), false);
}
{
String catalog = null;
String schema = "AIS";
String table = "C_OUTS";
String column = "COM_MESSAGEID";
String res = mapper.getMappedSchema(catalog, schema, table, column, schema);
assertEquals("checking schema", "AIS1", res);
res = mapper.getMappedTable(catalog, schema, table, column, table);
assertEquals("checking table", "C_INS", res);
res = mapper.getMappedColumn(catalog, schema, table, column, column);
assertEquals("checking column", "COM_RECORDID", res);
}
{
String catalog = null;
String schema = "AIS";
String table = "C_OUTS";
String column = "COM_RECORDID";
String res = mapper.getMappedSchema(catalog, schema, table, column, schema);
assertEquals("checking schema", "AIS1", res);
res = mapper.getMappedTable(catalog, schema, table, column, table);
assertEquals("checking table", "C_INS", res);
res = mapper.getMappedColumn(catalog, schema, table, column, column);
assertEquals("checking column", "COM_RECORDID", res);
String xmlTxt =
"<?xml version='1.0' encoding='UTF-8' ?>\n" +
"<sql>\n" +
" <desc>\n" +
" <command>REPLICATION</command>\n" +
" <ident>16</ident>\n" +
" </desc>\n" +
" <row num='0'>\n" +
" <col name='COM_MESSAGEID'></col>\n" +
" <col name='COM_RECORDID'>55</col>\n" +
" <col name='COM_TABLE' encoding='base64'>TjF8Mg==</col>\n" +
" <col name='COM_COMMAND' encoding='base64'>RA==</col>\n" +
" <col name='COM_TXT1'></col>\n" +
" <col name='COM_TXTL' encoding='base64'>OTg0NTA5AwM=</col>\n" +
" <col name='COM_CHANNEL'></col>\n" +
" <col name='COM_DEBUG'></col>\n" +
" <attr name='replKey'>16</attr>\n" +
" <attr name='action'>INSERT</attr>\n" +
" <attr name='transaction'>4.24.2232</attr>\n" +
" <attr name='guid'>AAAT0EAAGAAAAKsAAA</attr>\n" +
" <attr name='tableName'>C_OUTS</attr>\n" +
" <attr name='schema'>AIS</attr>\n" +
" <attr name='dbId'>NULL</attr>\n" +
" <attr name='version'>0.0</attr>\n" +
" </row>\n" +
"</sql>\n";
try {
String oldName = "COM_RECORDID";
String newName = "COM_MESSAGEID";
SqlInfoParser parser = new SqlInfoParser();
parser.init(info);
SqlInfo sqlInfo = parser.parse(xmlTxt);
List rows = sqlInfo.getRows();
assertEquals("The number of rows is wrong", 1, rows.size());
SqlRow row = (SqlRow)rows.get(0);
log.info(row.toXml(""));
row.renameColumn(oldName, newName);
log.info(row.toXml(""));
}
catch (Exception ex) {
ex.printStackTrace();
assertTrue("An Exception should not occur when testing renaming of columns " + ex.getMessage(), false);
}
}
{
String catalog = null;
String schema = "AIS";
String table = "OTHER";
String column = "COM_MESSAGEID";
String res = mapper.getMappedSchema(catalog, schema, table, column, schema);
assertEquals("checking schema", "AIS1", res);
res = mapper.getMappedTable(catalog, schema, table, column, table);
assertEquals("checking table", "OTHER", res);
res = mapper.getMappedColumn(catalog, schema, table, column, column);
assertEquals("checking column", "COM_MESSAGEID", res);
}
log.info("SUCCESS");
}