use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method queueSyncTriggers.
@SuppressWarnings("unchecked")
protected void queueSyncTriggers(SimpleRouterContext routingContext, DataMetaData dataMetaData, Map<String, String> columnValues) {
if ((tableMatches(dataMetaData, TableConstants.SYM_TRIGGER) || tableMatches(dataMetaData, TableConstants.SYM_TRIGGER_ROUTER))) {
Object needResync = routingContext.get(CTX_KEY_RESYNC_NEEDED);
if (needResync == null || needResync instanceof Set) {
if (needResync == null) {
needResync = new HashSet<Trigger>();
routingContext.put(CTX_KEY_RESYNC_NEEDED, needResync);
}
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
boolean refreshCache = false;
if (routingContext.get(CTX_KEY_FLUSHED_TRIGGER_ROUTERS) == null) {
triggerRouterService.clearCache();
refreshCache = true;
routingContext.put(CTX_KEY_FLUSHED_TRIGGER_ROUTERS, true);
}
Trigger trigger = null;
Date lastUpdateTime = null;
String triggerId = columnValues.get("TRIGGER_ID");
if (tableMatches(dataMetaData, TableConstants.SYM_TRIGGER_ROUTER)) {
String routerId = columnValues.get("ROUTER_ID");
TriggerRouter tr = triggerRouterService.findTriggerRouterById(triggerId, routerId, refreshCache);
if (tr != null) {
trigger = tr.getTrigger();
lastUpdateTime = tr.getLastUpdateTime();
}
} else {
trigger = triggerRouterService.getTriggerById(triggerId, refreshCache);
if (trigger != null) {
lastUpdateTime = trigger.getLastUpdateTime();
}
}
if (trigger != null) {
List<TriggerHistory> histories = triggerRouterService.getActiveTriggerHistories(trigger);
boolean sync = false;
if (histories != null && histories.size() > 0) {
for (TriggerHistory triggerHistory : histories) {
if (triggerHistory.getCreateTime().before(lastUpdateTime)) {
sync = true;
}
}
} else {
sync = true;
}
if (sync) {
((Set<Trigger>) needResync).add(trigger);
}
}
}
} else if (tableMatches(dataMetaData, TableConstants.SYM_ROUTER) || tableMatches(dataMetaData, TableConstants.SYM_NODE_GROUP_LINK)) {
routingContext.put(CTX_KEY_RESYNC_NEEDED, Boolean.TRUE);
}
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method syncTriggers.
public void syncTriggers(Table table, boolean force) {
boolean ignoreCase = this.parameterService.is(ParameterConstants.DB_METADATA_IGNORE_CASE);
if (table == null) {
throw new SymmetricException("'table' cannot be null, check that the table exists.");
}
/* Re-lookup just in case the table was just altered */
platform.resetCachedTableModel();
table = platform.getTableFromCache(table.getCatalog(), table.getSchema(), table.getName(), true);
List<Trigger> triggersForCurrentNode = getTriggersForCurrentNode();
List<TriggerHistory> activeTriggerHistories = getActiveTriggerHistories();
for (Trigger trigger : triggersForCurrentNode) {
if (trigger.matches(table, platform.getDefaultCatalog(), platform.getDefaultSchema(), ignoreCase)) {
log.info("Synchronizing triggers for {}", table.getFullyQualifiedTableName());
updateOrCreateDatabaseTriggers(trigger, table, null, force, true, activeTriggerHistories);
log.info("Done synchronizing triggers for {}", table.getFullyQualifiedTableName());
}
}
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method buildTriggerRoutersForSymmetricTables.
public List<TriggerRouter> buildTriggerRoutersForSymmetricTables(String version, NodeGroupLink nodeGroupLink, String... tablesToExclude) {
int initialLoadOrder = 1;
List<Trigger> triggers = buildTriggersForSymmetricTables(version, tablesToExclude);
List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>(triggers.size());
for (int j = 0; j < triggers.size(); j++) {
Trigger trigger = triggers.get(j);
TriggerRouter triggerRouter = buildTriggerRoutersForSymmetricTables(version, trigger, nodeGroupLink);
triggerRouter.setInitialLoadOrder(initialLoadOrder++);
triggerRouters.add(triggerRouter);
}
return triggerRouters;
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method getTriggers.
public List<Trigger> getTriggers(boolean replaceTokens) {
List<Trigger> triggers = sqlTemplate.query("select " + getSql("selectTriggersColumnList", "selectTriggersSql"), new TriggerMapper());
if (replaceTokens) {
@SuppressWarnings({ "rawtypes", "unchecked" }) Map<String, String> replacements = (Map) parameterService.getAllParameters();
for (Trigger trigger : triggers) {
trigger.setSourceCatalogName(FormatUtils.replaceTokens(trigger.getSourceCatalogName(), replacements, true));
trigger.setSourceSchemaName(FormatUtils.replaceTokens(trigger.getSourceSchemaName(), replacements, true));
trigger.setSourceTableName(FormatUtils.replaceTokens(trigger.getSourceTableName(), replacements, true));
}
}
return triggers;
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method createTriggersOnChannelForTables.
public void createTriggersOnChannelForTables(String channelId, String catalogName, String schemaName, List<String> tables, String lastUpdateBy) {
List<Trigger> createdTriggers = new ArrayList<Trigger>();
List<Trigger> existingTriggers = getTriggers();
for (String table : tables) {
Trigger trigger = new Trigger();
trigger.setChannelId(channelId);
trigger.setSourceCatalogName(catalogName);
trigger.setSourceSchemaName(schemaName);
trigger.setSourceTableName(table);
String triggerId = table;
if (table.length() > 50) {
triggerId = table.substring(0, 13) + "_" + UUID.randomUUID().toString();
}
boolean uniqueNameCreated = false;
int suffix = 0;
while (!uniqueNameCreated) {
String triggerIdPriorToCheck = triggerId;
for (Trigger existingTrigger : existingTriggers) {
if (triggerId.equals(existingTrigger.getTriggerId())) {
String suffixString = "_" + suffix;
if (suffix == 0) {
triggerId = triggerId + suffixString;
} else {
triggerId = triggerId.substring(0, triggerId.length() - ("_" + (suffix - 1)).length()) + suffixString;
}
suffix++;
}
}
if (triggerId.equals(triggerIdPriorToCheck)) {
uniqueNameCreated = true;
}
}
trigger.setTriggerId(triggerId);
trigger.setLastUpdateBy(lastUpdateBy);
trigger.setLastUpdateTime(new Date());
trigger.setCreateTime(new Date());
saveTrigger(trigger);
createdTriggers.add(trigger);
}
}
Aggregations