SpecificHelper specificHelper = new SpecificHelper(System.getProperties());
I_Info info = new PropertiesInfo((Properties)specificHelper.getProperties().clone());
info.put("replication.searchable.xmlBlaster.table1", "first, second, third, fourth");
info.put("replication.searchable.XMLBLASTER.TABLE2", "FIRST,SECOND");
DbPool pool = new DbPool();
pool.init(info);
info.putObject(DbWriter.DB_POOL_KEY, pool);
SearchableConfig searchableConfig = new SearchableConfig();
searchableConfig.init(info);
info.putObject(SearchableConfig.NAME, searchableConfig);
pool.update("drop table table1");
String txt = "create table table1 (first VARCHAR(100), second VARCHAR(100), third blob, fifth VARCHAR(29), primary key(first))";
pool.update(txt);
pool.update("INSERT INTO table1 (first, second, fifth) values ('oldOne', 'oldTwo', 'oldFive')");
Set vals = searchableConfig.getSearchableColumnNames(null, "XMLBLASTER", "TABLE1");
String[] ret = (String[])vals.toArray(new String[vals.size()]);
assertEquals("Wrong number of colums found", 4, ret.length);
SqlInfo sqlInfo = new SqlInfo(info);
Connection conn = pool.reserve();
sqlInfo.fillMetadata(conn, null, "XMLBLASTER", "TABLE1", null, null);
pool.release(conn);
SqlDescription description = sqlInfo.getDescription();
boolean isConfigured = description.isColumnSearchConfigured(null);
assertTrue("shall be configured", isConfigured);
isConfigured = description.isColumnSearchConfigured("FIRST");
assertTrue("shall be configured", isConfigured);
isConfigured = description.isColumnSearchConfigured("SECOND");
assertTrue("shall be configured", isConfigured);
isConfigured = description.isColumnSearchConfigured("THIRD");
assertFalse("shall not be configured", isConfigured);
isConfigured = description.isColumnSearchConfigured("FOURTH");
assertTrue("shall be configured (since it could be added later)", isConfigured);
String oldFirst = "oldOne";
String oldSecond = "oldTwo";
String first = "one";
String second = "two";
String fifth = "five";
int replKey = 1;
SqlInfo sql = createMsg(info, oldFirst, oldSecond, first, second, fifth, replKey);
String xml = sql.toXml("");
log.info(xml);
SqlInfoParser parser = new SqlInfoParser();
parser.init(info);
sql = parser.parse(xml);
ReplicationWriter writer = new ReplicationWriter();
writer.init(info);
writer.store(sql);
// verify now,
conn = pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT count(*) FROM TABLE1");
rs.next();
int count = rs.getInt(1);
assertEquals("there must be only one entry in the table TABLE1", 1, count);
st.close();
st = conn.createStatement();
rs = st.executeQuery("SELECT FIRST,SECOND,FIFTH FROM TABLE1");
rs.next();
first = rs.getString(1);
second = rs.getString(2);
fifth = rs.getString(3);
st.close();
pool.release(conn);
assertEquals("first", "one", first);
assertEquals("second", "two", second);
assertEquals("fifth", "five", fifth);
pool.update("drop table table1");
}
catch (Exception ex) {
ex.printStackTrace();
assertTrue("An exception should not occur here" + ex.getMessage(), false);
}