if (!isSchemaRegistered(conn, schema)) {
log.info("schema '" + schema + "' is not registered, going to add it");
addSchemaToWatch(conn, catalog, schema);
}
TableToWatchInfo tableToWatch = getTableToWatch(conn, catalog, schema, tableName);
if (!conn.getAutoCommit())
conn.commit(); // to be sure it is a new transaction
if (!force && tableToWatch != null && tableToWatch.isStatusOk(this, conn)) {
// send it manually since table exits already and trigger is OK.
log.info("table '" + tableName + "' is already registered, will add directly an entry in the ENTRIES Table");
String destAttrName = "?";
if (destinations == null || destinations.length == 0)
destAttrName = "NULL";
String sql = "{? = call " + this.replPrefix + "check_tables(NULL,?,?,?," + destAttrName + ")}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, schema);
st.setString(3, tableName);
st.setString(4, ReplicationConstants.CREATE_ACTION);
if (destinations != null && destinations.length != 0) {
String post = "</desc>";
if (forceSend)
post = "<attr id='_forceSend'>true</attr>" + post;
String destinationTxt = "<desc><attr id='_destination'>" + toString(destinations) + "</attr>" + post;
st.setString(5, destinationTxt);
}
st.registerOutParameter(1, Types.VARCHAR);
st.executeQuery();
st.close();
return false;
}
/*
if (force) {
if (isTableRegistered(conn, tableToWatch)) {
log.info("table '" + tableName + "' is already registered and 'force' has been choosed. Will set its status to 'REMOVE'");
tableToWatch.setStatus(TableToWatchInfo.STATUS_REMOVE);
tableToWatch.storeStatus(this.replPrefix, this.dbPool);
}
}
*/
// then it is either not OK or force true. or null
if (tableToWatch != null) // then it is either not OK or force true. In both cases we need to remove old entry
tableToWatch.removeFromDb(this.replPrefix, this.dbPool);
if (triggerName == null)
triggerName = this.replPrefix + tmp;
triggerName = this.dbMetaHelper.getIdentifier(triggerName);
long debug = 0;
TableToWatchInfo finalTableToWatch = new TableToWatchInfo(catalog, schema, tableName);
finalTableToWatch.setActions(actions);
finalTableToWatch.setTrigger(triggerName);
finalTableToWatch.setDebug((int)debug);
finalTableToWatch.setReplKey(tmp);
finalTableToWatch.store(this.replPrefix, this.dbPool, conn);
return true;
}
catch (Throwable ex) {
conn = removeFromPool(conn, ROLLBACK_YES);